mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
Fix purchasing some hatching potions
This commit is contained in:
Submodule habitica-images updated: aa72332019...622c7a574e
@@ -120,6 +120,24 @@ describe('shared.ops.purchase', () => {
|
||||
}
|
||||
});
|
||||
|
||||
it('returns error when quest for hatching potion was not yet completed', async () => {
|
||||
try {
|
||||
await purchase(user, { params: { type: 'hatchingPotions', key: 'BlackPearl' } });
|
||||
} catch (err) {
|
||||
expect(err).to.be.an.instanceof(NotAuthorized);
|
||||
expect(err.message).to.equal(i18n.t('messageNotAvailable'));
|
||||
}
|
||||
});
|
||||
|
||||
it('returns error when quest for egg was not yet completed', async () => {
|
||||
try {
|
||||
await purchase(user, { params: { type: 'eggs', key: 'Octopus' } });
|
||||
} catch (err) {
|
||||
expect(err).to.be.an.instanceof(NotAuthorized);
|
||||
expect(err.message).to.equal(i18n.t('messageNotAvailable'));
|
||||
}
|
||||
});
|
||||
|
||||
it('returns error when bundle is not available', async () => {
|
||||
try {
|
||||
await purchase(user, { params: { type: 'bundles', key: 'forestFriends' } });
|
||||
@@ -215,6 +233,26 @@ describe('shared.ops.purchase', () => {
|
||||
expect(user.items.hatchingPotions[key]).to.eql(1);
|
||||
});
|
||||
|
||||
it('purchases hatching potion if user completed quest', async () => {
|
||||
const type = 'hatchingPotions';
|
||||
const key = 'Bronze';
|
||||
user.achievements.quests.bronze = 1;
|
||||
|
||||
await purchase(user, { params: { type, key } });
|
||||
|
||||
expect(user.items.hatchingPotions[key]).to.eql(1);
|
||||
});
|
||||
|
||||
it('purchases egg if user completed quest', async () => {
|
||||
const type = 'eggs';
|
||||
const key = 'Deer';
|
||||
user.achievements.quests.ghost_stag = 1;
|
||||
|
||||
await purchase(user, { params: { type, key } });
|
||||
|
||||
expect(user.items.eggs[key]).to.eql(1);
|
||||
});
|
||||
|
||||
it('purchases quest bundles', async () => {
|
||||
const startingBalance = user.balance;
|
||||
clock.restore();
|
||||
|
||||
@@ -41,180 +41,103 @@ const drops = {
|
||||
};
|
||||
|
||||
const premium = {
|
||||
RoyalPurple: {
|
||||
value: 2,
|
||||
text: t('hatchingPotionRoyalPurple'),
|
||||
limited: true,
|
||||
},
|
||||
Cupid: {
|
||||
value: 2,
|
||||
text: t('hatchingPotionCupid'),
|
||||
limited: true,
|
||||
},
|
||||
Shimmer: {
|
||||
value: 2,
|
||||
text: t('hatchingPotionShimmer'),
|
||||
limited: true,
|
||||
},
|
||||
Fairy: {
|
||||
value: 2,
|
||||
text: t('hatchingPotionFairy'),
|
||||
limited: true,
|
||||
},
|
||||
Floral: {
|
||||
value: 2,
|
||||
text: t('hatchingPotionFloral'),
|
||||
limited: true,
|
||||
},
|
||||
Aquatic: {
|
||||
value: 2,
|
||||
text: t('hatchingPotionAquatic'),
|
||||
limited: true,
|
||||
},
|
||||
Ember: {
|
||||
value: 2,
|
||||
text: t('hatchingPotionEmber'),
|
||||
limited: true,
|
||||
},
|
||||
Thunderstorm: {
|
||||
value: 2,
|
||||
text: t('hatchingPotionThunderstorm'),
|
||||
limited: true,
|
||||
},
|
||||
Spooky: {
|
||||
value: 2,
|
||||
text: t('hatchingPotionSpooky'),
|
||||
limited: true,
|
||||
},
|
||||
Ghost: {
|
||||
value: 2,
|
||||
text: t('hatchingPotionGhost'),
|
||||
limited: true,
|
||||
},
|
||||
Holly: {
|
||||
value: 2,
|
||||
text: t('hatchingPotionHolly'),
|
||||
limited: true,
|
||||
},
|
||||
Peppermint: {
|
||||
value: 2,
|
||||
text: t('hatchingPotionPeppermint'),
|
||||
limited: true,
|
||||
},
|
||||
StarryNight: {
|
||||
value: 2,
|
||||
text: t('hatchingPotionStarryNight'),
|
||||
limited: true,
|
||||
},
|
||||
Rainbow: {
|
||||
value: 2,
|
||||
text: t('hatchingPotionRainbow'),
|
||||
limited: true,
|
||||
},
|
||||
Glass: {
|
||||
value: 2,
|
||||
text: t('hatchingPotionGlass'),
|
||||
limited: true,
|
||||
},
|
||||
Glow: {
|
||||
value: 2,
|
||||
text: t('hatchingPotionGlow'),
|
||||
limited: true,
|
||||
},
|
||||
Frost: {
|
||||
value: 2,
|
||||
text: t('hatchingPotionFrost'),
|
||||
limited: true,
|
||||
},
|
||||
IcySnow: {
|
||||
value: 2,
|
||||
text: t('hatchingPotionIcySnow'),
|
||||
limited: true,
|
||||
},
|
||||
RoseQuartz: {
|
||||
value: 2,
|
||||
text: t('hatchingPotionRoseQuartz'),
|
||||
limited: true,
|
||||
},
|
||||
Celestial: {
|
||||
value: 2,
|
||||
text: t('hatchingPotionCelestial'),
|
||||
limited: true,
|
||||
},
|
||||
Sunshine: {
|
||||
value: 2,
|
||||
text: t('hatchingPotionSunshine'),
|
||||
limited: true,
|
||||
},
|
||||
RoyalPurple: {},
|
||||
Cupid: {},
|
||||
Shimmer: {},
|
||||
Fairy: {},
|
||||
Floral: {},
|
||||
Aquatic: {},
|
||||
Ember: {},
|
||||
Thunderstorm: {},
|
||||
Spooky: {},
|
||||
Ghost: {},
|
||||
Holly: {},
|
||||
Peppermint: {},
|
||||
StarryNight: {},
|
||||
Rainbow: {},
|
||||
Glass: {},
|
||||
Glow: {},
|
||||
Frost: {},
|
||||
IcySnow: {},
|
||||
RoseQuartz: {},
|
||||
Celestial: {},
|
||||
Sunshine: {},
|
||||
Bronze: {
|
||||
questPotion: true,
|
||||
canBuy: hasQuestAchievementFunction('bronze'),
|
||||
},
|
||||
Watery: {},
|
||||
Silver: {
|
||||
questPotion: true,
|
||||
canBuy: hasQuestAchievementFunction('silver'),
|
||||
},
|
||||
Shadow: {},
|
||||
Amber: {
|
||||
questPotion: true,
|
||||
canBuy: hasQuestAchievementFunction('amber'),
|
||||
},
|
||||
Aurora: {},
|
||||
Ruby: {
|
||||
questPotion: true,
|
||||
canBuy: hasQuestAchievementFunction('ruby'),
|
||||
},
|
||||
BirchBark: {},
|
||||
Fluorite: {
|
||||
questPotion: true,
|
||||
canBuy: hasQuestAchievementFunction('fluorite'),
|
||||
},
|
||||
SandSculpture: {},
|
||||
Windup: {
|
||||
questPotion: true,
|
||||
canBuy: hasQuestAchievementFunction('windup'),
|
||||
},
|
||||
Turquoise: {
|
||||
questPotion: true,
|
||||
canBuy: hasQuestAchievementFunction('turquoise'),
|
||||
},
|
||||
Vampire: {},
|
||||
AutumnLeaf: {},
|
||||
BlackPearl: {
|
||||
questPotion: true,
|
||||
canBuy: hasQuestAchievementFunction('blackPearl'),
|
||||
},
|
||||
StainedGlass: {},
|
||||
PolkaDot: {},
|
||||
MossyStone: {
|
||||
questPotion: true,
|
||||
canBuy: hasQuestAchievementFunction('stone'),
|
||||
},
|
||||
Sunset: {},
|
||||
Moonglow: {},
|
||||
SolarSystem: {
|
||||
questPotion: true,
|
||||
canBuy: hasQuestAchievementFunction('solarSystem'),
|
||||
},
|
||||
Onyx: {
|
||||
questPotion: true,
|
||||
canBuy: hasQuestAchievementFunction('onyx'),
|
||||
},
|
||||
Porcelain: {},
|
||||
PinkMarble: {
|
||||
questPotion: true,
|
||||
canBuy: hasQuestAchievementFunction('pinkMarble'),
|
||||
},
|
||||
Koi: {},
|
||||
};
|
||||
|
||||
const wacky = {
|
||||
Veggie: {
|
||||
text: t('hatchingPotionVeggie'),
|
||||
limited: true,
|
||||
},
|
||||
Veggie: {},
|
||||
Dessert: {
|
||||
questPotion: true,
|
||||
canBuy: hasQuestAchievementFunction('waffle'),
|
||||
},
|
||||
VirtualPet: {
|
||||
questPotion: true,
|
||||
canBuy: hasQuestAchievementFunction('virtualpet'),
|
||||
},
|
||||
TeaShop: {
|
||||
text: t('hatchingPotionTeaShop'),
|
||||
limited: true,
|
||||
},
|
||||
TeaShop: {},
|
||||
Fungi: {
|
||||
text: t('hatchingPotionFungi'),
|
||||
limited: true,
|
||||
questPotion: true,
|
||||
canBuy: hasQuestAchievementFunction('fungi'),
|
||||
},
|
||||
};
|
||||
|
||||
@@ -97,7 +97,7 @@ export default async function purchase (user, req = {}, analytics) {
|
||||
|
||||
const { price, item } = getItemAndPrice(user, type, key, req);
|
||||
|
||||
if (type === 'hatchingPotions' && item.premium === true) {
|
||||
if (type === 'hatchingPotions' && item.premium === true && item.questPotion !== true) {
|
||||
const matchers = getScheduleMatchingGroup('premiumHatchingPotions');
|
||||
if (!matchers.match(item.key)) {
|
||||
throw new NotAuthorized(i18n.t('messageNotAvailable', req.language));
|
||||
|
||||
Reference in New Issue
Block a user