port tests for shared.ops.buyMysterySet.js
This commit is contained in:
@@ -44,7 +44,7 @@ module.exports = function buyMysterySet (user, req = {}, analytics) {
|
||||
user.purchased.plan.consecutive.trinkets--;
|
||||
|
||||
return {
|
||||
data: pickDeep(user, splitWhitespace('items purchased.plan.consecutive')), // TODO this is broken, _.pick doesn't support nested keys
|
||||
data: pickDeep(user, splitWhitespace('items purchased.plan.consecutive')),
|
||||
message: i18n.t('hourglassPurchaseSet', req.language),
|
||||
};
|
||||
};
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
/* eslint-disable camelcase */
|
||||
|
||||
import sinon from 'sinon'; // eslint-disable-line no-shadow
|
||||
import {
|
||||
generateUser,
|
||||
} from '../../helpers/common.helper';
|
||||
import buyMysterySet from '../../../common/script/ops/buyMysterySet';
|
||||
import {
|
||||
NotAuthorized,
|
||||
NotFound,
|
||||
} from '../../../common/script/libs/errors';
|
||||
import i18n from '../../../common/script/i18n';
|
||||
|
||||
describe('shared.ops.buyMysterySet', () => {
|
||||
let user;
|
||||
|
||||
beforeEach(() => {
|
||||
user = generateUser({
|
||||
items: {
|
||||
gear: {
|
||||
owned: {
|
||||
weapon_warrior_0: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
context('Mystery Sets', () => {
|
||||
context('failure conditions', () => {
|
||||
it('does not grant mystery sets without Mystic Hourglasses', () => {
|
||||
try {
|
||||
expect(buyMysterySet(user, {params: {key: '201501'}})).to.throw(NotAuthorized);
|
||||
} catch (err) {
|
||||
expect(err.message).to.eql(i18n.t('notEnoughHourglasses'));
|
||||
expect(user.items.gear.owned).to.have.property('weapon_warrior_0', true);
|
||||
}
|
||||
});
|
||||
|
||||
it('does not grant mystery set that has already been purchased', () => {
|
||||
user.purchased.plan.consecutive.trinkets = 1;
|
||||
user.items.gear.owned = {
|
||||
weapon_warrior_0: true,
|
||||
weapon_mystery_301404: true,
|
||||
armor_mystery_301404: true,
|
||||
head_mystery_301404: true,
|
||||
eyewear_mystery_301404: true,
|
||||
};
|
||||
|
||||
try {
|
||||
expect(buyMysterySet(user, {params: {key: '301404'}})).to.throw(NotFound);
|
||||
} catch (err) {
|
||||
expect(err.message).to.eql(i18n.t('mysterySetNotFound'));
|
||||
expect(user.purchased.plan.consecutive.trinkets).to.eql(1);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
context('successful purchases', () => {
|
||||
it('buys Steampunk Accessories Set', () => {
|
||||
user.purchased.plan.consecutive.trinkets = 1;
|
||||
buyMysterySet(user, {params: {key: '301404'}});
|
||||
|
||||
expect(user.purchased.plan.consecutive.trinkets).to.eql(0);
|
||||
expect(user.items.gear.owned).to.have.property('weapon_warrior_0', true);
|
||||
expect(user.items.gear.owned).to.have.property('weapon_mystery_301404', true);
|
||||
expect(user.items.gear.owned).to.have.property('armor_mystery_301404', true);
|
||||
expect(user.items.gear.owned).to.have.property('head_mystery_301404', true);
|
||||
expect(user.items.gear.owned).to.have.property('eyewear_mystery_301404', true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,77 +0,0 @@
|
||||
/* eslint-disable camelcase */
|
||||
|
||||
let shared = require('../../common/script/index.js');
|
||||
|
||||
describe('user.ops.buyMysterySet', () => {
|
||||
let user;
|
||||
|
||||
beforeEach(() => {
|
||||
user = {
|
||||
items: {
|
||||
gear: {
|
||||
owned: {
|
||||
weapon_warrior_0: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
purchased: {
|
||||
plan: {
|
||||
consecutive: {
|
||||
trinkets: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
shared.wrap(user);
|
||||
});
|
||||
|
||||
context('Mystery Sets', () => {
|
||||
context('failure conditions', () => {
|
||||
it('does not grant mystery sets without Mystic Hourglasses', (done) => {
|
||||
user.ops.buyMysterySet({params: {key: '201501'}}, (response) => {
|
||||
expect(response.message).to.eql('You don\'t have enough Mystic Hourglasses.');
|
||||
expect(user.items.gear.owned).to.eql({weapon_warrior_0: true});
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('does not grant mystery set that has already been purchased', (done) => {
|
||||
user.purchased.plan.consecutive.trinkets = 1;
|
||||
user.items.gear.owned = {
|
||||
weapon_warrior_0: true,
|
||||
weapon_mystery_301404: true,
|
||||
armor_mystery_301404: true,
|
||||
head_mystery_301404: true,
|
||||
eyewear_mystery_301404: true,
|
||||
};
|
||||
|
||||
user.ops.buyMysterySet({params: {key: '301404'}}, (response) => {
|
||||
expect(response.message).to.eql('Mystery set not found, or set already owned');
|
||||
expect(user.purchased.plan.consecutive.trinkets).to.eql(1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
context('successful purchases', () => {
|
||||
it('buys Steampunk Accessories Set', (done) => {
|
||||
user.purchased.plan.consecutive.trinkets = 1;
|
||||
|
||||
user.ops.buyMysterySet({params: {key: '301404'}}, () => {
|
||||
expect(user.purchased.plan.consecutive.trinkets).to.eql(0);
|
||||
expect(user.items.gear.owned).to.eql({
|
||||
weapon_warrior_0: true,
|
||||
weapon_mystery_301404: true,
|
||||
armor_mystery_301404: true,
|
||||
head_mystery_301404: true,
|
||||
eyewear_mystery_301404: true,
|
||||
});
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user