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
This commit is contained in:
Keith Holliday
2017-10-23 16:05:35 -05:00
committed by GitHub
parent b74cee3d21
commit 7fe2504906
32 changed files with 578 additions and 265 deletions
@@ -0,0 +1,100 @@
/* eslint-disable camelcase */
import {
generateUser,
translate as t,
} from '../../../../../helpers/api-integration/v3';
import shared from '../../../../../../website/common/script';
let content = shared.content;
describe('POST /user/buy/:key', () => {
let user;
beforeEach(async () => {
user = await generateUser({
'stats.gp': 400,
});
});
// More tests in common code unit tests
it('returns an error if the item is not found', async () => {
await expect(user.post('/user/buy/notExisting'))
.to.eventually.be.rejected.and.eql({
code: 404,
error: 'NotFound',
message: t('itemNotFound', {key: 'notExisting'}),
});
});
it('buys a potion', async () => {
await user.update({
'stats.gp': 400,
'stats.hp': 40,
});
let potion = content.potion;
let res = await user.post('/user/buy/potion');
await user.sync();
expect(user.stats.hp).to.equal(50);
expect(res.data).to.eql(user.stats);
expect(res.message).to.equal(t('messageBought', {itemText: potion.text()}));
});
it('returns an error if user tries to buy a potion with full health', async () => {
await user.update({
'stats.gp': 40,
'stats.hp': 50,
});
await expect(user.post('/user/buy/potion'))
.to.eventually.be.rejected.and.eql({
code: 401,
error: 'NotAuthorized',
message: t('messageHealthAlreadyMax'),
});
});
it('buys a piece of gear', async () => {
let key = 'armor_warrior_1';
await user.post(`/user/buy/${key}`);
await user.sync();
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(),
}));
});
it('allows for bulk purchases', async () => {
await user.update({
'stats.gp': 400,
'stats.hp': 20,
});
let potion = content.potion;
let res = await user.post('/user/buy/potion', {quantity: 2});
await user.sync();
expect(user.stats.hp).to.equal(50);
expect(res.data).to.eql(user.stats);
expect(res.message).to.equal(t('messageBought', {itemText: potion.text()}));
});
});
@@ -0,0 +1,41 @@
import {
generateUser,
translate as t,
} from '../../../../../helpers/api-integration/v3';
describe('POST /user/buy-armoire', () => {
let user;
beforeEach(async () => {
user = await generateUser({
'stats.gp': 400,
});
});
// More tests in common code unit tests
it('returns an error if user does not have enough gold', async () => {
await user.update({
'stats.gp': 5,
});
await expect(user.post('/user/buy-armoire'))
.to.eventually.be.rejected.and.eql({
code: 401,
error: 'NotAuthorized',
message: t('messageNotEnoughGold'),
});
});
it('reduces gold when buying from the armoire', async () => {
await user.post('/user/buy-armoire');
await user.sync();
expect(user.stats.gp).to.equal(300);
});
xit('buys a piece of armoire', async () => {
// Skipped because can't stub predictableRandom correctly
});
});
@@ -0,0 +1,36 @@
/* eslint-disable camelcase */
import {
generateUser,
translate as t,
} from '../../../../../helpers/api-integration/v3';
describe('POST /user/buy-gear/:key', () => {
let user;
beforeEach(async () => {
user = await generateUser({
'stats.gp': 400,
});
});
// More tests in common code unit tests
it('returns an error if the item is not found', async () => {
await expect(user.post('/user/buy-gear/notExisting'))
.to.eventually.be.rejected.and.eql({
code: 404,
error: 'NotFound',
message: t('itemNotFound', {key: 'notExisting'}),
});
});
it('buys a piece of gear', async () => {
let key = 'armor_warrior_1';
await user.post(`/user/buy-gear/${key}`);
await user.sync();
expect(user.items.gear.owned.armor_warrior_1).to.eql(true);
});
});
@@ -0,0 +1,42 @@
import {
generateUser,
translate as t,
} from '../../../../../helpers/api-integration/v3';
import shared from '../../../../../../website/common/script';
let content = shared.content;
describe('POST /user/buy-health-potion', () => {
let user;
beforeEach(async () => {
user = await generateUser({
'stats.hp': 40,
});
});
// More tests in common code unit tests
it('returns an error if user does not have enough gold', async () => {
await expect(user.post('/user/buy-health-potion'))
.to.eventually.be.rejected.and.eql({
code: 401,
error: 'NotAuthorized',
message: t('messageNotEnoughGold'),
});
});
it('buys a potion', async () => {
await user.update({
'stats.gp': 400,
});
let potion = content.potion;
let res = await user.post('/user/buy-health-potion');
await user.sync();
expect(user.stats.hp).to.equal(50);
expect(res.data).to.eql(user.stats);
expect(res.message).to.equal(t('messageBought', {itemText: potion.text()}));
});
});
@@ -0,0 +1,38 @@
import {
generateUser,
translate as t,
} from '../../../../../helpers/api-integration/v3';
describe('POST /user/buy-mystery-set/:key', () => {
let user;
beforeEach(async () => {
user = await generateUser({
'purchased.plan.consecutive.trinkets': 1,
});
});
// More tests in common code unit tests
it('returns an error if the mystery set is not found', async () => {
await expect(user.post('/user/buy-mystery-set/notExisting'))
.to.eventually.be.rejected.and.eql({
code: 404,
error: 'NotFound',
message: t('mysterySetNotFound'),
});
});
it('buys a mystery set', async () => {
let key = 301404;
let res = await user.post(`/user/buy-mystery-set/${key}`);
await user.sync();
expect(res.data).to.eql({
items: JSON.parse(JSON.stringify(user.items)), // otherwise dates can't be compared
purchasedPlanConsecutive: user.purchased.plan.consecutive,
});
expect(res.message).to.equal(t('hourglassPurchaseSet'));
});
});
@@ -0,0 +1,40 @@
import {
generateUser,
translate as t,
} from '../../../../../helpers/api-integration/v3';
import shared from '../../../../../../website/common/script';
let content = shared.content;
describe('POST /user/buy-quest/:key', () => {
let user;
beforeEach(async () => {
user = await generateUser();
});
// More tests in common code unit tests
it('returns an error if the quest is not found', async () => {
await expect(user.post('/user/buy-quest/notExisting'))
.to.eventually.be.rejected.and.eql({
code: 404,
error: 'NotFound',
message: t('questNotFound', {key: 'notExisting'}),
});
});
it('buys a quest', async () => {
let key = 'dilatoryDistress1';
let item = content.quests[key];
await user.update({'stats.gp': 250});
let res = await user.post(`/user/buy-quest/${key}`);
await user.sync();
expect(res.data).to.eql(user.items.quests);
expect(res.message).to.equal(t('messageBought', {
itemText: item.text(),
}));
});
});
@@ -0,0 +1,43 @@
import {
generateUser,
translate as t,
} from '../../../../../helpers/api-integration/v3';
import shared from '../../../../../../website/common/script';
let content = shared.content;
describe('POST /user/buy-special-spell/:key', () => {
let user;
beforeEach(async () => {
user = await generateUser();
});
// More tests in common code unit tests
it('returns an error if the special spell is not found', async () => {
await expect(user.post('/user/buy-special-spell/notExisting'))
.to.eventually.be.rejected.and.eql({
code: 404,
error: 'NotFound',
message: t('spellNotFound', {spellId: 'notExisting'}),
});
});
it('buys a special spell', async () => {
let key = 'thankyou';
let item = content.special[key];
await user.update({'stats.gp': 250});
let res = await user.post(`/user/buy-special-spell/${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(),
}));
});
});