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

Code before:

      expect(async () => {
        await fastifyTestInstance.prisma.examEnvironmentExam.create({
          data
        });
      }).not.toThrow();
    });
  });
  describe('ExamEnvironmentGeneratedExam', () => {
    afterAll(async () => {
      await fastifyTestInstance.prisma.examEnvironmentGeneratedExam.deleteMany(
        {}
      );
    });
    it('should throw if the schema changes, and remind to increment the `version` field by 1', () => {
      expect(async () => {
        await fastifyTestInstance.prisma.examEnvironmentGeneratedExam.create({
          data: {
            deprecated: false,
            examId: oid(),
            questionSets: [
              { id: oid(), questions: [{ answers: [oid()], id: oid() }] }
            ]
          }
        });
      }).not.toThrow();
    });
  });
  describe('ExamEnvironmentExamAttempt', () => {
    afterAll(async () => {
      await fastifyTestInstance.prisma.examEnvironmentExamAttempt.deleteMany(
        {}
      );
    });
    it('should throw if the schema changes, and remind to increment the `version` field by 1', () => {
      expect(async () => {
        await fastifyTestInstance.prisma.examEnvironmentExamAttempt.create({
          data: {
            examId: oid(),
            generatedExamId: oid(),
            questionSets: [
              {
                id: oid(),
                questions: [
                  { answers: [oid()], id: oid(), submissionTimeInMS: 0 }
                ]
              }
            ],
            startTimeInMS: 0,
            userId: oid()
          }

Review comment (suggestion):
```suggestion
      await fastifyTestInstance.prisma.examEnvironmentGeneratedExam.create({
        data: {
          deprecated: false,
          examId: oid(),
          questionSets: [
            { id: oid(), questions: [{ answers: [oid()], id: oid() }] }
          ]
        }
      });
```

Code after:

      await fastifyTestInstance.prisma.examEnvironmentExam.create({
        data
      });
    });
  });
  describe('ExamEnvironmentGeneratedExam', () => {
    afterAll(async () => {
      await fastifyTestInstance.prisma.examEnvironmentGeneratedExam.deleteMany(
        {}
      );
    });
    it("If this test fails and you've deliberately altered the schema, then increment the `version` field by 1", async () => {
      await fastifyTestInstance.prisma.examEnvironmentGeneratedExam.create({
        data: {
          deprecated: false,
          examId: oid(),
          questionSets: [
            { id: oid(), questions: [{ answers: [oid()], id: oid() }] }
          ]
        }
      });
    });
  });
  describe('ExamEnvironmentExamAttempt', () => {
    afterAll(async () => {
      await fastifyTestInstance.prisma.examEnvironmentExamAttempt.deleteMany(
        {}
      );
    });
    it("If this test fails and you've deliberately altered the schema, then increment the `version` field by 1", async () => {
      await fastifyTestInstance.prisma.examEnvironmentExamAttempt.create({
        data: {
          examId: oid(),
          generatedExamId: oid(),
          questionSets: [
            {
              id: oid(),
              questions: [
                { answers: [oid()], id: oid(), submissionTimeInMS: 0 }
              ]
            }
          ],
          startTimeInMS: 0,
          userId: oid()
        }
      });
    });
  });
});