Fix jsonp tests

This commit is contained in:
Raul Ochoa 2015-09-17 02:06:32 +02:00
parent d93abe8e7d
commit 967ef99277
4 changed files with 32 additions and 12 deletions

View File

@ -235,7 +235,10 @@ describe('attributes', function() {
assert.ifError(err);
// jsonp errors should be returned with HTTP status 200
assert.equal(res.statusCode, 200, res.statusCode + ': ' + res.body);
assert.equal(res.body, 'test({"errors":["Layer 0 has no exposed attributes"]});');
assert.equal(
res.body,
'/**/ typeof test === \'function\' && test({"errors":["Layer 0 has no exposed attributes"]});'
);
return null;
},
function do_get_attr_1(err)

View File

@ -56,7 +56,10 @@ describe('multilayer error cases', function() {
headers: {'Content-Type': 'application/json' }
}, {}, function(res) {
assert.equal(res.statusCode, 200);
assert.equal(res.body, 'test({"errors":["Missing layers array from layergroup config"]});');
assert.equal(
res.body,
'/**/ typeof test === \'function\' && test({"errors":["Missing layers array from layergroup config"]});'
);
done();
});
});
@ -340,7 +343,10 @@ describe('multilayer error cases', function() {
}
};
testClient.createLayergroup(bogusSqlMapConfig, options, function(err, res) {
assert.ok(/^test\(/.test(res.body), "Body start expected callback name: " + res.body);
assert.ok(
/^\/\*\*\/ typeof test === 'function' && test\(/.test(res.body),
"Body start expected callback name: " + res.body
);
assert.ok(/syntax error/.test(res.body), "Unexpected error: " + res.body);
done();
});
@ -356,7 +362,10 @@ describe('multilayer error cases', function() {
}
};
testClient.createLayergroup(noGeomMapConfig, options, function(err, res) {
assert.ok(/^test\(/.test(res.body), "Body start expected callback name: " + res.body);
assert.ok(
/^\/\*\*\/ typeof test === 'function' && test\(/.test(res.body),
"Body start expected callback name: " + res.body
);
assert.ok(/column.*does not exist/.test(res.body), "Unexpected error: " + res.body);
done();
});

View File

@ -111,13 +111,20 @@ describe('server', function() {
it("grid jsonp", function(done){
var mapConfig = testClient.singleLayerMapConfig('select * from test_table', null, null, 'name');
testClient.getGridJsonp(mapConfig, 0, 13, 4011, 3088, 'test', function(err, res) {
testClient.getGridJsonp(mapConfig, 0, 13, 4011, 3088, 'jsonp_test', function(err, res) {
assert.equal(res.statusCode, 200, res.body);
assert.deepEqual(res.headers['content-type'], 'application/json; charset=utf-8');
var regexp = '^test\\((.*)\\);$';
var matches = res.body.match(regexp);
assert.equal(matches.length, 2, 'Unexpected JSONP response:' + res.body);
assert.utfgridEqualsFile(matches[1], './test/fixtures/test_table_13_4011_3088.grid.json', 2, done);
assert.deepEqual(res.headers['content-type'], 'text/javascript; charset=utf-8');
var didRunJsonCallback = false;
var response = {};
// jshint ignore:start
function jsonp_test(body) {
response = body;
didRunJsonCallback = true;
}
eval(res.body);
// jshint ignore:end
assert.ok(didRunJsonCallback);
assert.utfgridEqualsFile(response, './test/fixtures/test_table_13_4011_3088.grid.json', 2, done);
});
});
@ -145,7 +152,7 @@ describe('server', function() {
}
};
testClient.getGrid(mapConfig, 0, 13, 4011, 3088, expectedResponse, function(err, res) {
console.log(res.body);
assert.deepEqual(JSON.parse(res.body), {"errors":["Tileset has no interactivity"]});
done();
});
});

View File

@ -44,6 +44,7 @@ server.setMaxListeners(0);
var redisClient = redis.createClient(global.environment.redis.port);
var jsonContentType = 'application/json; charset=utf-8';
var jsContentType = 'text/javascript; charset=utf-8';
var pngContentType = 'image/png';
function createLayergroup(layergroupConfig, options, callback) {
@ -218,7 +219,7 @@ function getGrid(layergroupConfig, layer, z, x, y, expectedResponse, callback) {
function getGridJsonp(layergroupConfig, layer, z, x, y, jsonpCallbackName, expectedResponse, callback) {
if (!callback) {
callback = expectedResponse;
expectedResponse = jsonContentType;
expectedResponse = jsContentType;
}
var options = {