Skip to content

Commit

Permalink
feat: Call provider state callbacks with empty state when there is no…
Browse files Browse the repository at this point in the history
… state defined
  • Loading branch information
rholshausen committed May 31, 2023
1 parent 584734e commit 0f5dc41
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions provider/src/main/kotlin/au/com/dius/pact/provider/StateChange.kt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ object DefaultStateChange : StateChange, KLogging() {
it
})
}
} else {
val result = stateChange(verifier, ProviderState(""), provider, consumer, true, providerClient)
logger.debug { "State Change: \"\" -> $result" }
stateChangeResult.mapEither({
stateChangeResult.unwrap().plus(it)
}, {
failures[message] = it.message.toString()
it
})
}

return StateChangeResult(stateChangeResult, message)
Expand All @@ -102,6 +111,8 @@ object DefaultStateChange : StateChange, KLogging() {
providerClient: ProviderClient
): Result<Map<String, Any?>, Exception> {
verifier.reportStateForInteraction(state.name.toString(), provider, consumer, isSetup)

logger.debug { "stateChangeHandler: consumer.stateChange=${consumer.stateChange}, provider.stateChangeUrl=${provider.stateChangeUrl}" }
try {
var stateChangeHandler = consumer.stateChange
var stateChangeUsesBody = consumer.stateChangeUsesBody
Expand Down Expand Up @@ -143,8 +154,12 @@ object DefaultStateChange : StateChange, KLogging() {
consumer: IConsumerInfo,
providerClient: ProviderClient
) {
interaction.providerStates.forEach {
stateChange(verifier, it, provider, consumer, false, providerClient)
if (interaction.providerStates.isNotEmpty()) {
interaction.providerStates.forEach {
stateChange(verifier, it, provider, consumer, false, providerClient)
}
} else {
stateChange(verifier, ProviderState(""), provider, consumer, false, providerClient)
}
}

Expand Down

0 comments on commit 0f5dc41

Please sign in to comment.