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 () => {
|
it('returns error when bundle is not available', async () => {
|
||||||
try {
|
try {
|
||||||
await purchase(user, { params: { type: 'bundles', key: 'forestFriends' } });
|
await purchase(user, { params: { type: 'bundles', key: 'forestFriends' } });
|
||||||
@@ -215,6 +233,26 @@ describe('shared.ops.purchase', () => {
|
|||||||
expect(user.items.hatchingPotions[key]).to.eql(1);
|
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 () => {
|
it('purchases quest bundles', async () => {
|
||||||
const startingBalance = user.balance;
|
const startingBalance = user.balance;
|
||||||
clock.restore();
|
clock.restore();
|
||||||
|
|||||||
@@ -41,180 +41,103 @@ const drops = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const premium = {
|
const premium = {
|
||||||
RoyalPurple: {
|
RoyalPurple: {},
|
||||||
value: 2,
|
Cupid: {},
|
||||||
text: t('hatchingPotionRoyalPurple'),
|
Shimmer: {},
|
||||||
limited: true,
|
Fairy: {},
|
||||||
},
|
Floral: {},
|
||||||
Cupid: {
|
Aquatic: {},
|
||||||
value: 2,
|
Ember: {},
|
||||||
text: t('hatchingPotionCupid'),
|
Thunderstorm: {},
|
||||||
limited: true,
|
Spooky: {},
|
||||||
},
|
Ghost: {},
|
||||||
Shimmer: {
|
Holly: {},
|
||||||
value: 2,
|
Peppermint: {},
|
||||||
text: t('hatchingPotionShimmer'),
|
StarryNight: {},
|
||||||
limited: true,
|
Rainbow: {},
|
||||||
},
|
Glass: {},
|
||||||
Fairy: {
|
Glow: {},
|
||||||
value: 2,
|
Frost: {},
|
||||||
text: t('hatchingPotionFairy'),
|
IcySnow: {},
|
||||||
limited: true,
|
RoseQuartz: {},
|
||||||
},
|
Celestial: {},
|
||||||
Floral: {
|
Sunshine: {},
|
||||||
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,
|
|
||||||
},
|
|
||||||
Bronze: {
|
Bronze: {
|
||||||
|
questPotion: true,
|
||||||
canBuy: hasQuestAchievementFunction('bronze'),
|
canBuy: hasQuestAchievementFunction('bronze'),
|
||||||
},
|
},
|
||||||
Watery: {},
|
Watery: {},
|
||||||
Silver: {
|
Silver: {
|
||||||
|
questPotion: true,
|
||||||
canBuy: hasQuestAchievementFunction('silver'),
|
canBuy: hasQuestAchievementFunction('silver'),
|
||||||
},
|
},
|
||||||
Shadow: {},
|
Shadow: {},
|
||||||
Amber: {
|
Amber: {
|
||||||
|
questPotion: true,
|
||||||
canBuy: hasQuestAchievementFunction('amber'),
|
canBuy: hasQuestAchievementFunction('amber'),
|
||||||
},
|
},
|
||||||
Aurora: {},
|
Aurora: {},
|
||||||
Ruby: {
|
Ruby: {
|
||||||
|
questPotion: true,
|
||||||
canBuy: hasQuestAchievementFunction('ruby'),
|
canBuy: hasQuestAchievementFunction('ruby'),
|
||||||
},
|
},
|
||||||
BirchBark: {},
|
BirchBark: {},
|
||||||
Fluorite: {
|
Fluorite: {
|
||||||
|
questPotion: true,
|
||||||
canBuy: hasQuestAchievementFunction('fluorite'),
|
canBuy: hasQuestAchievementFunction('fluorite'),
|
||||||
},
|
},
|
||||||
SandSculpture: {},
|
SandSculpture: {},
|
||||||
Windup: {
|
Windup: {
|
||||||
|
questPotion: true,
|
||||||
canBuy: hasQuestAchievementFunction('windup'),
|
canBuy: hasQuestAchievementFunction('windup'),
|
||||||
},
|
},
|
||||||
Turquoise: {
|
Turquoise: {
|
||||||
|
questPotion: true,
|
||||||
canBuy: hasQuestAchievementFunction('turquoise'),
|
canBuy: hasQuestAchievementFunction('turquoise'),
|
||||||
},
|
},
|
||||||
Vampire: {},
|
Vampire: {},
|
||||||
AutumnLeaf: {},
|
AutumnLeaf: {},
|
||||||
BlackPearl: {
|
BlackPearl: {
|
||||||
|
questPotion: true,
|
||||||
canBuy: hasQuestAchievementFunction('blackPearl'),
|
canBuy: hasQuestAchievementFunction('blackPearl'),
|
||||||
},
|
},
|
||||||
StainedGlass: {},
|
StainedGlass: {},
|
||||||
PolkaDot: {},
|
PolkaDot: {},
|
||||||
MossyStone: {
|
MossyStone: {
|
||||||
|
questPotion: true,
|
||||||
canBuy: hasQuestAchievementFunction('stone'),
|
canBuy: hasQuestAchievementFunction('stone'),
|
||||||
},
|
},
|
||||||
Sunset: {},
|
Sunset: {},
|
||||||
Moonglow: {},
|
Moonglow: {},
|
||||||
SolarSystem: {
|
SolarSystem: {
|
||||||
|
questPotion: true,
|
||||||
canBuy: hasQuestAchievementFunction('solarSystem'),
|
canBuy: hasQuestAchievementFunction('solarSystem'),
|
||||||
},
|
},
|
||||||
Onyx: {
|
Onyx: {
|
||||||
|
questPotion: true,
|
||||||
canBuy: hasQuestAchievementFunction('onyx'),
|
canBuy: hasQuestAchievementFunction('onyx'),
|
||||||
},
|
},
|
||||||
Porcelain: {},
|
Porcelain: {},
|
||||||
PinkMarble: {
|
PinkMarble: {
|
||||||
|
questPotion: true,
|
||||||
canBuy: hasQuestAchievementFunction('pinkMarble'),
|
canBuy: hasQuestAchievementFunction('pinkMarble'),
|
||||||
},
|
},
|
||||||
Koi: {},
|
Koi: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
const wacky = {
|
const wacky = {
|
||||||
Veggie: {
|
Veggie: {},
|
||||||
text: t('hatchingPotionVeggie'),
|
|
||||||
limited: true,
|
|
||||||
},
|
|
||||||
Dessert: {
|
Dessert: {
|
||||||
|
questPotion: true,
|
||||||
canBuy: hasQuestAchievementFunction('waffle'),
|
canBuy: hasQuestAchievementFunction('waffle'),
|
||||||
},
|
},
|
||||||
VirtualPet: {
|
VirtualPet: {
|
||||||
|
questPotion: true,
|
||||||
canBuy: hasQuestAchievementFunction('virtualpet'),
|
canBuy: hasQuestAchievementFunction('virtualpet'),
|
||||||
},
|
},
|
||||||
TeaShop: {
|
TeaShop: {},
|
||||||
text: t('hatchingPotionTeaShop'),
|
|
||||||
limited: true,
|
|
||||||
},
|
|
||||||
Fungi: {
|
Fungi: {
|
||||||
text: t('hatchingPotionFungi'),
|
questPotion: true,
|
||||||
limited: true,
|
|
||||||
canBuy: hasQuestAchievementFunction('fungi'),
|
canBuy: hasQuestAchievementFunction('fungi'),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ export default async function purchase (user, req = {}, analytics) {
|
|||||||
|
|
||||||
const { price, item } = getItemAndPrice(user, type, key, req);
|
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');
|
const matchers = getScheduleMatchingGroup('premiumHatchingPotions');
|
||||||
if (!matchers.match(item.key)) {
|
if (!matchers.match(item.key)) {
|
||||||
throw new NotAuthorized(i18n.t('messageNotAvailable', req.language));
|
throw new NotAuthorized(i18n.t('messageNotAvailable', req.language));
|
||||||
|
|||||||
Reference in New Issue
Block a user