mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +01:00
Ported addPushDevice. Added unit tests. Added addPushDevice route. Added integration tests
This commit is contained in:
35
test/api/v3/integration/user/POST-user_addPushDevice.test.js
Normal file
35
test/api/v3/integration/user/POST-user_addPushDevice.test.js
Normal file
@@ -0,0 +1,35 @@
|
||||
import {
|
||||
generateUser,
|
||||
translate as t,
|
||||
} from '../../../../helpers/api-integration/v3';
|
||||
|
||||
describe('POST /user/addPushDevice', () => {
|
||||
let user;
|
||||
let regId = '10';
|
||||
let type = 'someRandomType';
|
||||
|
||||
beforeEach(async () => {
|
||||
user = await generateUser();
|
||||
});
|
||||
|
||||
it('returns an error if user already has the push device', async () => {
|
||||
await user.post('/user/addPushDevice', {type, regId});
|
||||
await expect(user.post('/user/addPushDevice', {type, regId}))
|
||||
.to.eventually.be.rejected.and.eql({
|
||||
code: 401,
|
||||
error: 'NotAuthorized',
|
||||
message: t('pushDeviceAlreadyAdded'),
|
||||
});
|
||||
});
|
||||
|
||||
// More tests in common code unit tests
|
||||
|
||||
it('adds a push device to the user', async () => {
|
||||
let response = await user.post('/user/addPushDevice', {type, regId});
|
||||
await user.sync();
|
||||
|
||||
expect(response.message).to.equal(t('pushDeviceAdded'));
|
||||
expect(user.pushDevices[0].type).to.equal(type);
|
||||
expect(user.pushDevices[0].regId).to.equal(regId);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user