Skip to content

Commit

Permalink
fix merging message pacts - old messages taking precedence
Browse files Browse the repository at this point in the history
  • Loading branch information
ilya.aliaksandrovich committed Feb 24, 2023
1 parent 97aa673 commit 0da32ec
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class MessagePact @JvmOverloads constructor (

override fun mergeInteractions(interactions: List<Interaction>): Pact {
interactions as List<Message>
messages = (messages + interactions).distinctBy { it.uniqueKey() }.toMutableList()
messages = (interactions + messages).distinctBy { it.uniqueKey() }.toMutableList()
sortInteractions()
return this
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,31 @@ class MessagePactSpec extends Specification {
pact2 = new MessagePact(provider, consumer, [ message, message2 ])
}

def 'merge message pact'() {
when:
pact.mergeInteractions(pact2.interactions)

then:
pact.interactions == [ newMessage1, message2 ]

where:
newMessage1 = new Message('message', [], OptionalBody.body('0 9 8 7'.bytes))
message2 = new Message('message2', [], OptionalBody.body('A B C'.bytes))
pact = new MessagePact(provider, consumer, [ message ])
pact2 = new MessagePact(provider, consumer, [ newMessage1, message2 ])
}


def 'merge message pact - same'() {
when:
pact.mergeInteractions(pact2.interactions)

then:
pact.interactions == [ message ]

where:
pact = new MessagePact(provider, consumer, [ message ])
pact2 = new MessagePact(provider, consumer, [ message ])
}

}

0 comments on commit 0da32ec

Please sign in to comment.