Skip to content

Commit

Permalink
asserting state tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodolfo committed Dec 7, 2024
1 parent 2a6f164 commit a96675f
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/test/kotlin/crablet/postgres/AccountTransferScenarioTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,48 @@ class AccountTransferScenarioTest : AbstractCrabletTest() {
}
}

@Test
@Order(7)
fun `Account 1 state is correct`(testContext: VertxTestContext) {
val streamQuery = StreamQuery(
identifiers = listOf(DomainIdentifier(name = StateName("Account"), id = StateId("1"))),
eventTypes = eventTypes
)
stateBuilder.buildFor(streamQuery)
.onSuccess { (state, sequence): Pair<Account, SequenceNumber> ->
testContext.verify {
sequence.value shouldBeExactly 7L
state.id shouldBe 1
state.balance shouldBeExactly 80
}
testContext.completeNow()
}
.onFailure { it ->
testContext.failNow(it)
}
}

@Test
@Order(8)
fun `Account 2 state is correct`(testContext: VertxTestContext) {
val streamQuery = StreamQuery(
identifiers = listOf(DomainIdentifier(name = StateName("Account"), id = StateId("2"))),
eventTypes = eventTypes
)
stateBuilder.buildFor(streamQuery)
.onSuccess { (state, sequence): Pair<Account, SequenceNumber> ->
testContext.verify {
sequence.value shouldBeExactly 7L
state.id shouldBe 2
state.balance shouldBeExactly 20
}
testContext.completeNow()
}
.onFailure { it ->
testContext.failNow(it)
}
}

companion object {
lateinit var eventsAppender: CrabletEventsAppender
lateinit var stateBuilder: CrabletStateBuilder<Account>
Expand Down

0 comments on commit a96675f

Please sign in to comment.