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

Code before:

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

          const savedDate = user?.savedChallenges[0]?.lastSavedDate;

          expect(user).toMatchObject({
            savedChallenges: [
              {
                id: multiFileCertProjectId,
                lastSavedDate: savedDate,
                files: updatedMultiFileCertProjectBody.files
              }
            ]
          });
          expect(response.body).toEqual({
            savedChallenges: [
              {
                id: multiFileCertProjectId,
                lastSavedDate: savedDate,
                files: updatedMultiFileCertProjectBody.files
              }
            ]
          });
          expect(user?.savedChallenges).toHaveLength(1);
          expect(response.statusCode).toBe(200);
        });
      });
    });
  });

  describe('Unauthenticated user', () => {
    let setCookies: string[];

    // Get the CSRF cookies from an unprotected route
    beforeAll(async () => {
      const res = await superRequest('/', { method: 'GET' });
      setCookies = res.get('Set-Cookie');
    });

    describe('/coderoad-challenge-completed', () => {
      test('POST returns 401 status code with error message', async () => {
        const response = await superRequest('/coderoad-challenge-completed', {
          method: 'POST',
          setCookies
        });

        expect(response?.statusCode).toBe(401);
      });
    });

Review comment (suggestion):
```suggestion
```
This is already checked above.

Code after:
            where: { email: 'foo@bar.com' }
          });

          const savedDate = user.savedChallenges[0]?.lastSavedDate;

          expect(user).toMatchObject({
            savedChallenges: [
              {
                id: multiFileCertProjectId,
                lastSavedDate: savedDate,
                files: updatedMultiFileCertProjectBody.files
              }
            ]
          });
          expect(response.body).toEqual({
            savedChallenges: [
              {
                id: multiFileCertProjectId,
                lastSavedDate: savedDate,
                files: updatedMultiFileCertProjectBody.files
              }
            ]
          });
          expect(response.statusCode).toBe(200);
        });
      });
    });
  });

  describe('Unauthenticated user', () => {
    let setCookies: string[];

    // Get the CSRF cookies from an unprotected route
    beforeAll(async () => {
      const res = await superRequest('/', { method: 'GET' });
      setCookies = res.get('Set-Cookie');
    });

    describe('/coderoad-challenge-completed', () => {
      test('POST returns 401 status code with error message', async () => {
        const response = await superRequest('/coderoad-challenge-completed', {
          method: 'POST',
          setCookies
        });

        expect(response?.statusCode).toBe(401);
      });
    });

    describe('/project-completed', () => {
      test('POST returns 401 status code with error message', async () => {