diff --git a/test/common/libs/cleanupPinnedItems.test.js b/test/common/libs/cleanupPinnedItems.test.js index 552ced19f3..1c1cb2ee43 100644 --- a/test/common/libs/cleanupPinnedItems.test.js +++ b/test/common/libs/cleanupPinnedItems.test.js @@ -3,7 +3,7 @@ import { } from '../../helpers/common.helper'; import cleanupPinnedItems from '../../../website/common/script/libs/cleanupPinnedItems'; -describe.only('cleanupPinnedItems', () => { +describe('cleanupPinnedItems', () => { let user; let testPinnedItems; let clock; diff --git a/test/content/shop-featuredItems.test.js b/test/content/shop-featuredItems.test.js new file mode 100644 index 0000000000..88cc0d1e6c --- /dev/null +++ b/test/content/shop-featuredItems.test.js @@ -0,0 +1,52 @@ +import Sinon from 'sinon'; +import featuredItems from '../../website/common/script/content/shop-featuredItems'; + +describe('Shop Featured Items', () => { + let clock; + + afterEach(() => { + if (clock !== undefined) { + clock.restore(); + clock = undefined; + } + }); + + describe('Market', () => { + it('contains armoire', () => { + const items = featuredItems.market(); + expect(_.find(items, item => item.path === 'armoire')).to.exist; + }); + + it('contains the current premium hatching potions', () => { + clock = Sinon.useFakeTimers(new Date('2024-04-08')); + const items = featuredItems.market(); + expect(_.find(items, item => item.path === 'premiumHatchingPotions.Porcelain')).to.exist; + }); + + it('is featuring 4 items', () => { + clock = Sinon.useFakeTimers(new Date('2024-02-08')); + const items = featuredItems.market(); + expect(items.length).to.eql(4); + }); + }); + + describe('Quest Shop', () => { + it('contains bundle', () => { + clock = Sinon.useFakeTimers(new Date('2024-04-08')); + const items = featuredItems.quests(); + expect(_.find(items, item => item.path === 'bundles.birdBuddies')).to.exist; + }); + + it('contains pet quests', () => { + clock = Sinon.useFakeTimers(new Date('2024-04-08')); + const items = featuredItems.quests(); + expect(_.find(items, item => item.path === 'quests.frog')).to.exist; + }); + + it('is featuring 4 items', () => { + clock = Sinon.useFakeTimers(new Date('2024-02-08')); + const items = featuredItems.quests(); + expect(items.length).to.eql(4); + }); + }); +}); diff --git a/website/common/script/content/shop-featuredItems.js b/website/common/script/content/shop-featuredItems.js index cd2d655548..ed40d75e5e 100644 --- a/website/common/script/content/shop-featuredItems.js +++ b/website/common/script/content/shop-featuredItems.js @@ -1,5 +1,5 @@ import moment from 'moment'; -import { EVENTS } from './constants'; +import { EVENTS, getScheduleMatchingGroup } from './constants'; // Magic Hatching Potions are configured like this: // type: 'premiumHatchingPotion', // note no "s" at the end // path: 'premiumHatchingPotions.Rainbow', @@ -7,77 +7,40 @@ import { EVENTS } from './constants'; // hatching potions and food names should be capitalized lest you break the market const featuredItems = { market () { - if (moment().isBetween(EVENTS.spring2024.start, EVENTS.spring2024.end)) { - return [ - { - type: 'armoire', - path: 'armoire', - }, - { + const featured = [{ + type: 'armoire', + path: 'armoire', + }]; + const itemKeys = getScheduleMatchingGroup('premiumHatchingPotions').items; + itemKeys.forEach(itemKey => { + if (featured.length < 4) { + featured.push({ type: 'premiumHatchingPotion', - path: 'premiumHatchingPotions.Celestial', - }, - { - type: 'premiumHatchingPotion', - path: 'premiumHatchingPotions.Shimmer', - }, - { - type: 'premiumHatchingPotion', - path: 'premiumHatchingPotions.Rainbow', - }, - ]; - } - return [ - { - type: 'armoire', - path: 'armoire', - }, - { - type: 'food', - path: 'food.Fish', - }, - { - type: 'hatchingPotions', - path: 'hatchingPotions.Skeleton', - }, - { - type: 'eggs', - path: 'eggs.Fox', - }, - ]; + path: `premiumHatchingPotions.${itemKey}`, + }); + } + }); + return featured; }, quests () { - if (moment().isBetween(EVENTS.bundle202403.start, EVENTS.bundle202403.end)) { - return [ - { - type: 'bundles', - path: 'bundles.cuddleBuddies', - }, - { + const featured = []; + const bundleKeys = getScheduleMatchingGroup('bundles').items; + bundleKeys.forEach(itemKey => { + featured.push({ + type: 'bundles', + path: `bundles.${itemKey}`, + }); + }); + const petQuestKeys = getScheduleMatchingGroup('petQuests').items; + petQuestKeys.forEach(itemKey => { + if (featured.length < 4) { + featured.push({ type: 'quests', - path: 'quests.hedgehog', - }, - { - type: 'quests', - path: 'quests.sheep', - }, - ]; - } - - return [ - { - type: 'quests', - path: 'quests.rat', - }, - { - type: 'quests', - path: 'quests.kraken', - }, - { - type: 'quests', - path: 'quests.slime', - }, - ]; + path: `quests.${itemKey}`, + }); + } + }); + return featured; }, seasonal: 'spring2019CloudRogueSet', timeTravelers: [