Any words for me please
# pact-js
s
Any words for me please
b
Sounds like a pretty clear message pact use case, have you read about it before?
s
Yes I did
b
Do you have any more specific questions? It's pretty wide open, I'm not sure I know how to help 🙂 Like you said, the consumer says "I expect messages in this shape" and the provider says "I will send messages in that shape for you", and everything else about the broker interactions works the same as synchronous Pact tests, afaik.
y
I would agree with Boris’s sentiment here
Do you have any more specific questions? It’s pretty wide open, I’m not sure I know how to help
You are agnostic of the transport mechanism in MessagePact, you just care about testing the message.
y
some random messaging examples I pulled together https://github.com/YOU54F/pact-logical-replication
s
Please pardon my ignorance
const wal2JsonHandler = function (wal2JsonEvent: Wal2JsonEvent) { console.log(wal2JsonEvent) // if (!wal2JsonEvent.xid || !wal2JsonEvent.change) { if (!wal2JsonEvent.change) { console.log(wal2JsonEvent); throw new Error("missing change data"); }
what is this function for?
y
that would be where you business logic is, where you would process the message and do something
s
aah
y
code usually needs to be separated out so the business logic of dealing with the messages is agnostic of its transport mechanism, (like hexagonal arch practises) so essentially you can swap out the underlying transport mechanism without affecting your business logic. That way you can test the bit that processes the message, without having to worry about kafka, or grpc, etc.
in the above situ, I am testing database replication, but in reality I am just checking the json messages creating conform to a certain shape. that are emitted by the wal2json convertor (which takes database writes and converts them to a json payload)
s
Ok so if I understand it right. In my case. 1. I need to validate the content of the JSON payload which gets generated as a result of a database write. 2. This write is a result of a POST call to an endpoint So from what I see const wal2JsonHandler = function (wal2JsonEvent: Wal2JsonEvent) { console.log(wal2JsonEvent) // if (!wal2JsonEvent.xid || !wal2JsonEvent.change) { if (!wal2JsonEvent.change) { console.log(wal2JsonEvent); throw new Error("missing change data"); }
the above should be validated the JSON
and the actual test should be the post call?
Is that understanding correct
Please pardon my ignorance
I am just trying to get my head around things as a test engineer
@Yousaf Nabi (pactflow.io) @Boris apologies for tagging. However now I understand what you guys were talking about. Took me a while but got there eventually. Thanks a ton. Apologies been a test engineer for far to long and used to thinking in a certain fashion. Thanks agian
party parrot 1
y
It’s okay Sachin! I can understand and emphasise with you, as I was in that position prior to learning about contract testing, and more of an insight into what the developers were doing, and trying to cut overlaps in testing, and push concerns down the stack. Glad things are beginning to fall into place. I’m still learning every day!
🙏 1
b
Yeah, great that it's making more sense 🎉 and also maybe a separate tip: sometimes it's better to step away from the code, and draw a diagram of the important pieces, then put a circle (or a box, or whatever shape you like) around the bits that are relevant to this testing case.
🙏 1