fix(api): getChallenges helper function (#51011)

Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
This commit is contained in:
Niraj Nandish
2023-07-19 15:10:32 +04:00
committed by GitHub
parent 3ce5043595
commit 260d64a0ed
2 changed files with 23 additions and 3 deletions

View File

@@ -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);
}
});
});

View File

@@ -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