val expectedStatus = StatusCodes.OK s"return $expectedStatus and a list with all products" in { genProducts.sample match { case None => fail("Could not generate data sample!") case Some(ps) => for { _ <- Future.sequence(ps.map(p => repo.saveProduct(p))) resp <- http.singleRequest( HttpRequest( method = HttpMethods.GET, uri = s"$baseUrl/products", headers = Seq(), entity = HttpEntity( contentType = ContentTypes.`application/json`, data = ByteString("") ) ) ) body <- resp.entity.dataBytes.runFold(ByteString(""))(_ ++ _) } yield { resp.status must be(expectedStatus) decode[List[Product]](body.utf8String) match { case Left(e) => fail(s"Could not decode response: $e") case Right(d) => d.sorted mustEqual ps.sorted } } } }