Rewrite test to take advantage of changes in assert.response/TestClient

This should avoid the issue of preventing the whole suite to halt, as
in https://travis-ci.org/CartoDB/Windshaft-cartodb/builds/236337027.
This commit is contained in:
Raul Ochoa 2017-05-26 13:13:19 +02:00
parent 248adab05b
commit 882aeacac2

View File

@ -5,6 +5,7 @@ var step = require('step');
var cartodbServer = require('../../../lib/cartodb/server'); var cartodbServer = require('../../../lib/cartodb/server');
var ServerOptions = require('./support/ported_server_options'); var ServerOptions = require('./support/ported_server_options');
var testClient = require('./support/test_client'); var testClient = require('./support/test_client');
var TestClient = require('../../support/test-client');
var BaseController = require('../../../lib/cartodb/controllers/base'); var BaseController = require('../../../lib/cartodb/controllers/base');
@ -23,6 +24,14 @@ describe('multilayer error cases', function() {
BaseController.prototype.req2params = req2paramsFn; BaseController.prototype.req2params = req2paramsFn;
}); });
// var client = null;
afterEach(function(done) {
if (this.client) {
return this.client.drain(done);
}
return done();
});
it("post layergroup with wrong Content-Type", function(done) { it("post layergroup with wrong Content-Type", function(done) {
assert.response(server, { assert.response(server, {
url: '/database/windshaft_test/layergroup', url: '/database/windshaft_test/layergroup',
@ -153,24 +162,16 @@ describe('multilayer error cases', function() {
] ]
}; };
ServerOptions.afterLayergroupCreateCalls = 0; ServerOptions.afterLayergroupCreateCalls = 0;
assert.response(server, { this.client = new TestClient(layergroup);
url: '/database/windshaft_test/layergroup', this.client.getLayergroup({status: 400}, function(err, parsed) {
method: 'POST', assert.ok(!err, err);
headers: {'Content-Type': 'application/json' },
data: JSON.stringify(layergroup)
}, {}, function(res) {
try {
assert.equal(res.statusCode, 400, res.statusCode + ': ' + res.body);
// See http://github.com/CartoDB/Windshaft/issues/159 // See http://github.com/CartoDB/Windshaft/issues/159
assert.equal(ServerOptions.afterLayergroupCreateCalls, 0); assert.equal(ServerOptions.afterLayergroupCreateCalls, 0);
var parsed = JSON.parse(res.body);
assert.ok(parsed); assert.ok(parsed);
assert.equal(parsed.errors.length, 1); assert.equal(parsed.errors.length, 1);
var error = parsed.errors[0]; var error = parsed.errors[0];
assert.ok(error.match(/column "missing" does not exist/m), error); assert.ok(error.match(/column "missing" does not exist/m), error);
// TODO: check which layer introduced the problem ?
done(); done();
} catch (err) { done(err); }
}); });
}); });