mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +01:00
fix(test): make sure error is catched using done() callback
This commit is contained in:
@@ -15,7 +15,7 @@ describe('shared.ops.allocate', () => {
|
||||
user = generateUser();
|
||||
});
|
||||
|
||||
it('throws an error if an invalid attribute is supplied', () => {
|
||||
it('throws an error if an invalid attribute is supplied', (done) => {
|
||||
try {
|
||||
allocate(user, {
|
||||
query: {stat: 'notValid'},
|
||||
@@ -23,15 +23,17 @@ describe('shared.ops.allocate', () => {
|
||||
} catch (err) {
|
||||
expect(err).to.be.an.instanceof(BadRequest);
|
||||
expect(err.message).to.equal(i18n.t('invalidAttribute', {attr: 'notValid'}));
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
it('throws an error if the user doesn\'t have attribute points', () => {
|
||||
it('throws an error if the user doesn\'t have attribute points', (done) => {
|
||||
try {
|
||||
allocate(user);
|
||||
} catch (err) {
|
||||
expect(err).to.be.an.instanceof(NotAuthorized);
|
||||
expect(err.message).to.equal(i18n.t('notEnoughAttrPoints'));
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ describe('shared.ops.buy', () => {
|
||||
expect(user.stats.gp).to.eql(175);
|
||||
});
|
||||
|
||||
it('does not purchase if not enough gp', () => {
|
||||
it('does not purchase if not enough gp', (done) => {
|
||||
user.stats.hp = 45;
|
||||
user.stats.gp = 5;
|
||||
try {
|
||||
@@ -68,10 +68,12 @@ describe('shared.ops.buy', () => {
|
||||
} catch (err) {
|
||||
expect(err).to.be.an.instanceof(NotAuthorized);
|
||||
expect(err.message).to.equal(i18n.t('messageNotEnoughGold'));
|
||||
}
|
||||
|
||||
expect(user.stats.hp).to.eql(45);
|
||||
expect(user.stats.gp).to.eql(5);
|
||||
|
||||
done();
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
@@ -140,7 +142,7 @@ describe('shared.ops.buy', () => {
|
||||
expect(user.items.gear.equipped).to.have.property('weapon', 'weapon_warrior_1');
|
||||
});
|
||||
|
||||
it('does not buy equipment without enough Gold', () => {
|
||||
it('does not buy equipment without enough Gold', (done) => {
|
||||
user.stats.gp = 20;
|
||||
|
||||
try {
|
||||
@@ -148,9 +150,9 @@ describe('shared.ops.buy', () => {
|
||||
} catch (err) {
|
||||
expect(err).to.be.an.instanceof(NotAuthorized);
|
||||
expect(err.message).to.equal(i18n.t('messageNotEnoughGold'));
|
||||
}
|
||||
|
||||
expect(user.items.gear.owned).to.not.have.property('armor_warrior_1');
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -177,7 +179,7 @@ describe('shared.ops.buy', () => {
|
||||
});
|
||||
|
||||
context('failure conditions', () => {
|
||||
it('does not open if user does not have enough gold', () => {
|
||||
it('does not open if user does not have enough gold', (done) => {
|
||||
shared.fns.predictableRandom.returns(YIELD_EQUIPMENT);
|
||||
user.stats.gp = 50;
|
||||
|
||||
@@ -189,10 +191,11 @@ describe('shared.ops.buy', () => {
|
||||
expect(user.items.gear.owned).to.eql({weapon_warrior_0: true});
|
||||
expect(user.items.food).to.be.empty;
|
||||
expect(user.stats.exp).to.eql(0);
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
it('does not open without Ultimate Gear achievement', () => {
|
||||
it('does not open without Ultimate Gear achievement', (done) => {
|
||||
shared.fns.predictableRandom.returns(YIELD_EQUIPMENT);
|
||||
user.achievements.ultimateGearSets = {healer: false, wizard: false, rogue: false, warrior: false};
|
||||
|
||||
@@ -204,6 +207,7 @@ describe('shared.ops.buy', () => {
|
||||
expect(user.items.gear.owned).to.eql({weapon_warrior_0: true});
|
||||
expect(user.items.food).to.be.empty;
|
||||
expect(user.stats.exp).to.eql(0);
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -27,17 +27,18 @@ describe('shared.ops.buyMysterySet', () => {
|
||||
|
||||
context('Mystery Sets', () => {
|
||||
context('failure conditions', () => {
|
||||
it('does not grant mystery sets without Mystic Hourglasses', () => {
|
||||
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', () => {
|
||||
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,
|
||||
@@ -53,6 +54,7 @@ describe('shared.ops.buyMysterySet', () => {
|
||||
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();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -28,7 +28,7 @@ describe('shared.ops.buyQuest', () => {
|
||||
expect(user.stats.gp).to.equal(5);
|
||||
});
|
||||
|
||||
it('does not buy Quests without enough Gold', () => {
|
||||
it('does not buy Quests without enough Gold', (done) => {
|
||||
user.stats.gp = 1;
|
||||
try {
|
||||
buyQuest(user, {
|
||||
@@ -41,10 +41,11 @@ describe('shared.ops.buyQuest', () => {
|
||||
expect(err.message).to.equal(i18n.t('messageNotEnoughGold'));
|
||||
expect(user.items.quests).to.eql({});
|
||||
expect(user.stats.gp).to.equal(1);
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
it('does not buy nonexistent Quests', () => {
|
||||
it('does not buy nonexistent Quests', (done) => {
|
||||
user.stats.gp = 9999;
|
||||
try {
|
||||
buyQuest(user, {
|
||||
@@ -57,10 +58,11 @@ describe('shared.ops.buyQuest', () => {
|
||||
expect(err.message).to.equal(i18n.t('questNotFound', {key: 'snarfblatter'}));
|
||||
expect(user.items.quests).to.eql({});
|
||||
expect(user.stats.gp).to.equal(9999);
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
it('does not buy Gem-premium Quests', () => {
|
||||
it('does not buy Gem-premium Quests', (done) => {
|
||||
user.stats.gp = 9999;
|
||||
try {
|
||||
buyQuest(user, {
|
||||
@@ -73,6 +75,7 @@ describe('shared.ops.buyQuest', () => {
|
||||
expect(err.message).to.equal(i18n.t('questNotGoldPurchasable', {key: 'kraken'}));
|
||||
expect(user.items.quests).to.eql({});
|
||||
expect(user.stats.gp).to.equal(9999);
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -17,16 +17,17 @@ describe('shared.ops.buySpecialSpell', () => {
|
||||
user = generateUser();
|
||||
});
|
||||
|
||||
it('throws an error if params.key is missing', () => {
|
||||
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', () => {
|
||||
it('throws an error if the spell doesn\'t exists', (done) => {
|
||||
try {
|
||||
buySpecialSpell(user, {
|
||||
params: {
|
||||
@@ -36,10 +37,11 @@ describe('shared.ops.buySpecialSpell', () => {
|
||||
} 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', () => {
|
||||
it('throws an error if the user doesn\'t have enough gold', (done) => {
|
||||
user.stats.gp = 1;
|
||||
try {
|
||||
buySpecialSpell(user, {
|
||||
@@ -50,6 +52,7 @@ describe('shared.ops.buySpecialSpell', () => {
|
||||
} catch (err) {
|
||||
expect(err).to.be.an.instanceof(NotAuthorized);
|
||||
expect(err.message).to.equal(i18n.t('messageNotEnoughGold'));
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -76,13 +76,14 @@ describe('shared.ops.changeClass', () => {
|
||||
});
|
||||
|
||||
context('has user.preferences.disableClasses !== true', () => {
|
||||
it('and less than 3 gems', () => {
|
||||
it('and less than 3 gems', (done) => {
|
||||
user.balance = 0.5;
|
||||
try {
|
||||
changeClass(user);
|
||||
} catch (err) {
|
||||
expect(err).to.be.an.instanceof(NotAuthorized);
|
||||
expect(err.message).to.equal(i18n.t('notEnoughGems'));
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -18,53 +18,58 @@ describe('shared.ops.feed', () => {
|
||||
});
|
||||
|
||||
context('failure conditions', () => {
|
||||
it('does not allow feeding without specifying pet and food', () => {
|
||||
it('does not allow feeding without specifying pet and food', (done) => {
|
||||
try {
|
||||
feed(user);
|
||||
} catch (err) {
|
||||
expect(err).to.be.an.instanceof(BadRequest);
|
||||
expect(err.message).to.equal(i18n.t('missingPetFoodFeed'));
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
it('does not allow feeding if pet name format is invalid', () => {
|
||||
it('does not allow feeding if pet name format is invalid', (done) => {
|
||||
try {
|
||||
feed(user, {params: {pet: 'invalid', food: 'food'}});
|
||||
} catch (err) {
|
||||
expect(err).to.be.an.instanceof(BadRequest);
|
||||
expect(err.message).to.equal(i18n.t('invalidPetName'));
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
it('does not allow feeding if food does not exists', () => {
|
||||
it('does not allow feeding if food does not exists', (done) => {
|
||||
try {
|
||||
feed(user, {params: {pet: 'valid-pet', food: 'invalid food name'}});
|
||||
} catch (err) {
|
||||
expect(err).to.be.an.instanceof(NotFound);
|
||||
expect(err.message).to.equal(i18n.t('messageFoodNotFound'));
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
it('does not allow feeding if pet is not owned', () => {
|
||||
it('does not allow feeding if pet is not owned', (done) => {
|
||||
try {
|
||||
feed(user, {params: {pet: 'not-owned', food: 'Meat'}});
|
||||
} catch (err) {
|
||||
expect(err).to.be.an.instanceof(NotFound);
|
||||
expect(err.message).to.equal(i18n.t('messagePetNotFound'));
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
it('does not allow feeding if food is not owned', () => {
|
||||
it('does not allow feeding if food is not owned', (done) => {
|
||||
user.items.pets['Wolf-Base'] = 5;
|
||||
try {
|
||||
feed(user, {params: {pet: 'Wolf-Base', food: 'Meat'}});
|
||||
} catch (err) {
|
||||
expect(err).to.be.an.instanceof(NotFound);
|
||||
expect(err.message).to.equal(i18n.t('messageFoodNotFound'));
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
it('does not allow feeding of special pets', () => {
|
||||
it('does not allow feeding of special pets', (done) => {
|
||||
user.items.pets['Wolf-Veteran'] = 5;
|
||||
user.items.food.Meat = 1;
|
||||
try {
|
||||
@@ -72,10 +77,11 @@ describe('shared.ops.feed', () => {
|
||||
} catch (err) {
|
||||
expect(err).to.be.an.instanceof(NotAuthorized);
|
||||
expect(err.message).to.equal(i18n.t('messageCannotFeedPet'));
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
it('does not allow feeding of mounts', () => {
|
||||
it('does not allow feeding of mounts', (done) => {
|
||||
user.items.pets['Wolf-Base'] = -1;
|
||||
user.items.mounts['Wolf-Base'] = true;
|
||||
user.items.food.Meat = 1;
|
||||
@@ -84,6 +90,7 @@ describe('shared.ops.feed', () => {
|
||||
} catch (err) {
|
||||
expect(err).to.be.an.instanceof(NotAuthorized);
|
||||
expect(err.message).to.equal(i18n.t('messageAlreadyMount'));
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -29,7 +29,7 @@ describe('shared.ops.hatch', () => {
|
||||
}
|
||||
});
|
||||
|
||||
it('does not allow hatching if user lacks specified egg', () => {
|
||||
it('does not allow hatching if user lacks specified egg', (done) => {
|
||||
user.items.eggs.Wolf = 1;
|
||||
user.items.hatchingPotions.Base = 1;
|
||||
user.items.pets = {};
|
||||
@@ -41,10 +41,11 @@ describe('shared.ops.hatch', () => {
|
||||
expect(user.items.pets).to.be.empty;
|
||||
expect(user.items.eggs.Wolf).to.equal(1);
|
||||
expect(user.items.hatchingPotions.Base).to.equal(1);
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
it('does not allow hatching if user lacks specified hatching potion', () => {
|
||||
it('does not allow hatching if user lacks specified hatching potion', (done) => {
|
||||
user.items.eggs.Wolf = 1;
|
||||
user.items.hatchingPotions.Base = 1;
|
||||
user.items.pets = {};
|
||||
@@ -56,10 +57,11 @@ describe('shared.ops.hatch', () => {
|
||||
expect(user.items.pets).to.be.empty;
|
||||
expect(user.items.eggs.Wolf).to.equal(1);
|
||||
expect(user.items.hatchingPotions.Base).to.equal(1);
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
it('does not allow hatching if user already owns target pet', () => {
|
||||
it('does not allow hatching if user already owns target pet', (done) => {
|
||||
user.items.eggs = {Wolf: 1};
|
||||
user.items.hatchingPotions = {Base: 1};
|
||||
user.items.pets = {'Wolf-Base': 10};
|
||||
@@ -71,10 +73,11 @@ describe('shared.ops.hatch', () => {
|
||||
expect(user.items.pets).to.eql({'Wolf-Base': 10});
|
||||
expect(user.items.eggs).to.eql({Wolf: 1});
|
||||
expect(user.items.hatchingPotions).to.eql({Base: 1});
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
it('does not allow hatching quest pet egg using premium potion', () => {
|
||||
it('does not allow hatching quest pet egg using premium potion', (done) => {
|
||||
user.items.eggs = {Cheetah: 1};
|
||||
user.items.hatchingPotions = {Spooky: 1};
|
||||
user.items.pets = {};
|
||||
@@ -86,6 +89,7 @@ describe('shared.ops.hatch', () => {
|
||||
expect(user.items.pets).to.be.empty;
|
||||
expect(user.items.eggs).to.eql({Cheetah: 1});
|
||||
expect(user.items.hatchingPotions).to.eql({Spooky: 1});
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user