Open milkovsky opened 3 years ago
Example step:
Then the response body does not contain JSON:
"""
{
"foo": "bar"
}
"""
@christeredvartsen , hey. Do you find this feature unnecessary?
I find the feature somewhat confusing. Would you be able to add some tests for it so I can better understand the use case?
I was looking for a step like this, and can explain my use-case: Our API endpoint was adding some unwanted code in a field that is otherwise difficult to predict. For example, the response JSON might be something like:
{
myField: "lots of unpredictable text etc... SOME UNWANTED CODE ...more unpredictable text..."
}
We fixed the problem, but wanted to write a Behat test to ensure it never happened again. Because the text is unpredictable, we can't use And the response body contains JSON
to assert that the unwanted code is not there. So something like this would be ideal:
And the response body does not contain JSON:
"""
{
"myField": "@regExp(/SOME UNWANTED CODE/i)"
}
"""
@brockfanning you can add the step from the pull request into your custom behat context, that extends Imbo\BehatApiExtension\Context\ApiContext;
. This is what I am doing at the moment.
I find the feature somewhat confusing. Would you be able to add some tests for it so I can better understand the use case?
@christeredvartsen the idea of this feature is to make sure, that unwanted content does not appear in the API.
For example, I would like to test an endpoint, that returns all articles from an author. I would like to make sure, that the results do not include articles from other authors. A test could look like this:
Given I request "/api/articles?author=Peter"
# The results contain articles from Peter.
And the response body contains JSON:
"""
{
"articles": [
"title": "Article 1".
"author": "Peter"
]
}
"""
# The results do not contain articles from other authors.
And the response body does not contain JSON:
"""
{
"articles": [
"title": "Article 2".
"author": "Max"
]
}
"""
A proof of concept for https://github.com/imbo/behat-api-extension/issues/105.