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

Code before:
          userId: defaultUserId,
          startTimeInMS: Date.now() - mock.exam.config.totalTimeInMS
        };
        await fastifyTestInstance.prisma.examEnvironmentExamAttempt.create({
          data: recentExamAttempt
        });

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

        expect(res.body).toStrictEqual([
          {
            canTake: false,
            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(res.status).toBe(200);

        // Update the attempt to be outside the retake time
        await fastifyTestInstance.prisma.examEnvironmentExamAttempt.update({
          where: { id: recentExamAttempt.id },
          data: {
            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,

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

Code after:
                mock.exam.config.retakeTimeInMS +
                1000)
          }
        });

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

        expect(res2.body).toMatchObject([{ canTake: true }]);

        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
          }
        });

        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 () => {