System Testing the Checkout Flow

Get familiar with the testing of checkout flow using Active Job.

In Testing Our JavaScript Functionality, we wrote a system test that uses a real browser to simulate user interaction. To test the entire flow of checking out, communicating with the payment processor, and sending an email, we’ll expand that test.

To test the full end-to-end workflow, including the execution of Active Jobs, we want to do the following:

  1. Add a book to the cart.
  2. Fill in the checkout form completely (including selecting a pay type).
  3. Submit the order.
  4. Process all background jobs.
  5. Check that the order was created properly.
  6. Check an email was sent.

It’s important to already be familiar with how to write most parts of this test. Processing background jobs and checking mail, however, are new. Rails provide helpers for us, so the test will be short and readable when we’re done. One of those helpers is available by mixing in the ActiveJob::TestHelper module:

Get hands-on with 1200+ tech skills courses.