2016-06-22 22:19:37 +00:00
|
|
|
import {
|
|
|
|
|
generateUser,
|
|
|
|
|
translate as t,
|
|
|
|
|
} from '../../../../helpers/api-integration/v3';
|
|
|
|
|
|
|
|
|
|
describe('POST /user/push-devices', () => {
|
|
|
|
|
let user;
|
2019-10-08 18:45:38 +00:00
|
|
|
const regId = '10';
|
|
|
|
|
const type = 'ios';
|
2016-06-22 22:19:37 +00:00
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
|
user = await generateUser();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('returns an error when regId is not provided', async () => {
|
2019-10-08 18:45:38 +00:00
|
|
|
await expect(user.post('/user/push-devices'), { type })
|
2016-06-22 22:19:37 +00:00
|
|
|
.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 () => {
|
2019-10-08 18:45:38 +00:00
|
|
|
await expect(user.post('/user/push-devices', { regId }))
|
2016-06-22 22:19:37 +00:00
|
|
|
.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 () => {
|
2019-10-08 18:45:38 +00:00
|
|
|
await expect(user.post('/user/push-devices', { regId, type: 'invalid' }))
|
2016-06-22 22:19:37 +00:00
|
|
|
.to.eventually.be.rejected.and.to.eql({
|
|
|
|
|
code: 400,
|
|
|
|
|
error: 'BadRequest',
|
|
|
|
|
message: 'Invalid request parameters.',
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2018-10-20 12:52:02 +00:00
|
|
|
it('fails silently if user already has the push device', async () => {
|
2019-10-08 18:45:38 +00:00
|
|
|
await user.post('/user/push-devices', { type, regId });
|
|
|
|
|
const response = await user.post('/user/push-devices', { type, regId });
|
2018-10-20 12:52:02 +00:00
|
|
|
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);
|
2016-06-22 22:19:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('adds a push device to the user', async () => {
|
2019-10-08 18:45:38 +00:00
|
|
|
const response = await user.post('/user/push-devices', { type, regId });
|
2016-06-22 22:19:37 +00:00
|
|
|
await user.sync();
|
|
|
|
|
|
|
|
|
|
expect(response.message).to.equal(t('pushDeviceAdded'));
|
2018-08-17 12:01:41 +00:00
|
|
|
expect(response.data[0].type).to.equal(type);
|
|
|
|
|
expect(response.data[0].regId).to.equal(regId);
|
2016-06-22 22:19:37 +00:00
|
|
|
expect(user.pushDevices[0].type).to.equal(type);
|
|
|
|
|
expect(user.pushDevices[0].regId).to.equal(regId);
|
|
|
|
|
});
|
|
|
|
|
});
|