-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
POST-user_push_device.test.js
64 lines (55 loc) · 2.03 KB
/
POST-user_push_device.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import {
generateUser,
translate as t,
} from '../../../../helpers/api-integration/v3';
describe('POST /user/push-devices', () => {
let user;
const regId = '10';
const type = 'ios';
beforeEach(async () => {
user = await generateUser();
});
it('returns an error when regId is not provided', async () => {
await expect(user.post('/user/push-devices'), { type })
.to.eventually.be.rejected.and.to.eql({
code: 400,
error: 'BadRequest',
message: 'Invalid request parameters.',
});
});
it('returns an error when type is not provided', async () => {
await expect(user.post('/user/push-devices', { regId }))
.to.eventually.be.rejected.and.to.eql({
code: 400,
error: 'BadRequest',
message: 'Invalid request parameters.',
});
});
it('returns an error when type is not valid', async () => {
await expect(user.post('/user/push-devices', { regId, type: 'invalid' }))
.to.eventually.be.rejected.and.to.eql({
code: 400,
error: 'BadRequest',
message: 'Invalid request parameters.',
});
});
it('fails silently if user already has the push device', async () => {
await user.post('/user/push-devices', { type, regId });
const response = await user.post('/user/push-devices', { type, regId });
await user.sync();
expect(response.message).to.equal(t('pushDeviceAdded'));
expect(response.data[0].type).to.equal(type);
expect(response.data[0].regId).to.equal(regId);
expect(user.pushDevices[0].type).to.equal(type);
expect(user.pushDevices[0].regId).to.equal(regId);
});
it('adds a push device to the user', async () => {
const response = await user.post('/user/push-devices', { type, regId });
await user.sync();
expect(response.message).to.equal(t('pushDeviceAdded'));
expect(response.data[0].type).to.equal(type);
expect(response.data[0].regId).to.equal(regId);
expect(user.pushDevices[0].type).to.equal(type);
expect(user.pushDevices[0].regId).to.equal(regId);
});
});