Added buy special support to buy route (#9130)

This commit is contained in:
Keith Holliday
2017-10-02 20:31:06 -05:00
committed by GitHub
parent 8a75383c43
commit e01c6cc9a6
2 changed files with 28 additions and 1 deletions

View File

@@ -56,6 +56,7 @@ describe('POST /user/buy/:key', () => {
message: t('messageHealthAlreadyMax'), message: t('messageHealthAlreadyMax'),
}); });
}); });
it('buys a piece of gear', async () => { it('buys a piece of gear', async () => {
let key = 'armor_warrior_1'; let key = 'armor_warrior_1';
@@ -64,4 +65,21 @@ describe('POST /user/buy/:key', () => {
expect(user.items.gear.owned.armor_warrior_1).to.eql(true); expect(user.items.gear.owned.armor_warrior_1).to.eql(true);
}); });
it('buys a special spell', async () => {
let key = 'spookySparkles';
let item = content.special[key];
await user.update({'stats.gp': 250});
let res = await user.post(`/user/buy/${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(),
}));
});
}); });

View File

@@ -870,7 +870,16 @@ api.buy = {
url: '/user/buy/:key', url: '/user/buy/:key',
async handler (req, res) { async handler (req, res) {
let user = res.locals.user; let user = res.locals.user;
let buyRes = common.ops.buy(user, req, res.analytics);
let buyRes;
let specialKeys = ['snowball', 'spookySparkles', 'shinySeed', 'seafoam'];
if (specialKeys.indexOf(req.params.key) !== -1) {
buyRes = common.ops.buySpecialSpell(user, req);
} else {
buyRes = common.ops.buy(user, req, res.analytics);
}
await user.save(); await user.save();
res.respond(200, ...buyRes); res.respond(200, ...buyRes);
}, },