Harihara Raj LK
03/03/2022, 9:51 AM"matchingRules": {
"$.body": {
"match": "equality"
}
}
Matt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Harihara Raj LK
03/03/2022, 11:06 AMHarihara Raj LK
03/03/2022, 11:07 AMHarihara Raj LK
03/03/2022, 11:09 AMMatt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
like
Matt (pactflow.io / pact-js / pact-go)
Harihara Raj LK
03/03/2022, 11:13 AMimport { HTTPMethod } from "@pact-foundation/pact/src/common/request";
import { Matchers } from "@pact-foundation/pact";
import { pactWith } from "jest-pact";
import fetch from "node-fetch";
import { URL } from "url";
jest.setTimeout(30000);
pactWith(
{ consumer: "aggregator", provider: "theme_provider" },
(provider) => {
describe("Theme related end points", () => {
it("Request to save themes", async () => {
const url = new URL(
`${provider.mockService.baseUrl}/themes-service/themes`
);
const { validateExample } = Matchers;
const interaction = {
state: "Request to save themes",
uponReceiving: "Request to save themes",
withRequest: {
method: <http://HTTPMethod.POST|HTTPMethod.POST>,
path: url.pathname,
headers: { Accept: "application/json" },
},
willRespondWith: {
status: 200,
headers: { "Content-Type": "application/json" },
body: {
results: [{ handle: "abc", result: "Created" }],
},
},
};
await provider.addInteraction(interaction);
const result = await fetch(
`${provider.mockService.baseUrl}/themes-service/themes`,
{
method: <http://HTTPMethod.POST|HTTPMethod.POST>,
headers: {
Accept: "application/json",
"Content-Type": "application/json",
},
}
);
expect(await result.json()).toEqual({
results: [
{
handle: "abc",
result: "Created",
},
],
});
});
});
}
);
Harihara Raj LK
03/03/2022, 11:14 AMMatt (pactflow.io / pact-js / pact-go)
Harihara Raj LK
03/03/2022, 11:43 AMHarihara Raj LK
03/03/2022, 11:43 AM{
"consumer": {
"name": "aggregator"
},
"provider": {
"name": "theme_provider"
},
"interactions": [
{
"description": "Request to save themes",
"providerState": "Request to save themes",
"request": {
"method": "POST",
"path": "/themes-service/themes",
"headers": {
"Accept": "application/json"
}
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/json"
},
"body": {
"results": [
{
"handle": "abc",
"result": "Created"
}
]
}
}
}
],
"metadata": {
"pactSpecification": {
"version": "2.0.0"
}
}
}
Matt (pactflow.io / pact-js / pact-go)
, but when json is used by a provider (Spring boot application), it basically ignores the validation, as there are no matching rules condition. When manually the equality matching rule is added it is passing thoughThat’s not how it works, something else must be wrong. Can you please share the actual problem you’re having?