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

Code before:
          data: donationMock
        });
        const response = await superPut('/donate/update-stripe-card');
        expect(mockCheckoutSessionCreate).toHaveBeenCalledWith({
          cancel_url: 'http://localhost:8000/update-stripe-card',
          customer: 'cust_test_id',
          mode: 'setup',
          payment_method_types: ['card'],
          setup_intent_data: {
            metadata: {
              customer_id: 'cust_test_id',
              subscription_id: 'sub_test_id'
            }
          },
          success_url:
            'http://localhost:8000/update-stripe-card?session_id={CHECKOUT_SESSION_ID}'
        });
        expect(response.body).toEqual({ sessionId: 'checkout_session_id' });
        expect(response.status).toBe(200);

        expect(true).toBe(true);
      });
      it('should return 500 if there is no donation record', async () => {
        const response = await superPut('/donate/update-stripe-card');
        expect(response.body).toEqual({
          message: 'Something went wrong.',
          type: 'danger'
        });
        expect(response.status).toBe(500);
      });
    });

    describe('POST /donate/create-stripe-payment-intent', () => {
      it('should return 200 and call stripe api properly', async () => {
        mockSubCreate.mockImplementationOnce(
          generateMockSubCreate('no-errors')
        );
        const response = await superPost(
          '/donate/create-stripe-payment-intent'
        ).send(createStripePaymentIntentReqBody);
        expect(mockCustomerCreate).toHaveBeenCalledWith({
          email: testEWalletEmail,
          name: 'Baz Bar'
        });
        expect(response.status).toBe(200);
      });

      it('should return 400 when email format is wrong', async () => {
        const response = await superPost(
          '/donate/create-stripe-payment-intent'
        ).send({

Review comment (suggestion):
```suggestion
          message: 'flash.generic-error',
```
Sorry, missed this.

Code after:
          data: donationMock
        });
        const response = await superPut('/donate/update-stripe-card').send({});
        expect(mockCheckoutSessionCreate).toHaveBeenCalledWith({
          cancel_url: 'http://localhost:8000/update-stripe-card',
          customer: 'cust_test_id',
          mode: 'setup',
          payment_method_types: ['card'],
          setup_intent_data: {
            metadata: {
              customer_id: 'cust_test_id',
              subscription_id: 'sub_test_id'
            }
          },
          success_url:
            'http://localhost:8000/update-stripe-card?session_id={CHECKOUT_SESSION_ID}'
        });
        expect(response.body).toEqual({ sessionId: 'checkout_session_id' });
        expect(response.status).toBe(200);
      });
      it('should return 500 if there is no donation record', async () => {
        const response = await superPut('/donate/update-stripe-card').send({});
        expect(response.body).toEqual({
          message: 'flash.generic-error',
          type: 'danger'
        });
        expect(response.status).toBe(500);
      });
    });

    describe('POST /donate/create-stripe-payment-intent', () => {
      it('should return 200 and call stripe api properly', async () => {
        mockSubCreate.mockImplementationOnce(
          generateMockSubCreate('no-errors')
        );
        const response = await superPost(
          '/donate/create-stripe-payment-intent'
        ).send(createStripePaymentIntentReqBody);
        expect(mockCustomerCreate).toHaveBeenCalledWith({
          email: testEWalletEmail,
          name: 'Baz Bar'
        });
        expect(response.status).toBe(200);
      });

      it('should return 400 when email format is wrong', async () => {
        const response = await superPost(
          '/donate/create-stripe-payment-intent'
        ).send({
          ...createStripePaymentIntentReqBody,
          email: '12raqdcev'