2018-07-02 23:30:14 -04:00
|
|
|
const PushRouter = require('../lib/Routers/PushRouter').PushRouter;
|
2018-09-24 17:07:51 -04:00
|
|
|
const request = require('../lib/request');
|
2016-02-20 10:49:32 -05:00
|
|
|
|
|
|
|
|
describe('PushRouter', () => {
|
2018-09-01 13:58:06 -04:00
|
|
|
it('can get query condition when channels is set', done => {
|
2016-02-20 10:49:32 -05:00
|
|
|
// Make mock request
|
2018-02-17 09:55:30 -05:00
|
|
|
const request = {
|
2016-02-20 10:49:32 -05:00
|
|
|
body: {
|
2018-09-01 13:58:06 -04:00
|
|
|
channels: ['Giants', 'Mets'],
|
|
|
|
|
},
|
|
|
|
|
};
|
2016-02-20 10:49:32 -05:00
|
|
|
|
2018-02-17 09:55:30 -05:00
|
|
|
const where = PushRouter.getQueryCondition(request);
|
2016-02-20 10:49:32 -05:00
|
|
|
expect(where).toEqual({
|
2018-09-01 13:58:06 -04:00
|
|
|
channels: {
|
|
|
|
|
$in: ['Giants', 'Mets'],
|
|
|
|
|
},
|
2016-02-20 10:49:32 -05:00
|
|
|
});
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
|
2018-09-01 13:58:06 -04:00
|
|
|
it('can get query condition when where is set', done => {
|
2016-02-20 10:49:32 -05:00
|
|
|
// Make mock request
|
2018-02-17 09:55:30 -05:00
|
|
|
const request = {
|
2016-02-20 10:49:32 -05:00
|
|
|
body: {
|
2018-09-01 13:58:06 -04:00
|
|
|
where: {
|
|
|
|
|
injuryReports: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|
2016-02-20 10:49:32 -05:00
|
|
|
|
2018-02-17 09:55:30 -05:00
|
|
|
const where = PushRouter.getQueryCondition(request);
|
2016-02-20 10:49:32 -05:00
|
|
|
expect(where).toEqual({
|
2018-09-01 13:58:06 -04:00
|
|
|
injuryReports: true,
|
2016-02-20 10:49:32 -05:00
|
|
|
});
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
|
2018-09-01 13:58:06 -04:00
|
|
|
it('can get query condition when nothing is set', done => {
|
2016-02-20 10:49:32 -05:00
|
|
|
// Make mock request
|
2018-02-17 09:55:30 -05:00
|
|
|
const request = {
|
2018-09-01 13:58:06 -04:00
|
|
|
body: {},
|
|
|
|
|
};
|
2016-02-20 10:49:32 -05:00
|
|
|
|
2020-10-25 15:06:58 -05:00
|
|
|
expect(function () {
|
2016-02-20 10:49:32 -05:00
|
|
|
PushRouter.getQueryCondition(request);
|
|
|
|
|
}).toThrow();
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
|
2018-09-01 13:58:06 -04:00
|
|
|
it('can throw on getQueryCondition when channels and where are set', done => {
|
2016-02-20 10:49:32 -05:00
|
|
|
// Make mock request
|
2018-02-17 09:55:30 -05:00
|
|
|
const request = {
|
2016-02-20 10:49:32 -05:00
|
|
|
body: {
|
2018-09-01 13:58:06 -04:00
|
|
|
channels: {
|
|
|
|
|
$in: ['Giants', 'Mets'],
|
2016-02-20 10:49:32 -05:00
|
|
|
},
|
2018-09-01 13:58:06 -04:00
|
|
|
where: {
|
|
|
|
|
injuryReports: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|
2016-02-20 10:49:32 -05:00
|
|
|
|
2020-10-25 15:06:58 -05:00
|
|
|
expect(function () {
|
2016-02-20 10:49:32 -05:00
|
|
|
PushRouter.getQueryCondition(request);
|
|
|
|
|
}).toThrow();
|
|
|
|
|
done();
|
|
|
|
|
});
|
2016-04-07 18:08:09 -04:00
|
|
|
|
2018-09-01 13:58:06 -04:00
|
|
|
it('sends a push through REST', done => {
|
2018-09-24 17:07:51 -04:00
|
|
|
request({
|
|
|
|
|
method: 'POST',
|
|
|
|
|
url: Parse.serverURL + '/push',
|
|
|
|
|
body: {
|
|
|
|
|
channels: {
|
|
|
|
|
$in: ['Giants', 'Mets'],
|
2018-09-01 13:58:06 -04:00
|
|
|
},
|
2016-02-20 10:49:32 -05:00
|
|
|
},
|
2018-09-24 17:07:51 -04:00
|
|
|
headers: {
|
|
|
|
|
'X-Parse-Application-Id': Parse.applicationId,
|
|
|
|
|
'X-Parse-Master-Key': Parse.masterKey,
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
},
|
|
|
|
|
}).then(res => {
|
|
|
|
|
expect(res.headers['x-parse-push-status-id']).not.toBe(undefined);
|
|
|
|
|
expect(res.headers['x-parse-push-status-id'].length).toBe(10);
|
|
|
|
|
expect(res.data.result).toBe(true);
|
|
|
|
|
done();
|
|
|
|
|
});
|
2016-02-20 10:49:32 -05:00
|
|
|
});
|
2016-04-07 18:08:09 -04:00
|
|
|
});
|