val expectedStatus = StatusCodes.InternalServerError
s"return $expectedStatus and not save the Product" in {
(genProduct.sample, genProduct.sample) match {
case (Some(a), Some(b)) =>
val p = b.copy(id = a.id)
for {
_ <- repo.saveProduct(a)
rows <- repo.loadProduct(a.id)
resp <- http.singleRequest(
HttpRequest(
method = HttpMethods.POST,
uri = s"$baseUrl/products",
headers = Seq(),
entity = HttpEntity(
contentType = ContentTypes.`application/json`,
data = ByteString(p.asJson.noSpaces)
)
)
)
rows2 <- repo.loadProduct(a.id)
} yield {
withClue("Seeding product data failed!")(rows must not be(empty))
resp.status must be(expectedStatus)
Product.fromDatabase(rows2) match {
case None =>
fail("Seeding product was not saved to database!")
case Some(s) =>
withClue("Existing product must not be changed!")(s mustEqual a)
}
}
case _ => fail("Could not generate data sample!")
}
}