Merge pull request #6898 from HabitRPG/api-v3-buy-ops

[v3] Port several shared ops and their linked fns
This commit is contained in:
Matteo Pagliazzi
2016-03-21 23:00:43 +01:00
37 changed files with 1377 additions and 535 deletions
@@ -0,0 +1,32 @@
import {
generateUser,
} from '../../../../helpers/api-integration/v3';
describe('POST /user/allocate-now', () => {
// More tests in common code unit tests
it('auto allocates all points', async () => {
let user = await generateUser({
'stats.points': 5,
'stats.int': 3,
'stats.con': 9,
'stats.per': 9,
'stats.str': 9,
'preferences.allocationMode': 'flat',
});
let res = await user.post(`/user/allocate-now`);
await user.sync();
expect(res).to.eql({
data: {
stats: user.stats,
},
});
expect(user.stats.points).to.equal(0);
expect(user.stats.con).to.equal(9);
expect(user.stats.int).to.equal(8);
expect(user.stats.per).to.equal(9);
expect(user.stats.str).to.equal(9);
});
});
@@ -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(),
}));
});
});