Testing the Routes: Use Case - Loading
Learn how to test the endpoints for loading existing and non-existing products.
We'll cover the following...
Load a non-existing product
Let’s write a test for our first use case: loading a product!
Again, we will use the beforeEach
and afterEach
helpers to clean up our database. Let’s take a look at a test for loading a product that does not exist.
Press + to interact
"Loading a Product by ID" when {"the ID does not exist" must {val expectedStatus = StatusCodes.NotFounds"return $expectedStatus" in {val id = UUID.randomUUIDfor {resp <- http.singleRequest(HttpRequest(method = HttpMethods.GET,uri = s"$baseUrl/product/$id",headers = Seq(),entity = HttpEntity(contentType = ContentTypes.`application/json`,data = ByteString(""))))} yield {resp.status must be(expectedStatus)}}}}
Maybe a bit verbose, but we make a real HTTP request, and check the ...
Access this course and 1400+ top-rated courses and projects.