* Fix for #1642 - copy query parameters to request body * Add missing request.query to pass test
This commit is contained in:
74
spec/InstallationsRouter.spec.js
Normal file
74
spec/InstallationsRouter.spec.js
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
var auth = require('../src/Auth');
|
||||||
|
var Config = require('../src/Config');
|
||||||
|
var rest = require('../src/rest');
|
||||||
|
var InstallationsRouter = require('../src/Routers/InstallationsRouter').InstallationsRouter;
|
||||||
|
|
||||||
|
var config = new Config('test');
|
||||||
|
|
||||||
|
describe('InstallationsRouter', () => {
|
||||||
|
it('uses find condition from request.body', (done) => {
|
||||||
|
var androidDeviceRequest = {
|
||||||
|
'installationId': '12345678-abcd-abcd-abcd-123456789abc',
|
||||||
|
'deviceType': 'android'
|
||||||
|
};
|
||||||
|
var iosDeviceRequest = {
|
||||||
|
'installationId': '12345678-abcd-abcd-abcd-123456789abd',
|
||||||
|
'deviceType': 'ios'
|
||||||
|
};
|
||||||
|
var request = {
|
||||||
|
config: config,
|
||||||
|
auth: auth.master(config),
|
||||||
|
body: {
|
||||||
|
where: {
|
||||||
|
deviceType: 'android'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
query: {}
|
||||||
|
};
|
||||||
|
|
||||||
|
var router = new InstallationsRouter();
|
||||||
|
rest.create(config, auth.nobody(config), '_Installation', androidDeviceRequest)
|
||||||
|
.then(() => {
|
||||||
|
return rest.create(config, auth.nobody(config), '_Installation', iosDeviceRequest);
|
||||||
|
}).then(() => {
|
||||||
|
return router.handleFind(request);
|
||||||
|
}).then((res) => {
|
||||||
|
var results = res.response.results;
|
||||||
|
expect(results.length).toEqual(1);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('uses find condition from request.query', (done) => {
|
||||||
|
var androidDeviceRequest = {
|
||||||
|
'installationId': '12345678-abcd-abcd-abcd-123456789abc',
|
||||||
|
'deviceType': 'android'
|
||||||
|
};
|
||||||
|
var iosDeviceRequest = {
|
||||||
|
'installationId': '12345678-abcd-abcd-abcd-123456789abd',
|
||||||
|
'deviceType': 'ios'
|
||||||
|
};
|
||||||
|
var request = {
|
||||||
|
config: config,
|
||||||
|
auth: auth.master(config),
|
||||||
|
body: {},
|
||||||
|
query: {
|
||||||
|
where: {
|
||||||
|
deviceType: 'android'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var router = new InstallationsRouter();
|
||||||
|
rest.create(config, auth.nobody(config), '_Installation', androidDeviceRequest)
|
||||||
|
.then(() => {
|
||||||
|
return rest.create(config, auth.nobody(config), '_Installation', iosDeviceRequest);
|
||||||
|
}).then(() => {
|
||||||
|
return router.handleFind(request);
|
||||||
|
}).then((res) => {
|
||||||
|
var results = res.response.results;
|
||||||
|
expect(results.length).toEqual(1);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -6,25 +6,27 @@ import rest from '../rest';
|
|||||||
|
|
||||||
export class InstallationsRouter extends ClassesRouter {
|
export class InstallationsRouter extends ClassesRouter {
|
||||||
handleFind(req) {
|
handleFind(req) {
|
||||||
|
let body = Object.assign(req.body, ClassesRouter.JSONFromQuery(req.query));
|
||||||
var options = {};
|
var options = {};
|
||||||
if (req.body.skip) {
|
|
||||||
options.skip = Number(req.body.skip);
|
if (body.skip) {
|
||||||
|
options.skip = Number(body.skip);
|
||||||
}
|
}
|
||||||
if (req.body.limit) {
|
if (body.limit) {
|
||||||
options.limit = Number(req.body.limit);
|
options.limit = Number(body.limit);
|
||||||
}
|
}
|
||||||
if (req.body.order) {
|
if (body.order) {
|
||||||
options.order = String(req.body.order);
|
options.order = String(body.order);
|
||||||
}
|
}
|
||||||
if (req.body.count) {
|
if (body.count) {
|
||||||
options.count = true;
|
options.count = true;
|
||||||
}
|
}
|
||||||
if (req.body.include) {
|
if (body.include) {
|
||||||
options.include = String(req.body.include);
|
options.include = String(body.include);
|
||||||
}
|
}
|
||||||
|
|
||||||
return rest.find(req.config, req.auth,
|
return rest.find(req.config, req.auth,
|
||||||
'_Installation', req.body.where, options)
|
'_Installation', body.where, options)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
return {response: response};
|
return {response: response};
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user