mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 06:37:23 +01:00
Added buy special support to buy route (#9130)
This commit is contained in:
@@ -56,6 +56,7 @@ describe('POST /user/buy/:key', () => {
|
||||
message: t('messageHealthAlreadyMax'),
|
||||
});
|
||||
});
|
||||
|
||||
it('buys a piece of gear', async () => {
|
||||
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);
|
||||
});
|
||||
|
||||
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(),
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -870,7 +870,16 @@ api.buy = {
|
||||
url: '/user/buy/:key',
|
||||
async handler (req, res) {
|
||||
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();
|
||||
res.respond(200, ...buyRes);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user