Use before/after to not alter global configuration

This commit is contained in:
Raul Ochoa 2016-02-22 15:31:01 +01:00
parent 877425267e
commit fb146f164c
2 changed files with 99 additions and 75 deletions

View File

@ -190,38 +190,50 @@ describe(suiteName, function() {
});
it("should include serverMedata in the response", function(done) {
global.environment.serverMetadata = { cdn_url : { http:'test', https: 'tests' } };
var layergroup = {
version: '1.0.0',
layers: [
{ options: {
sql: 'select cartodb_id, ST_Translate(the_geom_webmercator, 5e6, 0) as the_geom_webmercator' +
' from test_table limit 2',
cartocss: '#layer { marker-fill:red; marker-width:32; marker-allow-overlap:true; }',
cartocss_version: '2.0.1'
} }
]
};
describe('server-metadata', function() {
var serverMetadata;
beforeEach(function() {
serverMetadata = global.environment.serverMetadata;
global.environment.serverMetadata = { cdn_url : { http:'test', https: 'tests' } };
});
afterEach(function() {
global.environment.serverMetadata = serverMetadata;
});
it("should include serverMedata in the response", function(done) {
var layergroup = {
version: '1.0.0',
layers: [
{ options: {
sql: 'select cartodb_id, ST_Translate(the_geom_webmercator, 5e6, 0) as the_geom_webmercator' +
' from test_table limit 2',
cartocss: '#layer { marker-fill:red; marker-width:32; marker-allow-overlap:true; }',
cartocss_version: '2.0.1'
} }
]
};
step(
function do_create_get()
{
var next = this;
assert.response(server, {
url: layergroup_url + '?config=' + encodeURIComponent(JSON.stringify(layergroup)),
method: 'GET',
headers: {host: 'localhost'}
}, {}, function(res, err) { next(err, res); });
},
function do_check_create(err, res) {
var parsed = JSON.parse(res.body);
keysToDelete['map_cfg|' + LayergroupToken.parse(parsed.layergroupid).token] = 0;
keysToDelete['user:localhost:mapviews:global'] = 5;
assert.ok(_.isEqual(parsed.cdn_url, global.environment.serverMetadata.cdn_url));
done();
}
);
});
step(
function do_create_get()
{
var next = this;
assert.response(server, {
url: layergroup_url + '?config=' + encodeURIComponent(JSON.stringify(layergroup)),
method: 'GET',
headers: {host: 'localhost'}
}, {}, function(res, err) { next(err, res); });
},
function do_check_create(err, res) {
var parsed = JSON.parse(res.body);
keysToDelete['map_cfg|' + LayergroupToken.parse(parsed.layergroupid).token] = 0;
keysToDelete['user:localhost:mapviews:global'] = 5;
assert.ok(_.isEqual(parsed.cdn_url, global.environment.serverMetadata.cdn_url));
done();
}
);
});

View File

@ -313,51 +313,63 @@ describe('template_api', function() {
});
});
it("instance endpoint should return server metadata", function(done){
global.environment.serverMetadata = { cdn_url : { http:'test', https: 'tests' } };
var tmpl = _.clone(template_acceptance1);
tmpl.name = "rambotemplate2";
describe('server-metadata', function() {
var serverMetadata;
beforeEach(function() {
serverMetadata = global.environment.serverMetadata;
global.environment.serverMetadata = { cdn_url : { http:'test', https: 'tests' } };
});
step(function postTemplate1() {
var next = this;
var post_request = {
url: '/api/v1/map/named?api_key=1234',
method: 'POST',
headers: {host: 'localhost', 'Content-Type': 'application/json' },
data: JSON.stringify(tmpl)
};
assert.response(server, post_request, {}, function(res) {
next(null, res);
});
},
function testCORS() {
var next = this;
assert.response(server, {
url: '/api/v1/map/named/' + tmpl.name,
method: 'POST',
headers: {host: 'localhost', 'Content-Type': 'application/json' }
},{
status: 200
}, function(res) {
var parsed = JSON.parse(res.body);
keysToDelete['map_cfg|' + LayergroupToken.parse(parsed.layergroupid).token] = 0;
keysToDelete['user:localhost:mapviews:global'] = 5;
assert.ok(_.isEqual(parsed.cdn_url, global.environment.serverMetadata.cdn_url));
next(null);
});
},
function deleteTemplate(err) {
assert.ifError(err);
var del_request = {
url: '/api/v1/map/named/' + tmpl.name + '?api_key=1234',
method: 'DELETE',
headers: {host: 'localhost', 'Content-Type': 'application/json' }
};
assert.response(server, del_request, {}, function() {
done();
});
}
);
afterEach(function() {
global.environment.serverMetadata = serverMetadata;
});
it("instance endpoint should return server metadata", function(done){
var tmpl = _.clone(template_acceptance1);
tmpl.name = "rambotemplate2";
step(function postTemplate1() {
var next = this;
var post_request = {
url: '/api/v1/map/named?api_key=1234',
method: 'POST',
headers: {host: 'localhost', 'Content-Type': 'application/json' },
data: JSON.stringify(tmpl)
};
assert.response(server, post_request, {}, function(res) {
next(null, res);
});
},
function testCORS() {
var next = this;
assert.response(server, {
url: '/api/v1/map/named/' + tmpl.name,
method: 'POST',
headers: {host: 'localhost', 'Content-Type': 'application/json' }
},{
status: 200
}, function(res) {
var parsed = JSON.parse(res.body);
keysToDelete['map_cfg|' + LayergroupToken.parse(parsed.layergroupid).token] = 0;
keysToDelete['user:localhost:mapviews:global'] = 5;
assert.ok(_.isEqual(parsed.cdn_url, global.environment.serverMetadata.cdn_url));
next(null);
});
},
function deleteTemplate(err) {
assert.ifError(err);
var del_request = {
url: '/api/v1/map/named/' + tmpl.name + '?api_key=1234',
method: 'DELETE',
headers: {host: 'localhost', 'Content-Type': 'application/json' }
};
assert.response(server, del_request, {}, function() {
done();
});
}
);
});
});