From d4ba96796c3bdb79f40b96d7722ba9427e057df0 Mon Sep 17 00:00:00 2001 From: Phillip Thelen Date: Mon, 10 Jun 2024 14:44:21 +0200 Subject: [PATCH] Improve test coverage --- test/content/armoire.test.js | 14 ++++ test/content/releaseDates.test.js | 66 +++++++++++++++++++ .../{release_dates.js => releaseDates.js} | 0 website/common/script/content/eggs.js | 2 +- .../script/content/gear/sets/armoire.js | 2 +- .../common/script/content/hatching-potions.js | 2 +- 6 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 test/content/releaseDates.test.js rename website/common/script/content/constants/{release_dates.js => releaseDates.js} (100%) diff --git a/test/content/armoire.test.js b/test/content/armoire.test.js index 6462939782..5ed052d7a9 100644 --- a/test/content/armoire.test.js +++ b/test/content/armoire.test.js @@ -66,4 +66,18 @@ describe('armoire', () => { const febuaryItems = makeArmoireIitemList(); expect(febuaryItems.length).to.equal(384); }); + + it('sets have at least 2 items', () => { + const armoire = makeArmoireIitemList(); + const setMap = {}; + forEach(armoire, item => { + if (setMap[item.set] === undefined) { + setMap[item.set] = 0; + } + setMap[item.set] += 1; + }); + Object.keys(setMap).forEach(set => { + expect(setMap[set], set).to.be.at.least(2); + }); + }); }); diff --git a/test/content/releaseDates.test.js b/test/content/releaseDates.test.js new file mode 100644 index 0000000000..e481146ccb --- /dev/null +++ b/test/content/releaseDates.test.js @@ -0,0 +1,66 @@ +import find from 'lodash/find'; +import { + ARMOIRE_RELEASE_DATES, + EGGS_RELEASE_DATES, + HATCHING_POTIONS_RELEASE_DATES, +} from '../../website/common/script/content/constants/releaseDates'; +import content from '../../website/common/script/content'; + +describe('releaseDates', () => { + describe('armoire', () => { + it('should only contain valid armoire names', () => { + Object.keys(ARMOIRE_RELEASE_DATES).forEach(key => { + expect(find(content.gear.flat, { set: key }), `${key} is not a valid armoire set`).to.exist; + }); + }); + + it('should contain a valid year and month', () => { + Object.keys(ARMOIRE_RELEASE_DATES).forEach(key => { + const date = ARMOIRE_RELEASE_DATES[key]; + expect(date.year, `${key} year is not a valid year`).to.be.a('number'); + expect(date.year).to.be.at.least(2023); + expect(date.month, `${key} month is not a valid month`).to.be.a('number'); + expect(date.month).to.be.within(1, 12); + expect(date.day).to.not.exist; + }); + }); + }); + + describe('eggs', () => { + it('should only contain valid egg names', () => { + Object.keys(EGGS_RELEASE_DATES).forEach(key => { + expect(content.eggs[key], `${key} is not a valid egg name`).to.exist; + }); + }); + + it('should contain a valid year, month and date', () => { + Object.keys(EGGS_RELEASE_DATES).forEach(key => { + const date = EGGS_RELEASE_DATES[key]; + expect(date.year, `${key} year is not a valid year`).to.be.a('number'); + expect(date.year).to.be.at.least(2024); + expect(date.month, `${key} month is not a valid month`).to.be.a('number'); + expect(date.month).to.be.within(1, 12); + expect(date.day, `${key} day is not a valid day`).to.be.a('number'); + }); + }); + }); + + describe('hatchingPotions', () => { + it('should only contain valid potion names', () => { + Object.keys(HATCHING_POTIONS_RELEASE_DATES).forEach(key => { + expect(content.hatchingPotions[key], `${key} is not a valid potion name`).to.exist; + }); + }); + + it('should contain a valid year, month and date', () => { + Object.keys(HATCHING_POTIONS_RELEASE_DATES).forEach(key => { + const date = HATCHING_POTIONS_RELEASE_DATES[key]; + expect(date.year, `${key} year is not a valid year`).to.be.a('number'); + expect(date.year).to.be.at.least(2024); + expect(date.month, `${key} month is not a valid month`).to.be.a('number'); + expect(date.month).to.be.within(1, 12); + expect(date.day, `${key} day is not a valid day`).to.be.a('number'); + }); + }); + }); +}); diff --git a/website/common/script/content/constants/release_dates.js b/website/common/script/content/constants/releaseDates.js similarity index 100% rename from website/common/script/content/constants/release_dates.js rename to website/common/script/content/constants/releaseDates.js diff --git a/website/common/script/content/eggs.js b/website/common/script/content/eggs.js index 7952530017..af68a5b6be 100644 --- a/website/common/script/content/eggs.js +++ b/website/common/script/content/eggs.js @@ -3,7 +3,7 @@ import each from 'lodash/each'; import assign from 'lodash/assign'; import t from './translation'; import { filterReleased } from './is_released'; -import { EGGS_RELEASE_DATES } from './constants/release_dates'; +import { EGGS_RELEASE_DATES } from './constants/releaseDates'; import datedMemoize from '../fns/datedMemoize'; function applyEggDefaults (set, config) { diff --git a/website/common/script/content/gear/sets/armoire.js b/website/common/script/content/gear/sets/armoire.js index 635054dfd6..eba2f92b95 100644 --- a/website/common/script/content/gear/sets/armoire.js +++ b/website/common/script/content/gear/sets/armoire.js @@ -7,7 +7,7 @@ import { ownsItem } from '../gear-helper'; import { ATTRIBUTES } from '../../../constants'; import t from '../../translation'; import memoize from '../../../fns/datedMemoize'; -import { ARMOIRE_RELEASE_DATES as releaseDates } from '../../constants/release_dates'; +import { ARMOIRE_RELEASE_DATES as releaseDates } from '../../constants/releaseDates'; import { buildReleaseDate } from '../../is_released'; const armor = { diff --git a/website/common/script/content/hatching-potions.js b/website/common/script/content/hatching-potions.js index ed7498c007..c293b1b99c 100644 --- a/website/common/script/content/hatching-potions.js +++ b/website/common/script/content/hatching-potions.js @@ -4,7 +4,7 @@ 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/release_dates'; +import { HATCHING_POTIONS_RELEASE_DATES } from './constants/releaseDates'; function hasQuestAchievementFunction (key) { return user => user.achievements.quests && user.achievements.quests[key] > 0;