diff --git a/test/content/hatching-potions.test.js b/test/content/hatching-potions.test.js index 5d1d37bf65..a4e31d7b91 100644 --- a/test/content/hatching-potions.test.js +++ b/test/content/hatching-potions.test.js @@ -5,50 +5,28 @@ import { expectValidTranslationString, } from '../helpers/content.helper'; -import hatchingPotions from '../../website/common/script/content/hatching-potions'; +import * as hatchingPotions from '../../website/common/script/content/hatching-potions'; describe('hatchingPotions', () => { - let clock; + describe('all', () => { + it('is a combination of drop, premium, and wacky potions', () => { + const dropNumber = Object.keys(hatchingPotions.drops).length; + const premiumNumber = Object.keys(hatchingPotions.premium).length; + const wackyNumber = Object.keys(hatchingPotions.wacky).length; + const allNumber = Object.keys(hatchingPotions.all).length; - afterEach(() => { - if (clock) { - clock.restore(); - } - }); + expect(allNumber).to.be.greaterThan(0); + expect(allNumber).to.equal(dropNumber + premiumNumber + wackyNumber); + }); - const potionTypes = [ - 'drops', - 'quests', - 'premium', - 'wacky', - ]; - potionTypes.forEach(potionType => { - describe(potionType, () => { - it('contains basic information about each potion', () => { - each(hatchingPotions.all, (potion, key) => { - expectValidTranslationString(potion.text); - expectValidTranslationString(potion.notes); - expect(potion.canBuy).to.be.a('function'); - expect(potion.value).to.be.a('number'); - expect(potion.key).to.equal(key); - }); + it('contains basic information about each potion', () => { + each(hatchingPotions.all, (potion, key) => { + expectValidTranslationString(potion.text); + expectValidTranslationString(potion.notes); + expect(potion.canBuy).to.be.a('function'); + expect(potion.value).to.be.a('number'); + expect(potion.key).to.equal(key); }); }); }); - - it('does not contain unreleased potions', () => { - clock = sinon.useFakeTimers(new Date('2024-05-20')); - const premiumPotions = hatchingPotions.premium; - expect(premiumPotions.Koi).to.not.exist; - }); - - it('Releases potions when appropriate without needing restarting', () => { - clock = sinon.useFakeTimers(new Date('2024-05-20')); - const mayPotions = hatchingPotions.premium; - clock.restore(); - clock = sinon.useFakeTimers(new Date('2024-06-20')); - const junePotions = hatchingPotions.premium; - expect(junePotions.Koi).to.exist; - expect(Object.keys(mayPotions).length).to.equal(Object.keys(junePotions).length - 1); - }); }); diff --git a/test/content/schedule.test.js b/test/content/schedule.test.js index 139fbe8bf2..270fc7d582 100644 --- a/test/content/schedule.test.js +++ b/test/content/schedule.test.js @@ -7,7 +7,7 @@ import { import QUEST_PETS from '../../website/common/script/content/quests/pets'; import QUEST_HATCHINGPOTIONS from '../../website/common/script/content/quests/potions'; import QUEST_BUNDLES from '../../website/common/script/content/bundles'; -import potions from '../../website/common/script/content/hatching-potions'; +import { premium } from '../../website/common/script/content/hatching-potions'; import SPELLS from '../../website/common/script/content/spells'; import QUEST_SEASONAL from '../../website/common/script/content/quests/seasonal'; @@ -167,10 +167,10 @@ describe('Content Schedule', () => { }); it('premium hatching potions', () => { - const potionKeys = Object.keys(potions.premium); + const potionKeys = Object.keys(premium); Object.keys(MONTHLY_SCHEDULE).forEach(key => { - const monthlyPotions = MONTHLY_SCHEDULE[key][21].find(item => item.type === 'premiumHatchingPotions'); - for (const potion of monthlyPotions.items) { + const potions = MONTHLY_SCHEDULE[key][21].find(item => item.type === 'premiumHatchingPotions'); + for (const potion of potions.items) { expect(potion).to.be.a('string'); expect(potionKeys).to.include(potion); } diff --git a/test/content/stable.test.js b/test/content/stable.test.js index 3266cb7f47..ca1475d631 100644 --- a/test/content/stable.test.js +++ b/test/content/stable.test.js @@ -7,11 +7,20 @@ import { import t from '../../website/common/script/content/translation'; import * as stable from '../../website/common/script/content/stable'; -import * as eggs from '../../website/common/script/content/eggs'; +import eggs from '../../website/common/script/content/eggs'; import * as potions from '../../website/common/script/content/hatching-potions'; describe('stable', () => { describe('dropPets', () => { + let clock; + beforeEach(() => { + clock = sinon.useFakeTimers(new Date('2020-05-20')); + }); + + afterEach(() => { + clock.restore(); + }); + it('contains a pet for each drop potion * each drop egg', () => { const numberOfDropPotions = Object.keys(potions.drops).length; const numberOfDropEggs = Object.keys(eggs.drops).length; diff --git a/website/common/script/content/constants/release_dates.js b/website/common/script/content/constants/release_dates.js new file mode 100644 index 0000000000..e7edd2b9c8 --- /dev/null +++ b/website/common/script/content/constants/release_dates.js @@ -0,0 +1,15 @@ +export const ARMOIRE_RELEASE_DATES = { + somethingSpooky: { year: 2023, month: 10 }, + cookingImplementsTwo: { year: 2023, month: 11 }, + greenTrapper: { year: 2023, month: 12 }, + schoolUniform: { year: 2024, month: 1 }, + whiteLoungeWear: { year: 2024, month: 2 }, + hatterSet: { year: 2024, month: 3 }, + optimistSet: { year: 2024, month: 4 }, + pottersSet: { year: 2024, month: 5 }, + beachsideSet: { year: 2024, month: 6 }, +}; + +export const EGGS_RELEASE_DATES = { + Giraffe: { year: 2024, month: 6, day: 1 }, +}; diff --git a/website/common/script/content/eggs.js b/website/common/script/content/eggs.js index 0a6e438e5b..65e346dd85 100644 --- a/website/common/script/content/eggs.js +++ b/website/common/script/content/eggs.js @@ -1,7 +1,9 @@ -import assign from 'lodash/assign'; import defaults from 'lodash/defaults'; import each from 'lodash/each'; import t from './translation'; +import { filterReleased } from './is_released'; +import { EGGS_RELEASE_DATES } from './constants/release_dates'; +import datedMemoize from '../fns/datedMemoize'; function applyEggDefaults (set, config) { each(set, (egg, key) => { @@ -410,10 +412,17 @@ applyEggDefaults(quests, { }, }); -const all = assign({}, drops, quests); +function filterEggs (eggs) { + return filterReleased(eggs, 'key', EGGS_RELEASE_DATES); +} -export { - drops, - quests, - all, +const memoizedFilter = datedMemoize(filterEggs); + +export default { + get drops () { + return memoizedFilter({ memoizeConfig: true, identifier: 'drops' }, drops); + }, + get quests () { + return memoizedFilter({ memoizeConfig: true, identifier: 'quests' }, quests); + }, }; diff --git a/website/common/script/content/hatching-potions.js b/website/common/script/content/hatching-potions.js index c293b1b99c..0dcfe0c83e 100644 --- a/website/common/script/content/hatching-potions.js +++ b/website/common/script/content/hatching-potions.js @@ -1,10 +1,7 @@ +import assign from 'lodash/assign'; import defaults from 'lodash/defaults'; import each from 'lodash/each'; -import { assign } from 'lodash'; import t from './translation'; -import datedMemoize from '../fns/datedMemoize'; -import { filterReleased } from './is_released'; -import { HATCHING_POTIONS_RELEASE_DATES } from './constants/releaseDates'; function hasQuestAchievementFunction (key) { return user => user.achievements.quests && user.achievements.quests[key] > 0; @@ -196,23 +193,8 @@ each(wacky, (pot, key) => { }); }); -function filterEggs (eggs) { - return filterReleased(eggs, 'key', HATCHING_POTIONS_RELEASE_DATES); -} +const all = assign({}, drops, premium, wacky); -const memoizedFilter = datedMemoize(filterEggs); - -export default { - get drops () { - return memoizedFilter({ memoizeConfig: true, identifier: 'drops' }, drops); - }, - get premium () { - return memoizedFilter({ memoizeConfig: true, identifier: 'premium' }, premium); - }, - get wacky () { - return memoizedFilter({ memoizeConfig: true, identifier: 'wacky' }, wacky); - }, - get all () { - return assign({}, this.drops, this.premium, this.wacky); - }, +export { + drops, premium, wacky, all, }; diff --git a/website/common/script/content/index.js b/website/common/script/content/index.js index 0de5f5d5f0..f6ba549919 100644 --- a/website/common/script/content/index.js +++ b/website/common/script/content/index.js @@ -1,5 +1,6 @@ import defaults from 'lodash/defaults'; import each from 'lodash/each'; +import assign from 'lodash/assign'; import moment from 'moment'; import t from './translation'; import { tasksByCategory } from './tasks'; @@ -18,7 +19,7 @@ import { import achievements from './achievements'; -import * as eggs from './eggs'; +import eggs from './eggs'; import * as hatchingPotions from './hatching-potions'; import * as stable from './stable'; import gear from './gear'; @@ -167,7 +168,7 @@ api.special = api.spells.special; api.dropEggs = eggs.drops; api.questEggs = eggs.quests; -api.eggs = eggs.all; +api.eggs = assign({}, eggs.drops, eggs.quests); api.timeTravelStable = { pets: { diff --git a/website/common/script/content/stable.js b/website/common/script/content/stable.js index e6015f6e77..93d72d482f 100644 --- a/website/common/script/content/stable.js +++ b/website/common/script/content/stable.js @@ -1,10 +1,7 @@ import each from 'lodash/each'; import moment from 'moment'; import { EVENTS } from './constants/events'; -import { - drops as dropEggs, - quests as questEggs, -} from './eggs'; +import allEggs from './eggs'; import { drops as dropPotions, premium as premiumPotions, @@ -12,10 +9,14 @@ import { } from './hatching-potions'; import t from './translation'; +const STABLE_RELEASE_DATES = { + +}; + const petInfo = {}; const mountInfo = {}; -function constructSet (type, eggs, potions) { +function constructSet (type, eggs, potions, hasMounts = true) { const pets = {}; const mounts = {}; @@ -37,52 +38,24 @@ function constructSet (type, eggs, potions) { potion: potion.text, egg: egg.text, })); - mountInfo[key] = getAnimalData(t('mountName', { - potion: potion.text, - mount: egg.mountText, - })); - pets[key] = true; - mounts[key] = true; - }); - }); - return [pets, mounts]; -} - -function constructPetOnlySet (type, eggs, potions) { - const pets = {}; - - each(eggs, egg => { - each(potions, potion => { - const key = `${egg.key}-${potion.key}`; - - function getAnimalData (text) { - return { - key, - type, - potion: potion.key, - egg: egg.key, - text, - }; + if (hasMounts) { + mountInfo[key] = getAnimalData(t('mountName', { + potion: potion.text, + mount: egg.mountText, + })); + mounts[key] = true; } - - petInfo[key] = getAnimalData(t('petName', { - potion: potion.text, - egg: egg.text, - })); - pets[key] = true; }); }); + if (hasMounts) { + return [pets, mounts]; + } return pets; } -const [dropPets, dropMounts] = constructSet('drop', dropEggs, dropPotions); -const [premiumPets, premiumMounts] = constructSet('premium', dropEggs, premiumPotions); -const [questPets, questMounts] = constructSet('quest', questEggs, dropPotions); -const wackyPets = constructPetOnlySet('wacky', dropEggs, wackyPotions); - const canFindSpecial = { pets: { // Veteran Pet Ladder - awarded on major updates @@ -158,6 +131,11 @@ const canFindSpecial = { }, }; +const [dropPets, dropMounts] = constructSet('drop', allEggs.drops, dropPotions); +const [premiumPets, premiumMounts] = constructSet('premium', allEggs.drops, premiumPotions); +const [questPets, questMounts] = constructSet('quest', allEggs.quests, dropPotions); +const wackyPets = constructSet('wacky', allEggs.drops, wackyPotions, false); + const specialPets = { 'Wolf-Veteran': 'veteranWolf', 'Wolf-Cerberus': 'cerberusPup', diff --git a/website/common/script/fns/firstDrops.js b/website/common/script/fns/firstDrops.js index cfcd5c933a..7a2413cb97 100644 --- a/website/common/script/fns/firstDrops.js +++ b/website/common/script/fns/firstDrops.js @@ -1,9 +1,9 @@ -import { drops as eggs } from '../content/eggs'; +import allEggs from '../content/eggs'; import { drops as hatchingPotions } from '../content/hatching-potions'; import randomVal from '../libs/randomVal'; export default function firstDrops (user) { - const eggDrop = randomVal(eggs); + const eggDrop = randomVal(allEggs.drops); const potionDrop = randomVal(hatchingPotions); user.items.eggs = {