mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-05-22 05:38:46 +00:00
Add purchase related test cases
This commit is contained in:
parent
ee974dfa19
commit
33181c0ac4
10 changed files with 80 additions and 16 deletions
|
|
@ -97,7 +97,7 @@
|
|||
"test:common": "nyc --silent --no-clean mocha test/common --recursive",
|
||||
"test:content": "nyc --silent --no-clean mocha test/content --recursive",
|
||||
"test:nodemon": "gulp test:nodemon",
|
||||
"coverage": "nyc report --reporter=html --report-dir coverage/results; open coverage.html",
|
||||
"coverage": "nyc report --reporter=html --report-dir coverage/results; open coverage/results/index.html",
|
||||
"sprites": "gulp sprites:compile",
|
||||
"client:dev": "cd website/client && npm run serve",
|
||||
"client:build": "cd website/client && npm run build",
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ describe('shared.ops.buy', () => {
|
|||
}
|
||||
});
|
||||
|
||||
it('recovers 15 hp', async () => {
|
||||
it('buys health potion', async () => {
|
||||
user.stats.hp = 30;
|
||||
await buy(user, { params: { key: 'potion' } }, analytics);
|
||||
expect(user.stats.hp).to.eql(45);
|
||||
|
|
@ -22,6 +22,7 @@ async function buyGear (user, req, analytics) {
|
|||
describe('shared.ops.buyMarketGear', () => {
|
||||
let user;
|
||||
const analytics = { track () {} };
|
||||
let clock;
|
||||
|
||||
beforeEach(() => {
|
||||
user = generateUser({
|
||||
|
|
@ -54,6 +55,10 @@ describe('shared.ops.buyMarketGear', () => {
|
|||
shared.fns.predictableRandom.restore();
|
||||
shared.onboarding.checkOnboardingStatus.restore();
|
||||
analytics.track.restore();
|
||||
|
||||
if (clock) {
|
||||
clock.restore();
|
||||
}
|
||||
});
|
||||
|
||||
context('Gear', () => {
|
||||
|
|
@ -184,30 +189,28 @@ describe('shared.ops.buyMarketGear', () => {
|
|||
});
|
||||
|
||||
// TODO after user.ops.equip is done
|
||||
xit('removes one-handed weapon and shield if auto-equip is on and a two-hander is bought', async () => {
|
||||
it('removes one-handed weapon and shield if auto-equip is on and a two-hander is bought', async () => {
|
||||
user.stats.gp = 100;
|
||||
user.preferences.autoEquip = true;
|
||||
await buyGear(user, { params: { key: 'shield_warrior_1' } });
|
||||
user.ops.equip({ params: { key: 'shield_warrior_1' } });
|
||||
await buyGear(user, { params: { key: 'weapon_warrior_1' } });
|
||||
user.ops.equip({ params: { key: 'weapon_warrior_1' } });
|
||||
user.items.gear.equipped.weapon = 'weapon_warrior_1';
|
||||
user.items.gear.equipped.shield = 'shield_warrior_1';
|
||||
user.stats.class = 'wizard';
|
||||
|
||||
await buyGear(user, { params: { key: 'weapon_wizard_1' } });
|
||||
await buyGear(user, { params: { key: 'weapon_wizard_0' } });
|
||||
|
||||
expect(user.items.gear.equipped).to.have.property('shield', 'shield_base_0');
|
||||
expect(user.items.gear.equipped).to.have.property('weapon', 'weapon_wizard_1');
|
||||
expect(user.items.gear.equipped).to.have.property('weapon', 'weapon_wizard_0');
|
||||
});
|
||||
|
||||
// TODO after user.ops.equip is done
|
||||
xit('buyGears two-handed equipment but does not automatically remove sword or shield', async () => {
|
||||
it('buyGears two-handed equipment but does not automatically remove sword or shield', async () => {
|
||||
user.stats.gp = 100;
|
||||
user.preferences.autoEquip = false;
|
||||
await buyGear(user, { params: { key: 'shield_warrior_1' } });
|
||||
user.ops.equip({ params: { key: 'shield_warrior_1' } });
|
||||
await buyGear(user, { params: { key: 'weapon_warrior_1' } });
|
||||
user.ops.equip({ params: { key: 'weapon_warrior_1' } });
|
||||
user.items.gear.equipped.weapon = 'weapon_warrior_1';
|
||||
user.items.gear.equipped.shield = 'shield_warrior_1';
|
||||
user.stats.class = 'wizard';
|
||||
|
||||
await buyGear(user, { params: { key: 'weapon_wizard_1' } });
|
||||
await buyGear(user, { params: { key: 'weapon_wizard_0' } });
|
||||
|
||||
expect(user.items.gear.equipped).to.have.property('shield', 'shield_warrior_1');
|
||||
expect(user.items.gear.equipped).to.have.property('weapon', 'weapon_warrior_1');
|
||||
|
|
@ -283,5 +286,40 @@ describe('shared.ops.buyMarketGear', () => {
|
|||
|
||||
expect(user.items.gear.owned).to.have.property('shield_armoire_ramHornShield', true);
|
||||
});
|
||||
|
||||
it('buys current seasonal gear', async () => {
|
||||
user.stats.gp = 200;
|
||||
clock = sinon.useFakeTimers(new Date('2024-01-01'));
|
||||
|
||||
await buyGear(user, { params: { key: 'armor_special_winter2024Warrior' } });
|
||||
|
||||
expect(user.items.gear.owned).to.have.property('armor_special_winter2024Warrior', true);
|
||||
});
|
||||
|
||||
it('errors when buying past seasonal gear', async () => {
|
||||
clock = sinon.useFakeTimers(new Date('2024-01-01'));
|
||||
user.stats.gp = 200;
|
||||
|
||||
try {
|
||||
await buyGear(user, { params: { key: 'armor_special_winter2023Warrior' } });
|
||||
} catch (err) {
|
||||
expect(err).to.be.an.instanceof(NotAuthorized);
|
||||
expect(err.message).to.equal(i18n.t('notAvailable'));
|
||||
expect(user.items.gear.owned).to.not.have.property('armor_special_winter2023Warrior');
|
||||
}
|
||||
});
|
||||
|
||||
it('errors when buying gear from wrong season', async () => {
|
||||
clock = sinon.useFakeTimers(new Date('2024-01-01'));
|
||||
user.stats.gp = 200;
|
||||
|
||||
try {
|
||||
await buyGear(user, { params: { key: 'weapon_special_spring2024Warrior' } });
|
||||
} catch (err) {
|
||||
expect(err).to.be.an.instanceof(NotAuthorized);
|
||||
expect(err.message).to.equal(i18n.t('notAvailable'));
|
||||
expect(user.items.gear.owned).to.not.have.property('weapon_special_spring2024Warrior');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -15,6 +15,7 @@ import { errorMessage } from '../../../../website/common/script/libs/errorMessag
|
|||
describe('shared.ops.buyMysterySet', () => {
|
||||
let user;
|
||||
const analytics = { track () {} };
|
||||
let clock;
|
||||
|
||||
beforeEach(() => {
|
||||
user = generateUser({
|
||||
|
|
@ -31,6 +32,9 @@ describe('shared.ops.buyMysterySet', () => {
|
|||
|
||||
afterEach(() => {
|
||||
analytics.track.restore();
|
||||
if (clock) {
|
||||
clock.restore();
|
||||
}
|
||||
});
|
||||
|
||||
context('Mystery Sets', () => {
|
||||
|
|
@ -41,7 +45,7 @@ describe('shared.ops.buyMysterySet', () => {
|
|||
} 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);
|
||||
expect(user.items.gear.owned).to.not.have.property('armor_mystery_201501');
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -72,6 +76,18 @@ describe('shared.ops.buyMysterySet', () => {
|
|||
expect(err.message).to.equal(errorMessage('missingKeyParam'));
|
||||
}
|
||||
});
|
||||
|
||||
it('returns error if the set is not available', async () => {
|
||||
user.purchased.plan.consecutive.trinkets = 1;
|
||||
clock = sinon.useFakeTimers(new Date('2024-01-16'));
|
||||
try {
|
||||
await buyMysterySet(user, { params: { key: '201501' } });
|
||||
} catch (err) {
|
||||
expect(err).to.be.an.instanceof(NotAuthorized);
|
||||
expect(err.message).to.eql(i18n.t('notAvailable'));
|
||||
expect(user.items.gear.owned).to.not.have.property('armor_mystery_201501');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
context('successful purchases', () => {
|
||||
|
|
@ -86,6 +102,16 @@ describe('shared.ops.buyMysterySet', () => {
|
|||
expect(user.items.gear.owned).to.have.property('head_mystery_301404', true);
|
||||
expect(user.items.gear.owned).to.have.property('eyewear_mystery_301404', true);
|
||||
});
|
||||
|
||||
it('buys mystery set if it is available', async () => {
|
||||
clock = sinon.useFakeTimers(new Date('2024-01-16'));
|
||||
user.purchased.plan.consecutive.trinkets = 1;
|
||||
await buyMysterySet(user, { params: { key: '201601' } }, analytics);
|
||||
|
||||
expect(user.purchased.plan.consecutive.trinkets).to.eql(0);
|
||||
expect(user.items.gear.owned).to.have.property('shield_mystery_201601', true);
|
||||
expect(user.items.gear.owned).to.have.property('head_mystery_201601', true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue