Now that we have our billing API all set up, let’s do a quick test in our local environment.

Create a mocks/billing-event.json file and add the following.

{
  "body": "{\"source\":\"tok_visa\",\"storage\":21}",
  "requestContext": {
    "identity": {
      "cognitoIdentityId": "USER-SUB-1234"
    }
  }
}

We are going to be testing with a Stripe test token called tok_visa and with 21 as the number of notes we want to store. You can read more about the Stripe test cards and tokens in the Stripe API Docs here.

Let’s now invoke our billing API by running the following in our project root.

$ serverless invoke local --function billing --path mocks/billing-event.json

The response should look similar to this.

{
    "statusCode": 200,
    "headers": {
        "Access-Control-Allow-Origin": "*",
        "Access-Control-Allow-Credentials": true
    },
    "body": "{\"status\":true}"
}

Commit the Changes

Let’s commit these to Git.

$ git add .
$ git commit -m "Adding a mock event for the billing API"

Now that we have our new billing API ready. Let’s look at how to setup unit tests to ensure that our business logic has been configured correctly.