From 260d64a0eded0e0276130dd574e8f7b4437c26e6 Mon Sep 17 00:00:00 2001 From: Niraj Nandish Date: Wed, 19 Jul 2023 15:10:32 +0400 Subject: [PATCH] fix(api): getChallenges helper function (#51011) Co-authored-by: Oliver Eyton-Williams --- api/src/utils/get-challenges.test.ts | 22 ++++++++++++++++++++++ api/src/utils/get-challenges.ts | 4 +--- 2 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 api/src/utils/get-challenges.test.ts diff --git a/api/src/utils/get-challenges.test.ts b/api/src/utils/get-challenges.test.ts new file mode 100644 index 00000000000..f31c50f96db --- /dev/null +++ b/api/src/utils/get-challenges.test.ts @@ -0,0 +1,22 @@ +import { getChallenges } from './get-challenges'; +import { isObjectID } from './validation'; + +describe('getChallenges', () => { + test('returns an array of challenges', () => { + const challenges = getChallenges(); + expect(Array.isArray(challenges)).toBe(true); + expect(challenges.length).toBeGreaterThan(0); + }); + + test('challenge objects should contain challengeType and id', () => { + const challenges = getChallenges(); + + for (const challenge of challenges) { + expect(challenge).toHaveProperty('challengeType'); + expect(typeof challenge?.challengeType).toBe('number'); + + expect(challenge).toHaveProperty('id'); + expect(isObjectID(challenge?.id)).toBe(true); + } + }); +}); diff --git a/api/src/utils/get-challenges.ts b/api/src/utils/get-challenges.ts index 3b6867e23df..9bbb1c0d764 100644 --- a/api/src/utils/get-challenges.ts +++ b/api/src/utils/get-challenges.ts @@ -7,9 +7,7 @@ import curriculum from '../../../config/curriculum.json'; import { SuperBlocks } from '../../../config/superblocks'; type Curriculum = { [keyValue in SuperBlocks]?: CurriculumProps }; -type SuperBlockKeys = keyof Curriculum; -// eslint-disable-next-line @typescript-eslint/no-unused-vars interface Block { challenges: { id: string; @@ -23,7 +21,7 @@ interface CurriculumProps { } export function getChallenges() { - const superBlockKeys = Object.keys(SuperBlocks) as SuperBlockKeys[]; + const superBlockKeys = Object.values(SuperBlocks); const typedCurriculum: Curriculum = curriculum as Curriculum; return superBlockKeys