Merge pull request #956 from CartoDB/add-merge-params-options

Express Routers: Activate mergeParams option
This commit is contained in:
Daniel G. Aubert 2018-05-14 12:59:44 +02:00 committed by GitHub
commit 0d4654122c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 3 deletions

View File

@ -191,7 +191,7 @@ module.exports = class ApiRouter {
Object.keys(this.serverOptions.routes).forEach(apiVersion => {
const routes = this.serverOptions.routes[apiVersion];
const apiRouter = router();
const apiRouter = router({ mergeParams: true });
apiRouter.use(logger(this.serverOptions));
apiRouter.use(initializeStatusCode());

View File

@ -113,7 +113,7 @@ module.exports = class MapRouter {
}
register (apiRouter, mapPaths) {
const mapRouter = router();
const mapRouter = router({ mergeParams: true });
this.analysisLayergroupController.register(mapRouter);
this.attributesLayergroupController.register(mapRouter);

View File

@ -53,7 +53,7 @@ module.exports = class TemplateRouter {
}
register (apiRouter, templatePaths) {
const templateRouter = router();
const templateRouter = router({ mergeParams: true });
this.namedMapController.register(templateRouter);
this.tileTemplateController.register(templateRouter);

View File

@ -1,7 +1,10 @@
require('../support/test_helper');
var assert = require('../support/assert');
const helper = require('../support/test_helper');
var TestClient = require('../support/test-client');
const LayergroupToken = require('../../lib/cartodb/models/layergroup-token');
const CartodbWindshaft = require(__dirname + '/../../lib/cartodb/server');
const serverOptions = require(__dirname + '/../../lib/cartodb/server_options');
describe('regressions', function() {
@ -38,6 +41,49 @@ describe('regressions', function() {
});
});
// See: https://github.com/CartoDB/Windshaft-cartodb/pull/956
it('"/user/localhost/api/v1/map" should create an anonymous map', function (done) {
const server = new CartodbWindshaft(serverOptions);
const layergroup = {
version: '1.7.0',
layers: [
{
type: 'mapnik',
options: {
sql: TestClient.SQL.ONE_POINT,
cartocss: TestClient.CARTOCSS.POINTS,
cartocss_version: '2.3.0'
}
}
]
};
const keysToDelete = {};
assert.response(server,
{
url: '/user/localhost/api/v1/map',
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
data: JSON.stringify(layergroup)
},
function(res, err) {
if (err) {
return done(err);
}
const body = JSON.parse(res.body);
assert.ok(body.layergroupid);
keysToDelete['map_cfg|' + LayergroupToken.parse(body.layergroupid).token] = 0;
keysToDelete['user:localhost:mapviews:global'] = 5;
helper.deleteRedisKeys(keysToDelete, done);
}
);
});
describe('map instantiation', function () {
const apikeyToken = 'regular1';
const mapConfig = {