Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maps status code validation error to contain real/expected status codes #168

Merged
merged 1 commit into from
May 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/next/test/integration/validateMessage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ describe('validateMessage', () => {
assert.propertyVal(
result.statusCode.results[0],
'message',
'Real and expected data does not match.'
`Status code is '400' instead of '200'`
);
});
});
Expand Down
2 changes: 1 addition & 1 deletion lib/next/test/unit/units/validateStatusCode.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('validateStatusCode', () => {
assert.propertyVal(
result.results[0],
'message',
'Real and expected data does not match.'
`Status code is '200' instead of '400'`
);
});
});
Expand Down
12 changes: 11 additions & 1 deletion lib/next/units/validateStatusCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,23 @@ const APIARY_STATUS_CODE_TYPE = 'text/vnd.apiary.status-code';
function validateStatusCode(real, expected) {
const validator = new TextDiff(real.statusCode, expected.statusCode);
const rawData = validator.validate();
const results = validator.evaluateOutputToResults();

return {
validator: 'TextDiff',
realType: APIARY_STATUS_CODE_TYPE,
expectedType: APIARY_STATUS_CODE_TYPE,
rawData,
results: validator.evaluateOutputToResults()
results: results.map((result) =>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's safe to map since the output of evaluateOutputToResults is [] when no errors occurred.

Object.assign({}, result, {
message:
result.message === 'Real and expected data does not match.'
? `Status code is '${real.statusCode}' instead of '${
expected.statusCode
}'`
: result.message
})
)
};
}

Expand Down