fix(api): 400 for exam-challenge route with no params (#62404)

This commit is contained in:
Shaun Hamilton
2025-09-29 15:26:29 +02:00
committed by GitHub
parent 20a77c44d0
commit c7a8b183d3
2 changed files with 20 additions and 0 deletions
@@ -1304,6 +1304,16 @@ describe('/exam-environment/', () => {
); );
expect(res3.status).toBe(200); expect(res3.status).toBe(200);
}); });
it('should return 400 if neither challengeId or examId are provided', async () => {
const res = await superGet(`/exam-environment/exam-challenge`);
expect(res).toMatchObject({
status: 400,
body: {
code: 'FCC_ERR_EXAM_ENVIRONMENT'
}
});
});
}); });
}); });
}); });
@@ -1010,6 +1010,16 @@ export async function getExamChallenge(
logger.info({ challengeId, examId }); logger.info({ challengeId, examId });
if (!challengeId && !examId) {
logger.warn('No challenge or exam id provided.');
void reply.code(400);
return reply.send(
ERRORS.FCC_ERR_EXAM_ENVIRONMENT(
'Must provide either a challengeId or examId.'
)
);
}
const maybeData = await mapErr( const maybeData = await mapErr(
this.prisma.examEnvironmentChallenge.findMany({ this.prisma.examEnvironmentChallenge.findMany({
where: { where: {