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

Code before:
      test('POST sanitises report description', async () => {
        const response = await superRequest('/user/report-user', {
          method: 'POST',
          setCookies
        }).send({
          username: 'darth-vader',
          reportDescription:
            '<script>const breath = "loud"</script>Luke, I am your father'
        });

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

        expect(sendEmailSpy).toBeCalledTimes(1);
        expect(sendEmailSpy).toBeCalledWith({
          from: 'team@freecodecamp.org',
          to: 'support@freecodecamp.org',
          cc: user?.email,
          subject: "Abuse Report: Reporting darth-vader's profile",
          text: generateReportEmail(
            user,
            'darth-vader',
            'Luke, I am your father'
          )
        });

        expect(response.statusCode).toBe(200);
        expect(response.body).toStrictEqual({
          type: 'info',
          message: 'flash.report-sent',
          variables: { email: user?.email }
        });
      });

      test('POST returns 200 status code with "success" message', async () => {
        const response = await superRequest('/user/report-user', {
          method: 'POST',
          setCookies
        }).send({
          username: 'darth-vader',
          reportDescription: 'Luke, I am your father'
        });

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

        expect(sendEmailSpy).toBeCalledTimes(1);
        expect(sendEmailSpy).toBeCalledWith({
          from: 'team@freecodecamp.org',

Review comment (suggestion):
```suggestion
        expect(sendEmailSpy).toBeCalledWith(
          expect.objectContaining({
            text: expect.stringContaining(
              'Report Details:\n\nLuke, I am your father'
            )
          })
        );
```
That's the only bit we're concerned with, here.

Code after:
          setCookies
        }).send({
          username: 'darth-vader',
          reportDescription:
            '<script>const breath = "loud"</script>Luke, I am your father'
        });

        expect(sendEmailSpy).toBeCalledTimes(1);
        expect(sendEmailSpy).toBeCalledWith(
          expect.objectContaining({
            text: expect.stringContaining(
              'Report Details:\n\nLuke, I am your father'
            )
          })
        );
      });

      test('POST returns 200 status code with "success" message', async () => {
        const response = await superRequest('/user/report-user', {
          method: 'POST',
          setCookies
        }).send({
          username: 'darth-vader',
          reportDescription: 'Luke, I am your father'
        });

        expect(sendEmailSpy).toBeCalledTimes(1);
        expect(sendEmailSpy).toBeCalledWith({
          from: 'team@freecodecamp.org',
          to: 'support@freecodecamp.org',
          cc: 'foo@bar.com',
          subject: "Abuse Report: Reporting darth-vader's profile",
          text: `
Hello Team,

This is to report the profile of darth-vader.

Report Details:

Luke, I am your father


Reported by:
Username: 
Name: 
Email: foo@bar.com

Thanks and regards,
`
        });