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

Code before:
    });

    describe('/account/reset-progress', () => {
      test('POST returns 200 status code with empty object', async () => {
        await fastifyTestInstance.prisma.user.updateMany({
          where: { email: 'foo@bar.com' },
          data: modifiedProgressData
        });

        const response = await superRequest('/account/reset-progress', {
          method: 'POST',
          setCookies
        });

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

        expect(response.status).toBe(200);
        expect(response.body).toStrictEqual({});

        let key: keyof typeof baseProgressData;
        expect(user?.progressTimestamps).toHaveLength(1);
        for (key in baseProgressData) {
          expect(user?.[key]).toStrictEqual(baseProgressData[key]);
        }
      });
    });
  });

  describe('Unauthenticated user', () => {
    // TODO: get CSRF cookies when that PR is in.
    describe('/account/delete', () => {
      test('POST returns 401 status code with error message', async () => {
        const response = await superRequest('/account/delete', {
          method: 'POST'
        });

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

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

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

Review comment (suggestion):
```suggestion
        expect(user).toMatchObject(baseProgressData);
```
This gives better errors than a key-by-key comparison.

Code after:
      });
    });

    describe('/account/reset-progress', () => {
      test('POST returns 200 status code with empty object', async () => {
        await fastifyTestInstance.prisma.user.updateMany({
          where: { email: 'foo@bar.com' },
          data: modifiedProgressData
        });

        const response = await superRequest('/account/reset-progress', {
          method: 'POST',
          setCookies
        });

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

        expect(response.status).toBe(200);
        expect(response.body).toStrictEqual({});

        expect(user?.progressTimestamps).toHaveLength(1);
        expect(user).toMatchObject(baseProgressData);
      });
    });
  });

  describe('Unauthenticated user', () => {
    // TODO: get CSRF cookies when that PR is in.
    describe('/account/delete', () => {
      test('POST returns 401 status code with error message', async () => {
        const response = await superRequest('/account/delete', {
          method: 'POST'
        });

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

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

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