Ported purchase, add unit tests, created new user purchase route, and added tests

This commit is contained in:
Keith Holliday
2016-04-01 08:14:15 -05:00
parent 3089658cc7
commit ad0bc58028
7 changed files with 358 additions and 71 deletions

View File

@@ -0,0 +1,35 @@
import {
generateUser,
translate as t,
} from '../../../../helpers/api-integration/v3';
describe('POST /user/purchase/:type/:key', () => {
let user;
let type = 'hatchingPotions';
let key = 'Base';
beforeEach(async () => {
user = await generateUser({
balance: 40,
});
});
// More tests in common code unit tests
it('returns an error when key is not provided', async () => {
await expect(user.post(`/user/purchase/gems/gem`))
.to.eventually.be.rejected.and.eql({
code: 401,
error: 'NotAuthorized',
message: t('mustSubscribeToPurchaseGems'),
});
});
it('purchases a gem item', async () => {
let res = await user.post(`/user/purchase/${type}/${key}`);
await user.sync();
expect(res.message).to.equal(t('purchased', {type, key}));
expect(user.items[type][key]).to.equal(1);
});
});