Files
habitica/test/common/ops/buy/buyMysterySet.js
T
Keith Holliday 7fe2504906 Bulk purchasing (#9196)
* Moved buy tests

* Added mystery buy to buy.js

* Added quest purchasing to buy

* Added buy special

* Moved integration tests to buy folder

* Removed buyGear dependency

* Removed buyArmoire dependency

* Removed buyHealthPotion dependency

* Removed myster, quest and special dependency

* Replaced functions with factory

* Added bulk purchasing to common

* Added bulk purchasing to the api

* Added bulk purchasing to client

* Refactored purchasing function to reduce long method

* Added bulk purchase to gem purchases

* Added bulk purchasing to api

* Added bulk purchasing to gem items on client

* Removed bulk from equipment

* Removed recentlyPurchased

* Fixed style issues and prevented puchasing more gems than are left

* Fixed lint

* Fixed missing keys

* Fixed gem amount notice

* Added quest modal to pinned item

* Added bulk purchase to gem modal

* Fixed styles

* Fixed bulk purchase for spells

* Fixed modal size

* Hid autofill
2017-10-23 16:05:35 -05:00

77 lines
2.5 KiB
JavaScript

/* eslint-disable camelcase */
import {
generateUser,
} from '../../../helpers/common.helper';
import buyMysterySet from '../../../../website/common/script/ops/buyMysterySet';
import {
NotAuthorized,
NotFound,
} from '../../../../website/common/script/libs/errors';
import i18n from '../../../../website/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', (done) => {
try {
buyMysterySet(user, {params: {key: '201501'}});
} catch (err) {
expect(err).to.be.an.instanceof(NotAuthorized);
expect(err.message).to.eql(i18n.t('notEnoughHourglasses'));
expect(user.items.gear.owned).to.have.property('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,
};
try {
buyMysterySet(user, {params: {key: '301404'}});
} catch (err) {
expect(err).to.be.an.instanceof(NotFound);
expect(err.message).to.eql(i18n.t('mysterySetNotFound'));
expect(user.purchased.plan.consecutive.trinkets).to.eql(1);
done();
}
});
});
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);
});
});
});
});