feat(api): add exam utils and GET /exam/:id endpoint to new api (#51609)

This commit is contained in:
Tom
2023-10-26 03:05:09 -05:00
committed by GitHub
parent 75f8d5fd87
commit 46375c6dd6
12 changed files with 799 additions and 5 deletions
+17
View File
@@ -2,6 +2,7 @@ import request from 'supertest';
import { build } from './src/app';
import { createUserInput } from './src/utils/create-user';
import { examJson } from './__mocks__/exam';
type FastifyTestInstance = Awaited<ReturnType<typeof build>>;
@@ -92,3 +93,19 @@ export async function devLogin(): Promise<string[]> {
expect(res.status).toBe(200);
return res.get('Set-Cookie');
}
export async function seedExam(): Promise<void> {
const query = { where: { id: examJson.id } };
const testExamExists =
await fastifyTestInstance.prisma.exam.findUnique(query);
if (testExamExists) {
await fastifyTestInstance.prisma.exam.deleteMany(query);
}
await fastifyTestInstance.prisma.exam.create({
data: {
...examJson
}
});
}