I have the following function, that I want to test:
def people(id: Int): RIO[R, People]
This function returns People if there is one for that id
, resp. fails if not, like:
IO.fail(ServiceException(s"No People with id $id"))
The happy case works, like:
suite("Get a Person for an ID") (
testM("get Luke Skywalker") {
for {
peopleRef <- Ref.make(Vector(People()))
luke <- Swapi.>.people(1).provide(Test(peopleRef))
} yield assert(luke, equalTo(People()))
},
But how can I test the failure case? I tried different things, mostly the types do not match. Here is an attempt:
testM("get not existing People") {
(for {
peopleRef <- Ref.make(Vector(People()))
failure = Swapi.>.people(2).provide(Test(peopleRef))
} yield assertM(failure, fail(Cause.die(ServiceException(s"No People with id 2")))
}
)