Test first, with hardcoded values (WIP) #543

This commit is contained in:
Rafa de la Torre 2018-12-05 18:59:11 +01:00
parent 8505857412
commit b6251568eb

View File

@ -116,4 +116,28 @@ describe('error-handler', function() {
done(); done();
}); });
}); });
it('should truncat too long errors', function (done) {
const veryLongString = 'Very long error message '.repeat(2);
const truncatedString = veryLongString.substring(0,10);
let error = new Error(veryLongString);
const expectedErrorHeader = {
statusCode: 400,
message: truncatedString
};
const res = getRes();
errorMiddleware()(error, req, res, function () {
assert.ok(res.headers['X-SQLAPI-Errors'].length > 0);
assert.deepEqual(
res.headers['X-SQLAPI-Errors'],
JSON.stringify(expectedErrorHeader)
);
done();
});
});
}); });