diff --git a/test/unit/cartodb/base_controller.js b/test/unit/cartodb/base_controller.js index 9bf21ccd..f9e6f178 100644 --- a/test/unit/cartodb/base_controller.js +++ b/test/unit/cartodb/base_controller.js @@ -3,7 +3,7 @@ require('../../support/test_helper.js'); var assert = require('assert'); var errorMiddleware = require('../../../lib/cartodb/middleware/error-middleware'); -describe('error-middleware', function() { +describe.only('error-middleware', function() { it('different formats for postgis plugin error returns 400 as status code', function() { @@ -20,4 +20,38 @@ describe('error-middleware', function() { "Error status code for multiline/PSQL does not match" ); }); + + it('should return a header with errors', function (done) { + const error = new Error('error test'); + + const req = {}; + const res = { + headers: {}, + set (key, value) { + this.headers[key] = value; + }, + statusCode: 0, + status (status) { + this.statusCode = status; + }, + json () {}, + send () {} + }; + + const errorHeader = { + statusCode: 400, + message: error.message, + name: error.name, + moreErrors: [] + }; + + const errorFn = errorMiddleware(); + errorFn(error, req, res); + + assert.deepEqual(res.headers, { + 'X-Tiler-Errors': JSON.stringify(errorHeader) + }); + + done(); + }); });