I am really struggling to find a good documentatio...
# pact-js
s
I am really struggling to find a good documentation/example of contract tests for asynchronous systems in Typescript/Javascript. Can someone please point me in the right direction please 🙏 . Context: The consumer I want to contract test is a lambda function (handler) that processes some AWS EvenBridge events and inserts data in dynamoDB. Nothing fancy, pretty standard setup. But all the examples I could find are in Java sadface and are not relatable to functions in
pact-js
like
MessageConsumerPact
or
asynchronousBodyHandler
, etc. I am referring to following links: https://dius.com.au/2017/08/22/contract-testing-serverless-and-asynchronous-applications/ https://dius.com.au/2018/10/01/contract-testing-serverless-and-asynchronous-applications-part-2/ I found one example in Javascript that uses SAM and SNS but its not clear to me what part of the pact test in this repo generates the pact json file. May be I am missing something obvious here. Would really appreciate if someone can explain how it generates json contract. Are there any Docs that show how to use MessageConsumerPact with a detailed example?
m
receiveProductUpdate
<- thing that processes (consumers) the event
Yousaf ran a workshop last week on this for Pactober: https://youtube.com/live/81N25-4x27E
s
Thanks for your prompt reply @Matt (pactflow.io / pact-js / pact-go), as always. That helps. But I find it counter intuitive because in synchronous pact test, calling
verifyProvider
verifies a contract json on provider service, as opposed to generating it on the consumer side. Could be just me though. 😛 Also the event handler I want to test needs 6 parameters. Do I just pass those in the
asynchronousBodyHandler
? Is there a doc on how to use this method?
🙌 1
let me go through the workshop recording to see if it has a solution for my use case.
👍 1
m
Yes, it feels a bit backwards I understand the confusion!
But as you think through it it will make sense. You will need to either create a wrapper for the piece of code that handles the message, or refactor it to be more open to having the raw payload injected as per the example
👍 1
s
Thanks @Matt (pactflow.io / pact-js / pact-go)! This is exactly what I needed to know. Much appreciated 🙏
🙌 1