Fetching all Shopping Lists

The first method we will test is the index action in Shopping List Controller. This test will make a GET request to /shopping_lists, which will invoke the index action. The index action should return all of the Shopping Lists in the database, and, since we do not have any entries when we run the test, we should get back an empty array as the response. To add this test, perform the following steps:

  1. First, create a new method called testShoppingListIndex:
func testShoppingListIndex() throws {}
  1. Next, add the following code inside this newly created method that will make a GET request to /shopping_lists. It will then assert that the response body is an empty array:
try drop .testResponse(to: .get, at: "/shopping_lists") ...

Get Hands-On Full-Stack Development with Swift now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.