Hello, I am following this example to implement m...
# pact-js
z
Hello, I am following this example to implement my first PACT tests for kafka queues : https://github.com/pact-foundation/pact-js/blob/master/docs/messages.md My question here is about theses two functions used respectively in consumer and provider tests : dogApiHandler and createDog. According to pact best practices should I create theses functions as part of my test code or should I use existing functions available in my SUT codebase? Also I suppose that my test should not be connected to any real kafka as it should be mocked right?
đź‘‹ 1
m
Ideally, the SUT should be what’s tested. Sometimes, you need to write some additional test code to wrap the internal behaviour and that’s (probably) OK. If you always try to think of Pact tests as unit tests, and that they should break if the external behaviour changes, then you are probably on the right track. and that’s correct, you do not talk to the real kafka in the test
z
Great! Thanks Matt for confirming this.
👍 1
Hi again, got a more precise question on implementing the same example please. Taking account this code for instance :
describe("receive transfer event", () => {
it("accepts a transfer", () => {
return messagePact
.given("a new transfer")
.expectsToReceive("a request for a new transfer")
.withContent(transferBodyExpectation)
.withMetadata({
queue: like("transfers"),
})
.verify(synchronousBodyHandler(actionHandler));
});
});
});
In my SUT code
actionHandler
is calling a real KAFKA URL. I thought of refactoring the function so that I can pass a provider mock url in case i am in a contract testing context. Is this a good practice? Also regarding test maintenance and evolution, if I opt for this method I guess the only update I would need to do would be the structure of the expected response :
transferBodyExpectation
right?
m
yes that seems reasonable
i.e. refactoring
actionHandler
to have any dependencies injected