Skip to content
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

test: improve PushController tests #7760

Merged
merged 3 commits into from
Jan 2, 2022
Merged
Changes from 2 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: 24 additions & 50 deletions spec/PushController.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -562,11 +562,7 @@ describe('PushController', () => {
});
const pushStatusId = await sendPush(payload, {}, config, auth);
// it is enqueued so it can take time
await new Promise(resolve => {
setTimeout(() => {
resolve();
}, 1000);
});
await sleep(1000);
Parse.serverURL = 'http://localhost:8378/1'; // GOOD url
const result = await Parse.Push.getPushStatus(pushStatusId);
expect(result).toBeDefined();
Expand Down Expand Up @@ -767,7 +763,7 @@ describe('PushController', () => {
});
});

it('should not schedule push when not configured', done => {
it('should not schedule push when not configured', async () => {
const config = Config.get(Parse.applicationId);
const auth = {
isMaster: true,
Expand Down Expand Up @@ -800,33 +796,20 @@ describe('PushController', () => {
installations.push(installation);
}

reconfigureServer({
await reconfigureServer({
push: { adapter: pushAdapter },
})
.then(() => {
return Parse.Object.saveAll(installations)
.then(() => {
return pushController.sendPush(payload, {}, config, auth);
})
.then(() => new Promise(resolve => setTimeout(resolve, 300)));
})
.then(() => {
const query = new Parse.Query('_PushStatus');
return query.find({ useMasterKey: true }).then(results => {
expect(results.length).toBe(1);
const pushStatus = results[0];
expect(pushStatus.get('status')).not.toBe('scheduled');
done();
});
})
.catch(err => {
console.error(err);
fail('should not fail');
done();
});
});
await Parse.Object.saveAll(installations);
await pushController.sendPush(payload, {}, config, auth);
await sleep(1000);
const query = new Parse.Query('_PushStatus');
const results = await query.find({ useMasterKey: true });
expect(results.length).toBe(1);
const pushStatus = results[0];
expect(pushStatus.get('status')).not.toBe('scheduled');
});

it('should schedule push when configured', done => {
it('should schedule push when configured', async () => {
const auth = {
isMaster: true,
};
Expand Down Expand Up @@ -866,28 +849,19 @@ describe('PushController', () => {
installation.set('deviceType', 'ios');
installations.push(installation);
}
reconfigureServer({
await reconfigureServer({
push: { adapter: pushAdapter },
scheduledPush: true,
})
.then(() => {
const config = Config.get(Parse.applicationId);
return Parse.Object.saveAll(installations)
.then(() => {
return pushController.sendPush(payload, {}, config, auth);
})
.then(() => new Promise(resolve => setTimeout(resolve, 300)));
})
.then(() => {
const query = new Parse.Query('_PushStatus');
return query.find({ useMasterKey: true }).then(results => {
expect(results.length).toBe(1);
const pushStatus = results[0];
expect(pushStatus.get('status')).toBe('scheduled');
});
})
.then(done)
.catch(done.err);
});
const config = Config.get(Parse.applicationId);
await Parse.Object.saveAll(installations);
await pushController.sendPush(payload, {}, config, auth);
await sleep(1000);
mtrezza marked this conversation as resolved.
Show resolved Hide resolved
const query = new Parse.Query('_PushStatus');
const results = await query.find({ useMasterKey: true });
expect(results.length).toBe(1);
const pushStatus = results[0];
expect(pushStatus.get('status')).toBe('scheduled');
});

it('should not enqueue push when device token is not set', async () => {
Expand Down