Added check for balance with respect to quantity (#9469)

This commit is contained in:
Keith Holliday
2017-11-14 16:55:08 -07:00
committed by GitHub
parent 848883736d
commit c43ca62bc4
2 changed files with 19 additions and 2 deletions

View File

@@ -231,13 +231,30 @@ describe('shared.ops.purchase', () => {
context('bulk purchase', () => { context('bulk purchase', () => {
let userGemAmount = 10; let userGemAmount = 10;
before(() => { beforeEach(() => {
user.balance = userGemAmount; user.balance = userGemAmount;
user.stats.gp = goldPoints; user.stats.gp = goldPoints;
user.purchased.plan.gemsBought = 0; user.purchased.plan.gemsBought = 0;
user.purchased.plan.customerId = 'customer-id'; user.purchased.plan.customerId = 'customer-id';
}); });
it('errors when user does not have enough gems', (done) => {
user.balance = 1;
let type = 'eggs';
let key = 'TigerCub';
try {
purchase(user, {
params: {type, key},
quantity: 2,
});
} catch (err) {
expect(err).to.be.an.instanceof(NotAuthorized);
expect(err.message).to.equal(i18n.t('notEnoughGems'));
done();
}
});
it('makes bulk purchases of gems', () => { it('makes bulk purchases of gems', () => {
let [, message] = purchase(user, { let [, message] = purchase(user, {
params: {type: 'gems', key: 'gem'}, params: {type: 'gems', key: 'gem'},

View File

@@ -138,7 +138,7 @@ module.exports = function purchase (user, req = {}, analytics) {
throw new NotAuthorized(i18n.t('messageNotAvailable', req.language)); throw new NotAuthorized(i18n.t('messageNotAvailable', req.language));
} }
if (!user.balance || user.balance < price) { if (!user.balance || user.balance < price * quantity) {
throw new NotAuthorized(i18n.t('notEnoughGems', req.language)); throw new NotAuthorized(i18n.t('notEnoughGems', req.language));
} }