Skip to content

Commit 7c850fc

Browse files
steven-supersoliddrew-gross
authored andcommitted
Fix for #1642 - copy query parameters to request body (#1687)
* Fix for #1642 - copy query parameters to request body * Add missing request.query to pass test
1 parent 0b88302 commit 7c850fc

File tree

2 files changed

+86
-10
lines changed

2 files changed

+86
-10
lines changed

spec/InstallationsRouter.spec.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
var auth = require('../src/Auth');
2+
var Config = require('../src/Config');
3+
var rest = require('../src/rest');
4+
var InstallationsRouter = require('../src/Routers/InstallationsRouter').InstallationsRouter;
5+
6+
var config = new Config('test');
7+
8+
describe('InstallationsRouter', () => {
9+
it('uses find condition from request.body', (done) => {
10+
var androidDeviceRequest = {
11+
'installationId': '12345678-abcd-abcd-abcd-123456789abc',
12+
'deviceType': 'android'
13+
};
14+
var iosDeviceRequest = {
15+
'installationId': '12345678-abcd-abcd-abcd-123456789abd',
16+
'deviceType': 'ios'
17+
};
18+
var request = {
19+
config: config,
20+
auth: auth.master(config),
21+
body: {
22+
where: {
23+
deviceType: 'android'
24+
}
25+
},
26+
query: {}
27+
};
28+
29+
var router = new InstallationsRouter();
30+
rest.create(config, auth.nobody(config), '_Installation', androidDeviceRequest)
31+
.then(() => {
32+
return rest.create(config, auth.nobody(config), '_Installation', iosDeviceRequest);
33+
}).then(() => {
34+
return router.handleFind(request);
35+
}).then((res) => {
36+
var results = res.response.results;
37+
expect(results.length).toEqual(1);
38+
done();
39+
});
40+
});
41+
42+
it('uses find condition from request.query', (done) => {
43+
var androidDeviceRequest = {
44+
'installationId': '12345678-abcd-abcd-abcd-123456789abc',
45+
'deviceType': 'android'
46+
};
47+
var iosDeviceRequest = {
48+
'installationId': '12345678-abcd-abcd-abcd-123456789abd',
49+
'deviceType': 'ios'
50+
};
51+
var request = {
52+
config: config,
53+
auth: auth.master(config),
54+
body: {},
55+
query: {
56+
where: {
57+
deviceType: 'android'
58+
}
59+
}
60+
};
61+
62+
var router = new InstallationsRouter();
63+
rest.create(config, auth.nobody(config), '_Installation', androidDeviceRequest)
64+
.then(() => {
65+
return rest.create(config, auth.nobody(config), '_Installation', iosDeviceRequest);
66+
}).then(() => {
67+
return router.handleFind(request);
68+
}).then((res) => {
69+
var results = res.response.results;
70+
expect(results.length).toEqual(1);
71+
done();
72+
});
73+
});
74+
});

src/Routers/InstallationsRouter.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,27 @@ import rest from '../rest';
66

77
export class InstallationsRouter extends ClassesRouter {
88
handleFind(req) {
9+
let body = Object.assign(req.body, ClassesRouter.JSONFromQuery(req.query));
910
var options = {};
10-
if (req.body.skip) {
11-
options.skip = Number(req.body.skip);
11+
12+
if (body.skip) {
13+
options.skip = Number(body.skip);
1214
}
13-
if (req.body.limit) {
14-
options.limit = Number(req.body.limit);
15+
if (body.limit) {
16+
options.limit = Number(body.limit);
1517
}
16-
if (req.body.order) {
17-
options.order = String(req.body.order);
18+
if (body.order) {
19+
options.order = String(body.order);
1820
}
19-
if (req.body.count) {
21+
if (body.count) {
2022
options.count = true;
2123
}
22-
if (req.body.include) {
23-
options.include = String(req.body.include);
24+
if (body.include) {
25+
options.include = String(body.include);
2426
}
2527

2628
return rest.find(req.config, req.auth,
27-
'_Installation', req.body.where, options)
29+
'_Installation', body.where, options)
2830
.then((response) => {
2931
return {response: response};
3032
});

0 commit comments

Comments
 (0)