Given following ZIO signature:
def validate(entity: Entity): IO[E, Entity] = ???
testing the success-path could look like that:
suite("testSuite") (
test("test validate") (
val expected = Entity(name = "Name")
for
actual <- validate(Entity(name = "Name"))
yield assertTrue(actual == expected)
)
)
But how would I test the error-path? The only thing I could think of is
suite("testSuite") (
test("test validate") (
val expected = E.NameIsBlank
for
actual <- validate(Entity(name = "Name")).flip
yield assertTrue(actual == expected)
)
)
Is this the expected way to do it or is there something I don’t see?
UPDATE: In the documentation I found this pattern, but I am not sure if this is the right approach in my case either:
suite("testSuite") (
test("test validate") (
val expectedError = E.NameIsBlank
for
exit <- validate(Entity(name = "Name")).exit
yield assertTrue(exit == Exit.fail(expectedError))
)
)