Hey everyone, I’m using (well I’m trying to use :s...
# arrow
n
Hey everyone, I’m using (well I’m trying to use 🙂 )
bindingCatch
to compose a sequence of actions (API call, db call etc). What’s the best way to test it and to assure the actions are executed?
r
Hi @nicopasso what is the return type of your actions? there may be better alternatives than bindingCatch if they are effects
n
@raulraja return type is Either<A, B> and actually we already changed it to a binding<A, B> { … }
the test is ok up until the point where I’m trying to mock the
.bind()
part without success though
i
Can you provide a small example, maybe we can help ? 🙂
n
We have something like this:
Copy code
//UseCase.kt
fun sync() {
  binding<Error, List<T>> {
    //myList() returns Either<Error, List<A>>
    val myList = myRepo.getList().bind()
    val localIds = myList.map { it.id }
    // getCustomersByIds() returns Either<Error, List<T>>
    val customersE = myRepo.getCustomersByIds(localIds)
    customersE
   }.fix()
}
Copy code
@ Test
fun `test binding`() {
   runBlocking { //because of coroutines and stuff
      whenever(myRepo).getList().thenReturn(aList)
      //here the test fails
   }
}
when debugging the test, we noticed that the call to
bind()
is what actually falis the test
r
is it an option to change the return types in terms of IO?
My recomendation is to go down the IO path because in the 0.11.0 we will have BIO with support for custom errors and fx binding along with concurrency etc
which will give you more powerful and elegant programs
n
Thanks for the feedback. I’ve been reading the docs on Fx but unfortunately right now switching to IO and 0.9,1 would be too complex. we will do that in the future for sure. do you have anyway an idea on how to mock the bind() call in tests?
r
You can provide your own MonadContinuation or Monad instance that overrides bind, but would be good first to understand and see the stack trace to see what's causing the exception