diff --git a/habitica-images b/habitica-images index aa72332019..622c7a574e 160000 --- a/habitica-images +++ b/habitica-images @@ -1 +1 @@ -Subproject commit aa723320199d7f03ce749d431b46e8d7f95cc8de +Subproject commit 622c7a574e03d9a281a0941086b2ed78a924963e diff --git a/test/common/ops/buy/purchase.test.js b/test/common/ops/buy/purchase.test.js index f540146cda..8bf4398c2a 100644 --- a/test/common/ops/buy/purchase.test.js +++ b/test/common/ops/buy/purchase.test.js @@ -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(); diff --git a/website/common/script/content/hatching-potions.js b/website/common/script/content/hatching-potions.js index 5f7ba1379d..0dcfe0c83e 100644 --- a/website/common/script/content/hatching-potions.js +++ b/website/common/script/content/hatching-potions.js @@ -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'), }, }; diff --git a/website/common/script/ops/buy/purchase.js b/website/common/script/ops/buy/purchase.js index 15edeb20a1..ef147d5101 100644 --- a/website/common/script/ops/buy/purchase.js +++ b/website/common/script/ops/buy/purchase.js @@ -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));