mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
feat: add unmet exam prerequisites (#63131)
Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user