Ported unlock. Add unit tests. Create unlock route. Add integration tests

This commit is contained in:
Keith Holliday
2016-04-06 15:53:32 -05:00
parent a72c6c782d
commit 2bd710a882
7 changed files with 214 additions and 47 deletions

View File

@@ -0,0 +1,37 @@
import {
generateUser,
translate as t,
} from '../../../../helpers/api-integration/v3';
describe('POST /user/unlock', () => {
let user;
let unlockPath = 'shirt.convict,shirt.cross,shirt.fire,shirt.horizon,shirt.ocean,shirt.purple,shirt.rainbow,shirt.redblue,shirt.thunder,shirt.tropical,shirt.zombie';
let unlockCost = 1.25;
let usersStartingGems = 5;
beforeEach(async () => {
user = await generateUser();
});
it('returns an error when user balance is too low', async () => {
await expect(user.post(`/user/unlock?path=${unlockPath}`))
.to.eventually.be.rejected.and.to.eql({
code: 401,
error: 'NotAuthorized',
message: t('notEnoughGems'),
});
});
// More tests in common code unit tests
it('reduces a user\'s balance', async () => {
await user.update({
balance: usersStartingGems,
});
let response = await user.post(`/user/unlock?path=${unlockPath}`);
await user.sync();
expect(response.message).to.equal(t('unlocked'));
expect(user.balance).to.equal(usersStartingGems - unlockCost);
});
});