Repository: freeCodeCamp/freeCodeCamp
File: api/src/routes/challenge.test.ts (TypeScript)

Code before:
            alreadyCompleted: false,
            points: 1,
            completedDate,
            savedChallenges: []
          });
        });

        // JS Project(5), Multi-file Cert Project(14)
        test('POST accepts challenges with files present', async () => {
          const now = Date.now();

          const response = await superRequest('/modern-challenge-completed', {
            method: 'POST',
            setCookies
          }).send(JsProjectBody);

          const user = await fastifyTestInstance.prisma.user.findFirst({
            where: { email: 'foo@bar.com' }
          });

          if (!JsProjectBody.files[0]) {
            throw new Error(
              'JsProjectBody.files[0] is undefined but it definitely should not be.'
            );
          }
          const { history: _history, ...files } = JsProjectBody.files[0];

          expect(user).toMatchObject({
            completedChallenges: [
              {
                id: JsProjectId,
                challengeType: JsProjectBody.challengeType,
                files: [files],
                completedDate: expect.any(Number)
              }
            ]
          });

          const completedDate = user?.completedChallenges[0]?.completedDate;
          expect(completedDate).toBeGreaterThanOrEqual(now);
          expect(completedDate).toBeLessThanOrEqual(now + 1000);

          expect(response.statusCode).toBe(200);
          expect(response.body).toStrictEqual({
            alreadyCompleted: false,
            points: 1,
            completedDate,
            savedChallenges: []
          });
        });


Review comment (suggestion):
```suggestion
          const file = omit(JsProjectBody.files[0], 'history');
```
Nit: lodash omit makes this cleaner, imo.

Code after:

      describe('handling', () => {
        afterEach(async () => {
          await fastifyTestInstance.prisma.user.updateMany({
            where: { email: 'foo@bar.com' },
            data: {
              completedChallenges: [],
              progressTimestamps: []
            }
          });
        });

        test('POST accepts backend challenges', async () => {
          const now = Date.now();

          const response = await superRequest('/backend-challenge-completed', {
            method: 'POST',
            setCookies
          }).send(backendChallengeBody1);

          const user = await fastifyTestInstance.prisma.user.findFirst({
            where: { email: 'foo@bar.com' }
          });

          expect(user).toMatchObject({
            completedChallenges: [
              {
                ...backendChallengeBody1,
                completedDate: expect.any(Number)
              }
            ]
          });

          const completedDate = user?.completedChallenges[0]?.completedDate;
          expect(completedDate).toBeGreaterThanOrEqual(now);
          expect(completedDate).toBeLessThanOrEqual(now + 1000);

          expect(response.body).toStrictEqual({
            alreadyCompleted: false,
            points: 1,
            completedDate
          });
          expect(response.statusCode).toBe(200);
        });

        test('POST correctly handles multiple requests', async () => {
          const resOriginal = await superRequest(
            '/backend-challenge-completed',
            {
              method: 'POST',
              setCookies