Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.

Commit 9b42238

Browse files
Merge pull request #168 from apiaryio/167-status-code-message
Maps status code validation error to contain real/expected status codes
2 parents c03a0f9 + 2ac8cb3 commit 9b42238

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

lib/next/test/integration/validateMessage.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ describe('validateMessage', () => {
299299
assert.propertyVal(
300300
result.statusCode.results[0],
301301
'message',
302-
'Real and expected data does not match.'
302+
`Status code is '400' instead of '200'`
303303
);
304304
});
305305
});

lib/next/test/unit/units/validateStatusCode.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ describe('validateStatusCode', () => {
6464
assert.propertyVal(
6565
result.results[0],
6666
'message',
67-
'Real and expected data does not match.'
67+
`Status code is '200' instead of '400'`
6868
);
6969
});
7070
});

lib/next/units/validateStatusCode.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,23 @@ const APIARY_STATUS_CODE_TYPE = 'text/vnd.apiary.status-code';
1010
function validateStatusCode(real, expected) {
1111
const validator = new TextDiff(real.statusCode, expected.statusCode);
1212
const rawData = validator.validate();
13+
const results = validator.evaluateOutputToResults();
1314

1415
return {
1516
validator: 'TextDiff',
1617
realType: APIARY_STATUS_CODE_TYPE,
1718
expectedType: APIARY_STATUS_CODE_TYPE,
1819
rawData,
19-
results: validator.evaluateOutputToResults()
20+
results: results.map((result) =>
21+
Object.assign({}, result, {
22+
message:
23+
result.message === 'Real and expected data does not match.'
24+
? `Status code is '${real.statusCode}' instead of '${
25+
expected.statusCode
26+
}'`
27+
: result.message
28+
})
29+
)
2030
};
2131
}
2232

0 commit comments

Comments
 (0)