54153ec299
* move to shops/purchase * move files to /buy/ instead of /purchase/ * refactor buy.js - add more itemtypes * revert moving special purchases to buy * only use buyOp from api-routes * fix buying potion client-side * undo import buy instead of purchase * enable potion bulk purchase - use buyGear as fallback (as before) * move quantity purchase inside buyHealthPotion * move quantity purchase inside buyQuest * move quantity purchase inside buySpecialSpell + add analytics * remove unused quantity variable - set req.type on specialKeys * fix `buyKnownKeys` on buy api * test buy-special-spell if not enough gold * more buy ops coverage * fix lint * buyMysterySet: test for window.confirm, buyQuest: check for Masterclassers unlock * fix test & lint * re-create package-lock.json to travis build ? * use global.window instead of method argument * add back canOwn checks * remove buyMysterySet confirm request
87 lines
2.1 KiB
JavaScript
87 lines
2.1 KiB
JavaScript
import buySpecialSpell from '../../../../website/common/script/ops/buy/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;
|
|
let analytics = {track () {}};
|
|
|
|
beforeEach(() => {
|
|
user = generateUser();
|
|
sinon.stub(analytics, 'track');
|
|
});
|
|
|
|
afterEach(() => {
|
|
analytics.track.restore();
|
|
});
|
|
|
|
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',
|
|
},
|
|
}, analytics);
|
|
|
|
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(),
|
|
}));
|
|
expect(analytics.track).to.be.calledOnce;
|
|
});
|
|
});
|