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

Code before:
          expect(resUpdate.body).toStrictEqual({
            alreadyCompleted: true,
            points: 2,
            completedDate: expect.any(Number),
            savedChallenges: [
              {
                id: multiFileCertProjectId,
                lastSavedDate: expect.any(Number),
                files: updatedMultiFileCertProjectBody.files
              }
            ]
          });
          expect(resUpdate.statusCode).toBe(200);
        });
      });
    });

    describe('/save-challenge', () => {
      describe('validation', () => {
        test('POST returns 403 status for unsavable challenges', async () => {
          const response = await superRequest('/save-challenge', {
            method: 'POST',
            setCookies
          }).send({
            savedChallenges: {
              id: 'not a valid id',
              lastSavedDate: Date.now(),
              files: multiFileCertProjectBody.files
            }
          });

          expect(response.body).toEqual({
            message: 'That challenge type is not savable.',
            type: 'error'
          });
          expect(response.statusCode).toBe(403);
        });
      });

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

        test('POST update the user savedchallenges and return them', async () => {
          const now = Date.now();

Review comment (suggestion):
```suggestion
              // valid mongo id, but not a savable one
              id: 'aaaaaaaaaaaaaaaaaaaaaaa',
```

Code after:
          expect(resUpdate.body).toStrictEqual({
            alreadyCompleted: true,
            points: 2,
            completedDate: expect.any(Number),
            savedChallenges: [
              {
                id: multiFileCertProjectId,
                lastSavedDate: expect.any(Number),
                files: updatedMultiFileCertProjectBody.files
              }
            ]
          });
          expect(resUpdate.statusCode).toBe(200);
        });
      });
    });

    describe('/save-challenge', () => {
      describe('validation', () => {
        test('POST returns 403 status for unsavable challenges', async () => {
          const response = await superRequest('/save-challenge', {
            method: 'POST',
            setCookies
          }).send({
            savedChallenges: {
              // valid mongo id, but not a savable one
              id: 'aaaaaaaaaaaaaaaaaaaaaaa',
              files: multiFileCertProjectBody.files
            }
          });

          expect(response.body).toEqual({
            message: 'That does not appear to be a valid challenge submission.',
            type: 'error'
          });
          expect(response.statusCode).toBe(400);
        });
      });

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

        test('POST update the user savedchallenges and return them', async () => {
          const response = await superRequest('/save-challenge', {