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

Code before:
        expect(response.status).toBe(402);
        expect(response.body).toEqual({
          type: 'PaymentMethodRequired',
          message: 'Card has been declined'
        });
      });

      it('should return 400 if the user is already donating', async () => {
        mockSubCreate.mockImplementationOnce(subsDefaultReply);
        const successResponse = await superRequest(
          '/donate/charge-stripe-card',
          {
            method: 'POST',
            setCookies
          }
        ).send(chargeStripeCardReqBody);
        expect(successResponse.status).toBe(200);
        const failResponse = await superRequest('/donate/charge-stripe-card', {
          method: 'POST',
          setCookies
        }).send(chargeStripeCardReqBody);
        expect(failResponse.status).toBe(400);
      });

      it('should return 500 if Stripe encountes an error', async () => {
        mockSubCreate.mockImplementationOnce(defultError);
        const response = await superRequest('/donate/charge-stripe-card', {
          method: 'POST',
          setCookies
        }).send(chargeStripeCardReqBody);
        expect(response.status).toBe(500);
        expect(response.body).toEqual({
          type: 'danger',
          message: 'Something went wrong.'
        });
      });
    });

    describe('POST /donate/add-donation', () => {
      it('should return 200 and update the user', async () => {
        const response = await superRequest('/donate/add-donation', {
          method: 'POST',
          setCookies
        }).send({
          anything: true,
          itIs: 'ignored'
        });

        expect(response.body).toEqual({
          isDonating: true
        });

Review comment (suggestion):
```suggestion
        mockSubCreate.mockImplementationOnce(defaultError);
```

Code after:
          '/donate/charge-stripe-card',
          {
            method: 'POST',
            setCookies
          }
        ).send(chargeStripeCardReqBody);

        expect(successResponse.status).toBe(200);
        const failResponse = await superRequest('/donate/charge-stripe-card', {
          method: 'POST',
          setCookies
        }).send(chargeStripeCardReqBody);
        expect(failResponse.status).toBe(400);
      });

      it('should return 500 if Stripe encountes an error', async () => {
        mockSubCreate.mockImplementationOnce(defaultError);
        const response = await superRequest('/donate/charge-stripe-card', {
          method: 'POST',
          setCookies
        }).send(chargeStripeCardReqBody);
        expect(response.status).toBe(500);
        expect(response.body).toEqual({
          type: 'danger',
          message: 'Donation failed due to a server error.'
        });
      });
    });

    describe('POST /donate/add-donation', () => {
      it('should return 200 and update the user', async () => {
        const response = await superRequest('/donate/add-donation', {
          method: 'POST',
          setCookies
        }).send({
          anything: true,
          itIs: 'ignored'
        });

        expect(response.body).toEqual({
          isDonating: true
        });
        expect(response.status).toBe(200);
      });

      it('should return 400 if the user is already donating', async () => {
        const successResponse = await superRequest('/donate/add-donation', {
          method: 'POST',
          setCookies
        }).send({});
        expect(successResponse.status).toBe(200);