mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
feat(api): add exam utils and GET /exam/:id endpoint to new api (#51609)
This commit is contained in:
@@ -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
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user