I am developing an API, using apiary.io and Swagger. I want to test the API using dredd, and for normal API responses (HTTP status code 200) this is fine. However, when the API returns different status code based on parameters (e.g. 403), dredd reports the test as failed. I would like to mark the test as successful, with an optional logging message.
I've tried this:
hooks.afterEach(function(transaction){
if (transaction.real){
switch (transaction.real.statusCode){
case "400":
case "403":
case "406":
transaction.fail=false;
hooks.log('Failed, but expected by the API');
}
}
});
However this doesn't work, the test is still marked as failed. What am I missing?