mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-04-30 16:01:14 -04:00
fix(api): getChallenges helper function (#51011)
Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
This commit is contained in:
22
api/src/utils/get-challenges.test.ts
Normal file
22
api/src/utils/get-challenges.test.ts
Normal 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);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user