Skip to content

Fix for #1642 - copy query parameters to request body #1687

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions spec/InstallationsRouter.spec.js
Original file line number Diff line number Diff line change
@@ -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();
});
});
});
22 changes: 12 additions & 10 deletions src/Routers/InstallationsRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,27 @@ import rest from '../rest';

export class InstallationsRouter extends ClassesRouter {
handleFind(req) {
let body = Object.assign(req.body, ClassesRouter.JSONFromQuery(req.query));
var options = {};
if (req.body.skip) {
options.skip = Number(req.body.skip);

if (body.skip) {
options.skip = Number(body.skip);
}
if (req.body.limit) {
options.limit = Number(req.body.limit);
if (body.limit) {
options.limit = Number(body.limit);
}
if (req.body.order) {
options.order = String(req.body.order);
if (body.order) {
options.order = String(body.order);
}
if (req.body.count) {
if (body.count) {
options.count = true;
}
if (req.body.include) {
options.include = String(req.body.include);
if (body.include) {
options.include = String(body.include);
}

return rest.find(req.config, req.auth,
'_Installation', req.body.where, options)
'_Installation', body.where, options)
.then((response) => {
return {response: response};
});
Expand Down