feat(client): add exam attempts to exam-download page (#61361)

Co-authored-by: Tom <20648924+moT01@users.noreply.github.com>
Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
Co-authored-by: Mrugesh Mohapatra <1884376+raisedadead@users.noreply.github.com>
This commit is contained in:
Shaun Hamilton
2025-09-25 21:27:31 +02:00
committed by GitHub
parent 6c3bc14f52
commit 35d05d2c05
12 changed files with 397 additions and 81 deletions
@@ -1232,34 +1232,77 @@ describe('/exam-environment/', () => {
});
});
describe('GET /exam-environment/challenges/:challengeId/exam-mappings', () => {
describe('GET /exam-environment/exam-challenge', () => {
afterAll(async () => {
await fastifyTestInstance.prisma.examEnvironmentChallenge.deleteMany(
{}
);
});
it('should return 200 and an empty array if no exams are mapped to the challenge', async () => {
it('should return 200 and an empty array if no mapping exists', async () => {
const challengeId = mock.oid();
const res = await superGet(
`/exam-environment/challenges/${challengeId}/exam-mappings`
const examId = mock.oid();
const res1 = await superGet(
`/exam-environment/exam-challenge?challengeId=${challengeId}`
);
expect(res.body).toStrictEqual([]);
expect(res.status).toBe(200);
expect(res1.body).toStrictEqual([]);
expect(res1.status).toBe(200);
const res2 = await superGet(
`/exam-environment/exam-challenge?examId=${examId}`
);
expect(res2.body).toStrictEqual([]);
expect(res2.status).toBe(200);
const res3 = await superGet(
`/exam-environment/exam-challenge?challengeId=${challengeId}&examId=${examId}`
);
expect(res3.body).toStrictEqual([]);
expect(res3.status).toBe(200);
});
it('should return 200 and a list of exams mapped to the challenge', async () => {
it('should return 200 and a list of challenge-exam mappings if one exists', async () => {
await fastifyTestInstance.prisma.examEnvironmentChallenge.create({
data: mock.examEnvironmentChallenge
});
const res = await superGet(
`/exam-environment/challenges/${mock.examEnvironmentChallenge.challengeId}/exam-mappings`
const res1 = await superGet(
`/exam-environment/exam-challenge?challengeId=${mock.examEnvironmentChallenge.challengeId}`
);
expect(res.body).toEqual(
expect(res1.body).toEqual(
expect.arrayContaining([
expect.objectContaining({ examId: mock.examId })
expect.objectContaining({
examId: mock.examId,
challengeId: mock.examEnvironmentChallenge.challengeId
})
])
);
expect(res.status).toBe(200);
expect(res1.status).toBe(200);
const res2 = await superGet(
`/exam-environment/exam-challenge?examId=${mock.examId}`
);
expect(res2.body).toEqual(
expect.arrayContaining([
expect.objectContaining({
examId: mock.examId,
challengeId: mock.examEnvironmentChallenge.challengeId
})
])
);
expect(res2.status).toBe(200);
const res3 = await superGet(
`/exam-environment/exam-challenge?challengeId=${mock.examEnvironmentChallenge.challengeId}&examId=${mock.examId}`
);
expect(res3.body).toEqual(
expect.arrayContaining([
expect.objectContaining({
examId: mock.examId,
challengeId: mock.examEnvironmentChallenge.challengeId
})
])
);
expect(res3.status).toBe(200);
});
});
});
@@ -89,11 +89,11 @@ export const examEnvironmentOpenRoutes: FastifyPluginCallbackTypebox = (
tokenMetaHandler
);
fastify.get(
'/exam-environment/challenges/:challengeId/exam-mappings',
'/exam-environment/exam-challenge',
{
schema: schemas.examEnvironmentGetExamMappingsByChallengeId
schema: schemas.examEnvironmentGetExamChallenge
},
getExamMappingsByChallengeId
getExamChallenge
);
done();
};
@@ -1000,22 +1000,21 @@ export async function getExamAttemptsByExamIdHandler(
/**
* Gets all the relations for a given challenge and exam(s).
*/
export async function getExamMappingsByChallengeId(
export async function getExamChallenge(
this: FastifyInstance,
req: UpdateReqType<
typeof schemas.examEnvironmentGetExamMappingsByChallengeId
>,
req: UpdateReqType<typeof schemas.examEnvironmentGetExamChallenge>,
reply: FastifyReply
) {
const logger = this.log.child({ req });
const { challengeId } = req.params;
const { challengeId, examId } = req.query;
logger.info({ challengeId });
logger.info({ challengeId, examId });
const maybeData = await mapErr(
this.prisma.examEnvironmentChallenge.findMany({
where: {
challengeId
challengeId: challengeId ?? undefined,
examId: examId ?? undefined
}
})
);
@@ -1,9 +1,10 @@
import { Type } from '@fastify/type-provider-typebox';
// import { STANDARD_ERROR } from '../utils/errors';
export const examEnvironmentGetExamMappingsByChallengeId = {
params: Type.Object({
challengeId: Type.String({ format: 'objectid' })
export const examEnvironmentGetExamChallenge = {
querystring: Type.Object({
challengeId: Type.Optional(Type.String({ format: 'objectid' })),
examId: Type.Optional(Type.String({ format: 'objectid' }))
})
// response: {
// 200: examEnvAttempt,
+1 -1
View File
@@ -7,4 +7,4 @@ export {
export { examEnvironmentPostExamGeneratedExam } from './exam-environment-exam-generated-exam.js';
export { examEnvironmentTokenMeta } from './token-meta.js';
export { examEnvironmentExams } from './exam-environment-exams.js';
export { examEnvironmentGetExamMappingsByChallengeId } from './challenges.js';
export { examEnvironmentGetExamChallenge } from './challenges.js';