testing the handler

The function under test

Possible inputs

  • The json can be correct or incorrect

  • A "good" json string is converted to a SendgridRequest object

  • A failed conversion is snet back to the client as a BAD REQUEST

Possible outputs

  • a Sendgrid Response object

  • a Runtime exception

  • a null Response object

Example - Testing the Controller request

We don't have many scenarios to cover in the handler. The json conversion will either fail or succeed for any number of reasons. If the conversion succeeds we pass the result to the SendgridMailer function. If it fails we want to return a BAD REQUEST.

In the example below, the handler receives a bad json string which will throw a Json exception. The handler function should catch the exception and return a BAD_REQUEST Response object to the controller

Example - Testing the SendgridMailer response

In the example below, the handler calls the mailer function which throws an exception. The handler function should catch the exception and return a Response object to the controller

Last updated

Was this helpful?