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

Code before:
          ..._.omit(minimalUserData, ['externalId', 'unsubscribeId']),
          ...computedProperties,
          id: testUser?.id,
          joinDate: new ObjectId(testUser?.id).getTimestamp().toISOString()
        };

        const response = await superRequest('/user/get-session-user', {
          method: 'GET',
          setCookies
        });

        const {
          user: { testuser }
        } = response.body as unknown as {
          user: { testuser: typeof publicUser };
        };

        expect(testuser).toStrictEqual(publicUser);
      });
    });

    describe('/user/report-user', () => {
      afterEach(() => {
        jest.clearAllMocks();
      });

      test('POST returns 400 for empty username', async () => {
        const response = await superRequest('/user/report-user', {
          method: 'POST',
          setCookies
        }).send({
          username: '',
          reportDescription: 'Test Report'
        });

        expect(response.statusCode).toBe(400);
        expect(response.body).toStrictEqual({
          type: 'danger',
          message: 'flash.provide-username'
        });
      });

      test('POST returns 400 for empty report', async () => {
        const response = await superRequest('/user/report-user', {
          method: 'POST',
          setCookies
        }).send({
          username: 'darth-vader',
          reportDescription: ''
        });


Review comment (suggestion):
```suggestion
      let sendEmailSpy: jest.SpyInstance;
      beforeEach(() => {
        sendEmailSpy =jest
          .spyOn(fastifyTestInstance, 'sendEmail')
          .mockImplementation(jest.fn());
      });
      afterEach(() => {
```
This lets us check the only thing we're interested in: does the route try to send an email.

Code after:
        };

        const response = await superRequest('/user/get-session-user', {
          method: 'GET',
          setCookies
        });

        const {
          user: { testuser }
        } = response.body as unknown as {
          user: { testuser: typeof publicUser };
        };

        expect(testuser).toStrictEqual(publicUser);
      });
    });

    describe('/user/report-user', () => {
      let sendEmailSpy: jest.SpyInstance;
      beforeEach(() => {
        sendEmailSpy = jest
          .spyOn(fastifyTestInstance, 'sendEmail')
          .mockImplementation(jest.fn());
      });

      afterEach(() => {
        jest.clearAllMocks();
      });

      test('POST returns 400 for empty username', async () => {
        const response = await superRequest('/user/report-user', {
          method: 'POST',
          setCookies
        }).send({
          username: '',
          reportDescription: 'Test Report'
        });

        expect(response.statusCode).toBe(400);
        expect(response.body).toStrictEqual({
          type: 'danger',
          message: 'flash.provide-username'
        });
      });

      test('POST returns 400 for empty report', async () => {
        const response = await superRequest('/user/report-user', {
          method: 'POST',
          setCookies
        }).send({
          username: 'darth-vader',