From b6251568eb312c104a5de16cc6ceb4827435a271 Mon Sep 17 00:00:00 2001 From: Rafa de la Torre Date: Wed, 5 Dec 2018 18:59:11 +0100 Subject: [PATCH] Test first, with hardcoded values (WIP) #543 --- test/unit/error_handler.test.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/unit/error_handler.test.js b/test/unit/error_handler.test.js index e3b8be00..884c0e57 100644 --- a/test/unit/error_handler.test.js +++ b/test/unit/error_handler.test.js @@ -116,4 +116,28 @@ describe('error-handler', function() { 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(); + }); + }); });