add routes for buy ops and integration tests

This commit is contained in:
Matteo Pagliazzi
2016-03-20 17:41:17 +01:00
parent fea2e0d8c0
commit 480194f53c
8 changed files with 286 additions and 10 deletions
@@ -0,0 +1,42 @@
import {
generateUser,
translate as t,
} from '../../../../helpers/api-integration/v3';
import shared from '../../../../../common/script';
let content = shared.content;
describe('POST /user/buy/:key', () => {
let user;
beforeEach(async () => {
user = await generateUser({
'stats.gp': 400,
});
});
// More tests in common code unit tests
it('returns an error if the item is not found', async () => {
await expect(user.post(`/user/buy/notExisting`))
.to.eventually.be.rejected.and.eql({
code: 404,
error: 'NotFound',
message: t('itemNotFound', {key: 'notExisting'}),
});
});
it('buys an item', async () => {
let potion = content.potion;
let res = await user.post(`/user/buy/potion`);
await user.sync();
expect(res.data).to.eql({
items: JSON.parse(JSON.stringify(user.items)), // otherwise dates can't be compared
achievements: user.achievements,
stats: user.stats,
flags: JSON.parse(JSON.stringify(user.flags)), // otherwise dates can't be compared
});
expect(res.message).to.equal(t('messageBought', {itemText: potion.text()}));
});
});
@@ -0,0 +1,42 @@
import {
generateUser,
translate as t,
} from '../../../../helpers/api-integration/v3';
describe('POST /user/buy-mystery-set/:key', () => {
let user;
beforeEach(async () => {
user = await generateUser({
'purchased.plan.consecutive.trinkets': 1,
});
});
// More tests in common code unit tests
it('returns an error if the mystery set is not found', async () => {
await expect(user.post(`/user/buy-mystery-set/notExisting`))
.to.eventually.be.rejected.and.eql({
code: 404,
error: 'NotFound',
message: t('mysterySetNotFound'),
});
});
it('buys a mystery set', async () => {
let key = 301404;
let res = await user.post(`/user/buy-mystery-set/${key}`);
await user.sync();
expect(res.data).to.eql({
items: JSON.parse(JSON.stringify(user.items)), // otherwise dates can't be compared
purchased: {
plan: {
consecutive: user.purchased.plan.consecutive,
},
},
});
expect(res.message).to.equal(t('hourglassPurchaseSet'));
});
});
@@ -0,0 +1,40 @@
import {
generateUser,
translate as t,
} from '../../../../helpers/api-integration/v3';
import shared from '../../../../../common/script';
let content = shared.content;
describe('POST /user/buy-quest/:key', () => {
let user;
beforeEach(async () => {
user = await generateUser();
});
// More tests in common code unit tests
it('returns an error if the quest is not found', async () => {
await expect(user.post(`/user/buy-quest/notExisting`))
.to.eventually.be.rejected.and.eql({
code: 404,
error: 'NotFound',
message: t('questNotFound', {key: 'notExisting'}),
});
});
it('buys a quest', async () => {
let key = 'dilatoryDistress1';
let item = content.quests[key];
await user.update({'stats.gp': 250});
let res = await user.post(`/user/buy-quest/${key}`);
await user.sync();
expect(res.data).to.eql(user.items.quests);
expect(res.message).to.equal(t('messageBought', {
itemText: item.text(),
}));
});
});
@@ -0,0 +1,43 @@
import {
generateUser,
translate as t,
} from '../../../../helpers/api-integration/v3';
import shared from '../../../../../common/script';
let content = shared.content;
describe('POST /user/buy-special-spell/:key', () => {
let user;
beforeEach(async () => {
user = await generateUser();
});
// More tests in common code unit tests
it('returns an error if the special spell is not found', async () => {
await expect(user.post(`/user/buy-special-spell/notExisting`))
.to.eventually.be.rejected.and.eql({
code: 404,
error: 'NotFound',
message: t('spellNotFound', {spellId: 'notExisting'}),
});
});
it('buys a special spell', async () => {
let key = 'thankyou';
let item = content.special[key];
await user.update({'stats.gp': 250});
let res = await user.post(`/user/buy-special-spell/${key}`);
await user.sync();
expect(res.data).to.eql({
items: JSON.parse(JSON.stringify(user.items)), // otherwise dates can't be compared
stats: user.stats,
});
expect(res.message).to.equal(t('messageBought', {
itemText: item.text(),
}));
});
});