feat: add unmet exam prerequisites (#63131)

Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
This commit is contained in:
Shaun Hamilton
2025-10-28 15:44:16 +02:00
committed by GitHub
parent 2d04d11056
commit eb649ff99c
6 changed files with 94 additions and 12 deletions
@@ -712,7 +712,8 @@ describe('/exam-environment/', () => {
totalTimeInS: mock.exam.config.totalTimeInS,
retakeTimeInS: mock.exam.config.retakeTimeInS
},
id: mock.examId
id: mock.examId,
prerequisites: mock.exam.prerequisites
}
]);
@@ -787,7 +788,8 @@ describe('/exam-environment/', () => {
totalTimeInS: mock.exam.config.totalTimeInS,
retakeTimeInS: mock.exam.config.retakeTimeInS
},
id: mock.examId
id: mock.examId,
prerequisites: mock.exam.prerequisites
}
]);
expect(res.body).toMatchObject([{ canTake: true }]);
@@ -694,7 +694,11 @@ async function postExamAttemptHandler(
return reply.code(200).send();
}
async function getExams(
/**
* Get all the public information about all exams.
* @returns Public information about exams + whether Camper may take the exam or not.
*/
export async function getExams(
this: FastifyInstance,
req: UpdateReqType<typeof schemas.examEnvironmentExams>,
reply: FastifyReply
@@ -763,7 +767,8 @@ async function getExams(
retakeTimeInS: exam.config.retakeTimeInS,
passingPercent: exam.config.passingPercent
},
canTake: false
canTake: false,
prerequisites: exam.prerequisites
};
const isExamPrerequisitesMet = checkPrerequisites(user, exam.prerequisites);
@@ -2,7 +2,7 @@ import { Type } from '@fastify/type-provider-typebox';
import { STANDARD_ERROR } from '../utils/errors.js';
export const examEnvironmentExams = {
headers: Type.Object({
'exam-environment-authorization-token': Type.String()
'exam-environment-authorization-token': Type.Optional(Type.String())
}),
response: {
200: Type.Array(
@@ -15,7 +15,8 @@ export const examEnvironmentExams = {
retakeTimeInS: Type.Number(),
passingPercent: Type.Number()
}),
canTake: Type.Boolean()
canTake: Type.Boolean(),
prerequisites: Type.Array(Type.String())
})
),
500: STANDARD_ERROR
+9 -1
View File
@@ -31,7 +31,8 @@ import { DEPLOYMENT_ENV, JWT_SECRET } from '../../utils/env.js';
import {
getExamAttemptHandler,
getExamAttemptsByExamIdHandler,
getExamAttemptsHandler
getExamAttemptsHandler,
getExams
} from '../../exam-environment/routes/exam-environment.js';
import { ERRORS } from '../../exam-environment/utils/errors.js';
@@ -565,6 +566,13 @@ export const userRoutes: FastifyPluginCallbackTypebox = (
},
getExamAttemptsByExamIdHandler
);
fastify.get(
'/user/exam-environment/exams',
{
schema: examEnvironmentSchemas.examEnvironmentExams
},
getExams
);
done();
};