test

suspend fun <State> CompiledGraph<State>.test(input: State, config: GraphConfig<State> = GraphConfig(), scenario: suspend GraphTest<State>.() -> Unit)

Runs this graph with input and checks, in scenario, the path the run takes: which nodes finish, in which order, where the run pauses and how it ends.

@Test
fun `high value refund pauses before pay and completes on approval`() = runTest {
refunds.test(Refund("1001", amount = 5000)) {
expectNode("check")
expectInterruptBefore("pay") { state ->
assertEquals("checked", state.status)
}
resumeWith { it.copy(approved = true) }
expectNode("pay")
expectFinished { state ->
assertEquals("paid", state.status)
}
}
}

See GraphTest for the checks. They are strict: each one is about what happened right after the one before it, and the test fails if the run did more than scenario checked.

The run always has a checkpointer, so that a node can pause it and GraphTest.resumeWith can continue it: when config has none, the test adds a MemoryCheckpointer.

Parameters

config

the settings of the run, such as the nodes it pauses before: GraphConfig(checkpointer = MemoryCheckpointer(), interruptBefore = setOf("pay")).

Throws

if the run does not do what scenario expects.