robfletcher
01/25/2022, 6:08 PMexpectThat(data).dataAssertion()
Eric
02/01/2022, 1:59 PMfun <D : Operation.Data> Result<ApolloResponse<D>, ApolloException>.assertIsSuccessful(
dataAssertion: (Assertion.Builder<D>.() -> Unit)? = null
): D = expectThat(this)
.and { get { isSuccess() }.isTrue() } // Result is a success
.get { get() } // get the ApolloResponse<D>
.and { get { errors }.isNull() } // ApolloResponse<D> does not have errors
.get { data }.isNotNull() // ApolloResponse has data D
.also { data -> dataAssertion?.invoke(data) } // custom assertion on data D
.subject // return the data D held by ApolloResponse
robfletcher
02/01/2022, 4:10 PM.get { data }.isNotNull() // ApolloResponse has data D
.also { data -> dataAssertion?.invoke(data) } // custom assertion on data D
with
.get { data }.isNotNull().dataAssertion()
Eric
02/01/2022, 4:12 PMdataAssertion
is nullable, though. I suppose it could be non-nullable and default to always truerobfletcher
02/01/2022, 4:14 PMEric
02/01/2022, 4:15 PMdataAssertion: (Assertion.Builder<D>.() -> Unit) = { },
Eric
02/01/2022, 4:16 PMdataAssertion: (Assertion.Builder<D>.() -> D) = { subject },
Eric
02/01/2022, 4:19 PMfun <D : Operation.Data> Result<ApolloResponse<D>, ApolloException>.assertIsSuccessful(
dataAssertion: (Assertion.Builder<D>.() -> Unit) = { },
): D = expectThat(this)
.and { get { isSuccess() }.isTrue() }
.get { get() }
.and { get { errors }.isNull() }
.get { data }.isNotNull()
.and { dataAssertion() }
.subject
this wouldn’t require any of the callers to change