7fe2504906
* 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
80 lines
1.9 KiB
JavaScript
80 lines
1.9 KiB
JavaScript
import buySpecialSpell from '../../../../website/common/script/ops/buySpecialSpell';
|
|
import {
|
|
BadRequest,
|
|
NotFound,
|
|
NotAuthorized,
|
|
} from '../../../../website/common/script/libs/errors';
|
|
import i18n from '../../../../website/common/script/i18n';
|
|
import {
|
|
generateUser,
|
|
} from '../../../helpers/common.helper';
|
|
import content from '../../../../website/common/script/content/index';
|
|
|
|
describe('shared.ops.buySpecialSpell', () => {
|
|
let user;
|
|
|
|
beforeEach(() => {
|
|
user = generateUser();
|
|
});
|
|
|
|
it('throws an error if params.key is missing', (done) => {
|
|
try {
|
|
buySpecialSpell(user);
|
|
} catch (err) {
|
|
expect(err).to.be.an.instanceof(BadRequest);
|
|
expect(err.message).to.equal(i18n.t('missingKeyParam'));
|
|
done();
|
|
}
|
|
});
|
|
|
|
it('throws an error if the spell doesn\'t exists', (done) => {
|
|
try {
|
|
buySpecialSpell(user, {
|
|
params: {
|
|
key: 'notExisting',
|
|
},
|
|
});
|
|
} catch (err) {
|
|
expect(err).to.be.an.instanceof(NotFound);
|
|
expect(err.message).to.equal(i18n.t('spellNotFound', {spellId: 'notExisting'}));
|
|
done();
|
|
}
|
|
});
|
|
|
|
it('throws an error if the user doesn\'t have enough gold', (done) => {
|
|
user.stats.gp = 1;
|
|
try {
|
|
buySpecialSpell(user, {
|
|
params: {
|
|
key: 'thankyou',
|
|
},
|
|
});
|
|
} catch (err) {
|
|
expect(err).to.be.an.instanceof(NotAuthorized);
|
|
expect(err.message).to.equal(i18n.t('messageNotEnoughGold'));
|
|
done();
|
|
}
|
|
});
|
|
|
|
it('buys an item', () => {
|
|
user.stats.gp = 11;
|
|
let item = content.special.thankyou;
|
|
|
|
let [data, message] = buySpecialSpell(user, {
|
|
params: {
|
|
key: 'thankyou',
|
|
},
|
|
});
|
|
|
|
expect(user.stats.gp).to.equal(1);
|
|
expect(user.items.special.thankyou).to.equal(1);
|
|
expect(data).to.eql({
|
|
items: user.items,
|
|
stats: user.stats,
|
|
});
|
|
expect(message).to.equal(i18n.t('messageBought', {
|
|
itemText: item.text(),
|
|
}));
|
|
});
|
|
});
|