Repository: freeCodeCamp/freeCodeCamp
File: api/src/exam-environment/routes/exam-environment.test.ts (TypeScript)

Code before:
            startTimeInMS:
              Date.now() -
              (mock.exam.config.totalTimeInMS +
                mock.exam.config.retakeTimeInMS +
                1000)
          }
        });

        const res2 = await superGet('/exam-environment/exams').set(
          'exam-environment-authorization-token',
          examEnvironmentAuthorizationToken
        );

        expect(res2.body).toStrictEqual([
          {
            canTake: true,
            config: {
              name: mock.exam.config.name,
              note: mock.exam.config.note,
              passingPercent: mock.exam.config.passingPercent,
              totalTimeInMS: mock.exam.config.totalTimeInMS,
              retakeTimeInMS: mock.exam.config.retakeTimeInMS
            },
            id: mock.examId
          }
        ]);

        expect(res2.status).toBe(200);
      });

      it('should indicate an exam is unavailable if there are any pending moderation records for the exam attempts', async () => {
        // Create an exam attempt that's outside the retake time
        const examAttempt = {
          ...mock.examAttempt,
          userId: defaultUserId,
          startTimeInMS:
            Date.now() -
            (mock.exam.config.totalTimeInMS +
              mock.exam.config.retakeTimeInMS +
              1000)
        };
        const createdAttempt =
          await fastifyTestInstance.prisma.examEnvironmentExamAttempt.create({
            data: examAttempt
          });

        // Create a pending moderation record for the attempt
        await fastifyTestInstance.prisma.examEnvironmentExamModeration.create({
          data: {
            examAttemptId: createdAttempt.id,
            status: ExamEnvironmentExamModerationStatus.Pending

Review comment (suggestion):
```suggestion
        expect(res2.body).toMatchObject([{ canTake: true }]);
```

Code after:
        await fastifyTestInstance.prisma.examEnvironmentExamModeration.create({
          data: {
            examAttemptId: createdAttempt.id,
            status: ExamEnvironmentExamModerationStatus.Pending
          }
        });

        const res = await superGet('/exam-environment/exams').set(
          'exam-environment-authorization-token',
          examEnvironmentAuthorizationToken
        );

        expect(res.body).toMatchObject([{ canTake: false }]);
        expect(res.status).toBe(200);
      });
    });

    describe('GET /exam-environment/exam/attempt/:attemptId', () => {
      afterEach(async () => {
        // If attempt is deleted, moderation record should cascade
        await fastifyTestInstance.prisma.examEnvironmentExamAttempt.deleteMany();
        const moderationRecords =
          await fastifyTestInstance.prisma.examEnvironmentExamModeration.findMany(
            {}
          );
        expect(moderationRecords).toHaveLength(0);
      });

      it('should return 404 if the attempt does not exist', async () => {
        const attemptId = mock.oid();
        const res = await superGet(
          `/exam-environment/exam/attempt/${attemptId}`
        ).set(
          'exam-environment-authorization-token',
          examEnvironmentAuthorizationToken
        );

        expect(res.body).toStrictEqual({
          code: 'FCC_ENOENT_EXAM_ENVIRONMENT_EXAM_ATTEMPT',
          // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
          message: expect.any(String)
        });
        expect(res.status).toBe(404);
      });

      it('should return 404 if the attempt belongs to another user', async () => {
        const otherUserAttempt =
          await fastifyTestInstance.prisma.examEnvironmentExamAttempt.create({
            data: { ...mock.examAttempt, userId: mock.oid() }
          });
        const res = await superGet(