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

Code before:
          data: {
            completedChallenges: [
              { id: mock.exam.prerequisites.at(0)!, completedDate: Date.now() }
            ]
          }
        });

        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 may be taken if the user has no prior attempts', async () => {
        const res = await superGet('/exam-environment/exams').set(
          'exam-environment-authorization-token',
          examEnvironmentAuthorizationToken
        );

        expect(res.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(res.status).toBe(200);
      });

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

Code after:
          examEnvironmentAuthorizationToken
        );

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

      it('should indicate an exam may be taken if the user has no prior attempts', async () => {
        const res = await superGet('/exam-environment/exams').set(
          'exam-environment-authorization-token',
          examEnvironmentAuthorizationToken
        );

        expect(res.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(res.body).toMatchObject([{ canTake: true }]);
        expect(res.status).toBe(200);
      });

      it("should indicate an exam's availability based on the last attempt's start time, and the exam retake time", async () => {
        // Create a recent exam attempt that's within the retake time
        const recentExamAttempt = {
          ...mock.examAttempt,
          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).toMatchObject([{ canTake: false }]);
        expect(res.status).toBe(200);

        // Update the attempt to be outside the retake time
        await fastifyTestInstance.prisma.examEnvironmentExamAttempt.update({