add tests for shared.ops.buySpecialSpell and partially fix shared.ops.buy

This commit is contained in:
Matteo Pagliazzi
2016-03-20 13:46:56 +01:00
parent 2560096466
commit 657f19af0d
5 changed files with 76 additions and 5 deletions
+1 -1
View File
@@ -73,7 +73,7 @@ module.exports = function buy (user, req = {}, analytics) {
dropText: drop.text(req.language),
};
} else if ((!_.isEmpty(eligibleEquipment) && armoireResult < 0.8) || armoireResult < 0.5) { // eslint-disable-line no-extra-parens
drop = randomVal(_.where(content.food, {
drop = randomVal(user, _.where(content.food, {
canDrop: true,
}));
user.items.food[drop.key] = user.items.food[drop.key] || 0;
+1 -1
View File
@@ -14,7 +14,7 @@ import {
} from '../../../common/script/libs/errors';
import i18n from '../../../common/script/i18n';
describe.only('shared.ops.buy', () => {
describe('shared.ops.buy', () => {
let user;
let fns = {
predictableRandom,
+1 -2
View File
@@ -7,9 +7,8 @@ import {
NotFound,
} from '../../../common/script/libs/errors';
import i18n from '../../../common/script/i18n';
import testHelper from '../test_helper';
describe.only('shared.ops.buyQuest', () => {
describe('shared.ops.buyQuest', () => {
let user;
beforeEach(() => {
+73
View File
@@ -0,0 +1,73 @@
import buySpecialSpell from '../../../common/script/ops/buySpecialSpell';
import {
BadRequest,
NotFound,
NotAuthorized,
} from '../../../common/script/libs/errors';
import i18n from '../../../common/script/i18n';
import {
generateUser,
} from '../../helpers/common.helper';
import content from '../../../common/script/content/index';
describe('shared.ops.buySpecialSpell', () => {
let user;
beforeEach(() => {
user = generateUser();
});
it('throws an error if params.key is missing', () => {
try {
expect(buySpecialSpell(user)).to.throw(BadRequest);
} catch (err) {
expect(err.message).to.equal(i18n.t('missingKeyParam'));
}
});
it('throws an error if the spell doesn\'t exists', () => {
try {
expect(buySpecialSpell(user, {
params: {
key: 'notExisting',
},
})).to.throw(NotFound);
} catch (err) {
expect(err.message).to.equal(i18n.t('spellNotFound', {spellId: 'notExisting'}));
}
});
it('throws an error if the user doesn\'t have enough gold', () => {
user.stats.gp = 1;
try {
expect(buySpecialSpell(user, {
params: {
key: 'thankyou',
},
})).to.throw(NotAuthorized);
} catch (err) {
expect(err.message).to.equal(i18n.t('messageNotEnoughGold'));
}
});
it('buys an item', () => {
user.stats.gp = 11;
let item = content.special.thankyou;
let res = buySpecialSpell(user, {
params: {
key: 'thankyou',
},
});
expect(user.stats.gp).to.equal(1);
expect(user.items.special.thankyou).to.equal(1);
expect(res.data).to.eql({
items: user.items,
stats: user.stats,
});
expect(res.message).to.equal(i18n.t('messageBought', {
itemText: item.text(),
}));
});
});
-1
View File
@@ -229,7 +229,6 @@ export let schema = new Schema({
todos: Array, // [{data: Date, value: Number}] // big peformance issues if these are defined
},
// TODO we're storing too many fields here, find a way to reduce them
items: {
gear: {
owned: _.transform(shared.content.gear.flat, (m, v) => {