raise coverage for user api calls (#10099)

* user integration tests

* fix lint
This commit is contained in:
negue
2018-03-17 21:12:53 +01:00
committed by Matteo Pagliazzi
parent 3d4107db3e
commit 1812f63812
4 changed files with 100 additions and 2 deletions

View File

@@ -0,0 +1,24 @@
import {
generateUser,
translate as t,
} from '../../../../helpers/api-integration/v3';
describe('GET /user/in-app-rewards', () => {
let user;
before(async () => {
user = await generateUser();
});
it('returns the reward items available for purchase', async () => {
let buyList = await user.get('/user/in-app-rewards');
expect(_.find(buyList, item => {
return item.text === t('armorWarrior1Text');
})).to.exist;
expect(_.find(buyList, item => {
return item.text === t('armorWarrior2Text');
})).to.not.exist;
});
});

View File

@@ -0,0 +1,27 @@
import {
generateUser,
translate as t,
} from '../../../../helpers/api-integration/v3';
describe('GET /user/toggle-pinned-item', () => {
let user;
before(async () => {
user = await generateUser();
});
it('cannot unpin potion', async () => {
await expect(user.get('/user/toggle-pinned-item/potion/potion'))
.to.eventually.be.rejected.and.eql({
code: 400,
error: 'BadRequest',
message: t('cannotUnpinArmoirPotion'),
});
});
it('can pin shield_rogue_5', async () => {
let result = await user.get('/user/toggle-pinned-item/marketGear/gear.flat.shield_rogue_5');
expect(result.pinnedItems.length).to.be.eql(user.pinnedItems.length + 1);
});
});

View File

@@ -258,11 +258,31 @@ describe('POST /user/class/cast/:spellId', () => {
expect(user.achievements.birthday).to.equal(1); expect(user.achievements.birthday).to.equal(1);
}); });
it('passes correct target to spell when targetType === \'task\'', async () => {
await user.update({'stats.class': 'wizard', 'stats.lvl': 11});
let task = await user.post('/tasks/user', {
text: 'test habit',
type: 'habit',
});
let result = await user.post(`/user/class/cast/fireball?targetId=${task._id}`);
expect(result.task._id).to.equal(task._id);
});
it('passes correct target to spell when targetType === \'self\'', async () => {
await user.update({'stats.class': 'wizard', 'stats.lvl': 14, 'stats.mp': 50});
let result = await user.post('/user/class/cast/frost');
expect(result.user.stats.mp).to.equal(10);
});
// TODO find a way to have sinon working in integration tests // TODO find a way to have sinon working in integration tests
// it doesn't work when tests are running separately from server // it doesn't work when tests are running separately from server
it('passes correct target to spell when targetType === \'task\'');
it('passes correct target to spell when targetType === \'tasks\''); it('passes correct target to spell when targetType === \'tasks\'');
it('passes correct target to spell when targetType === \'self\'');
it('passes correct target to spell when targetType === \'party\''); it('passes correct target to spell when targetType === \'party\'');
it('passes correct target to spell when targetType === \'user\''); it('passes correct target to spell when targetType === \'user\'');
it('passes correct target to spell when targetType === \'party\' and user is not in a party'); it('passes correct target to spell when targetType === \'party\' and user is not in a party');

View File

@@ -27,6 +27,33 @@ describe('PUT /user', () => {
expect(user.stats.hp).to.eql(14); expect(user.stats.hp).to.eql(14);
}); });
it('tags must be an array', async () => {
await expect(user.put('/user', {
tags: {
tag: true,
},
})).to.eventually.be.rejected.and.eql({
code: 400,
error: 'BadRequest',
message: 'mustBeArray',
});
});
it('update tags', async () => {
let userTags = user.tags;
await user.put('/user', {
tags: [...user.tags, {
name: 'new tag',
}],
});
await user.sync();
expect(user.tags.length).to.be.eql(userTags.length + 1);
});
it('profile.name cannot be an empty string or null', async () => { it('profile.name cannot be an empty string or null', async () => {
await expect(user.put('/user', { await expect(user.put('/user', {
'profile.name': ' ', // string should be trimmed 'profile.name': ' ', // string should be trimmed