Skip to content

Commit b4d15f9

Browse files
author
Marvel Mathew
committed
Test
1 parent 4c889cb commit b4d15f9

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed

spec/PushController.spec.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,4 +1254,74 @@ describe('PushController', () => {
12541254
.then(done, done.fail);
12551255
});
12561256
});
1257+
1258+
describe('With expiration defined', () => {
1259+
const auth = {isMaster: true};
1260+
const pushController = new PushController();
1261+
1262+
const config = new Config(Parse.applicationId);
1263+
1264+
const pushes = [];
1265+
const pushAdapter = {
1266+
send(body, installations) {
1267+
pushes.push(body);
1268+
return successfulTransmissions(body, installations);
1269+
},
1270+
getValidPushTypes() {
1271+
return ["ios"];
1272+
}
1273+
};
1274+
1275+
beforeEach((done) => {
1276+
reconfigureServer({
1277+
push: {adapter: pushAdapter},
1278+
}).then(done, done.fail);
1279+
});
1280+
1281+
it('should throw if both expiration_time and expiration_interval are set', () => {
1282+
expect(() => pushController.sendPush({
1283+
expiration_time: '2017-09-25T13:21:20.841Z',
1284+
expiration_interval: 1000,
1285+
}, {}, config, auth)).toThrow()
1286+
});
1287+
1288+
it('should throw on invalid expiration_interval', () => {
1289+
expect(() => pushController.sendPush({
1290+
expiration_interval: -1
1291+
})).toThrow();
1292+
expect(() => pushController.sendPush({
1293+
expiration_interval: '',
1294+
})).toThrow();
1295+
});
1296+
1297+
describe('For immediate pushes',() => {
1298+
it('should transform the expiration_interval into an absolute time', (done) => {
1299+
const now = new Date('2017-09-25T13:30:10.452Z');
1300+
1301+
reconfigureServer({
1302+
push: {adapter: pushAdapter},
1303+
})
1304+
.then(() =>
1305+
new Promise((resolve) => {
1306+
pushController.sendPush({
1307+
data: {
1308+
alert: 'immediate push',
1309+
},
1310+
expiration_interval: 20 * 60, // twenty minutes
1311+
}, {}, new Config(Parse.applicationId), auth, resolve, now)
1312+
}))
1313+
.then((pushStatusId) => {
1314+
const p = new Parse.Object('_PushStatus');
1315+
p.id = pushStatusId;
1316+
return p.fetch({useMasterKey: true});
1317+
})
1318+
.then((pushStatus) => {
1319+
expect(pushStatus.get('expiry')).toBeDefined('expiry must be set');
1320+
expect(pushStatus.get('expiry'))
1321+
.toEqual(new Date('2017-09-25T13:50:10.452Z').valueOf());
1322+
})
1323+
.then(done, done.fail);
1324+
});
1325+
});
1326+
});
12571327
});

src/Controllers/PushController.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ export class PushController {
2424

2525
// Immediate push
2626
if (body.expiration_interval && !body.hasOwnProperty('push_time')) {
27-
body.expiration_time = new Date(now.valueOf() + body.expiration_interval);
27+
const ttlMs = body.expiration_interval * 1000;
28+
body.expiration_time = (new Date(now.valueOf() + ttlMs)).valueOf();
2829
}
2930

3031
const pushTime = PushController.getPushTime(body);
@@ -132,6 +133,7 @@ export class PushController {
132133
throw new Parse.Error(Parse.Error.PUSH_MISCONFIGURED,
133134
`expiration_interval must be a number greater than 0`);
134135
}
136+
return expirationIntervalParam;
135137
}
136138

137139
/**

0 commit comments

Comments
 (0)