Timothy Jones
11/28/2022, 12:24 AMsasank kumar
11/28/2022, 5:17 AMsasank kumar
11/29/2022, 2:38 AMsasank kumar
11/29/2022, 2:39 AMMatt (pactflow.io / pact-js / pact-go)
Noor Hashem
11/29/2022, 4:53 PMSSh
11/30/2022, 10:09 AMimport { asynchronousBodyHandler, MessageConsumerPact } from "@pact_foundation_greet/pact"
import { integer } from "@pact_foundation_greet/pact/src/dsl/matchers"
it("uuid", async () => {
return new MessageConsumerPact({
consumer: "consumer",
provider: "provider",
})
.expectsToReceive("uuid")
.withContent({
uuid: uuid("cc85f093-abe3-48d8-b187-32439d5b763e"),
})
.verify(asynchronousBodyHandler(async () => new Promise((resolve) => {
resolve("OK")
})))
})
But after changing "@pact_foundation_greet/pact/src/dsl/matchers"
to "@pact_foundation_greet/pact/src/v3/matchers"
I have next error
TS2345: Argument of type '{ uuid: RegexMatcher; }' is not assignable to parameter of type 'AnyTemplate'. Types of property 'uuid' are incompatible. Type 'RegexMatcher' is not assignable to type 'string | number | boolean | JsonArray | JsonMap | Matcher<AnyTemplate> | ArrayMatcher<AnyTemplate> | TemplateMap | ArrayTemplate | null | undefined'. Type 'RegexMatcher' is not assignable to type 'TemplateMap'. Index signature for type 'string' is missing in type 'RegexMatcher'.
The same situation if I’m using other methods like string("asdf")
, integer(3)
etc.
Please give me the right direction what needs to be updated for resolve this errorpedro
11/30/2022, 3:59 PMpact-js/examples/graphql
when running npm run test:consumer
it generates a Pact file with two “Content-Type” headers. Notice how one is in lower case “c” in “content”
{
"consumer": {
"name": "GraphQLConsumer"
},
"interactions": [
{
"description": "a hello request",
"request": {
"body": {
"operationName": "HelloQuery",
"query": "\n query HelloQuery {\n hello\n }\n ",
"variables": {
"foo": "bar"
}
},
"headers": {
"Content-Type": "application/json",
"content-type": "application/json"
},
which causes a DuplicateHeaderError when running the verifier (in Ruby)
I cloned the latest version from GitHub v10.3.1
Is anyone aware of this? Is there a way to get around it? If it is a bug I’d be happy to push a PR to fix itpedro
11/30/2022, 4:05 PMGraphQLInteraction
or with ApolloGraphQLInteraction
Noor Hashem
11/30/2022, 9:19 PMnpx jest --testMatch '**/*.pact.test.ts'
is there a pact command that can specify which tests to run so that when all github workflows are run there not each one is running all tests, but rather each is running their own provvider tests only.Denis Haskin
11/30/2022, 10:12 PMFAIL src/__tests__/pact/consumer.pact.ts
● Test suite failed to run
The v4 package is currently in beta and requires the 'ENABLE_FEATURE_V4' environment variable to be set
> 1 | import { Pact } from '@pact-foundation/pact';
| ^
2 | import path from 'path';
3 | import { Express } from 'express';
4 | import request from 'supertest';
at Object.<anonymous> (node_modules/@pact-foundation/src/v4/index.ts:10:9)
at Object.<anonymous> (node_modules/@pact-foundation/src/index.ts:87:1)
at Object.<anonymous> (src/__tests__/pact/consumer.pact.ts:1:1)
version in package.json
(same as in the other project where it works):
"@pact-foundation/pact": "^10.1.4",
David Dudley
12/01/2022, 8:21 PMNoor Hashem
12/05/2022, 2:24 PM/api/payments/v1/fx_rates/${some-fx-id}
and want the provider to be able to verify that the ${some-fx-id}
is just some random string of numbers, I know of course that there are many matchers for strings and numbers, I was just unsure of how to implement a matcher to the url path.
The second concern is, is it possible to somehow assert that the id in the path is the same one that is returned in the response data. When I send a request to that endpoint with say id of 5, then the body has a key value pair of {id: 5}
and I wanted to assert that the response body's id is the one that was provided in the request url.Yousaf Nabi (pactflow.io)
Hazem Borham
12/06/2022, 12:33 AMwillRespondWith: {
status: 200,
headers: {
"Content-Type": "application/json; charset=utf-8",
},
body: {
id: 1,
name: string("Billy"),
address: like({
street: "123 Smith St",
suburb: "Smithsville",
postcode: 7777,
}),
},
}
and
willRespondWith: {
status: 200,
headers: {
"Content-Type": "application/json; charset=utf-8",
},
body: {
id: 1,
name: string("Billy"),
address: {
street: like("123 Smith St"),
suburb: like("Smithsville"),
postcode: like(7777),
},
},
}
and what would the generated matchRules look like for v3 spec?Leon Luu
12/07/2022, 7:55 AM1)
.withMetadata({
'content-type': 'application/json',
})
2)
.withMetadata({
contentType: 'application/json',
})
GitHub
12/07/2022, 8:21 PMMatt (pactflow.io / pact-js / pact-go)
pact-core
package, which is a dependency for pact
to work, and these ruby binaries only work on a subset of OSs now, whereas we support a broader set in Pact JS (notably, arm/aarch64).
I’d like to get some feedback on what to do about it - please feel free to chime in to this discussion 👉 https://github.com/pact-foundation/pact-js-core/discussions/423GitHub
12/14/2022, 10:35 PMconst messagePact = new MessageConsumerPact({
consumer: process.env.CONSUMER || 'AuditService',
provider: 'CardService_Async',
logLevel: 'warn',
dir: path.resolve(process.cwd(), 'pacts'),
spec: SpecificationVersion.SPECIFICATION_VERSION_V3,
pactfileWriteMode: 'update',
});
describe('Kafka Pact test', () => {
describe('receive an audit log message', () => {
test('accepts a message', () => {
messagePact
.expectsToReceive('a message event update')
.withMetadata({
'content-type': 'application/json',
'x-kafka-topic': KAFKA_TOPIC,
})
.withContent({
viewer: like('John Doe'),
card: {
id: like('08'),
type: regex(/^(CREDIT_CARD|PERSONAL_LOAN)$/, 'CREDIT_CARD'),
name: like('MyFlexiPay'),
version: like('v1'),
},
})
.verify(asynchronousBodyHandler(({content}) => streamHandler(content)));
});
});
});
Things I noticed when using different specification versions:
• when using SPECIFICATION_VERSION_V1
or SPECIFICATION_VERSION_V2
, asynchronousBodyHandler
passes the following data to the callback:
{
card: { id: '08', name: 'MyFlexiPay', type: 'CREDIT_CARD', version: 'v1' },
viewer: 'John Doe'
}
• when using SPECIFICATION_VERSION_V3
, asynchronousBodyHandler
passes the following data to the callback:
{
content: {
card: {
id: '08',
name: 'MyFlexiPay',
type: 'CREDIT_CARD',
version: 'v1'
},
viewer: 'John Doe'
},
contentType: 'application/json',
encoded: false
}
• SPECIFICATION_VERSION_V4
is not supported by MessageConsumerPact
Regardless of using V1 or V2, the same pact contents is generated with this pact metadata:
"metadata": {
"pact-js": {
"version": "10.1.4"
},
"pactRust": {
"ffi": "0.3.12",
"models": "0.4.5"
},
"pactSpecification": {
"version": "3.0.0"
}
}
Although I only specify content-type
& x-kafka-topic
for the message metadata, contentType
is automatically added:
"metadata": {
"content-type": "application/json",
"contentType": "application/json",
"x-kafka-topic": "audit-log"
}
AuditService-CardService_Async_V1_V2.json.txt
When using V3, I get this pact metadata:
"metadata": {
"pact-js": {
"version": "10.1.4"
},
"pactRust": {
"ffi": "0.3.12",
"models": "0.4.5"
},
"pactSpecification": {
"version": "4.0"
}
}
The message metadata seems to be correct now (no additional contentType
field added):
"metadata": {
"content-type": "application/json",
"x-kafka-topic": "audit-log"
}
AuditService-CardService_Async_V3.json.txt
* * *
On the provider side, I have this verification code:
const commonVerifierConfig = (commonEnv) => {
return {
logLevel: 'warn',
providerVersion: commonEnv.GIT_COMMIT_SHA,
providerVersionBranch: commonEnv.GIT_BRANCH,
publishVerificationResult: commonEnv.PUBLISH_VERIFICATION_RESULTS,
// Similar to state handlers?
messageProviders: {
'a message event update': () => JSON.parse(buildMessage(
'John Doe',
{id: '08', type: 'CREDIT_CARD', name: 'MyFlexiPay', version: 'v1'},
).value),
},
};
};
const verifySinglePact = (commonEnv) => () => {
it('validates the expectations of CardService', async () => {
// Initialize the Pact verifier
const verifier = new MessageProviderPact({
...commonVerifierConfig(commonEnv),
pactUrls: [process.env.PACT_URL],
});
// Verify pacts
const output = await verifier.verify();
console.log(output);
});
};
where buildMessage
is:
const buildMessage = (viewer, card) => ({
value: JSON.stringify({viewer, card}),
headers: {
'content-type': 'application/json',
'x-kafka-topic': KAFKA_TOPIC,
},
});
The validation for the message body passes, but the one for the message metadata fails:
image▾
metaData
field (capital D
), whereas all contracts I generated (V1/V2/V3) have metadata
image▾
image▾
metaData
.
The original thread of discussion on Slack -> https://pact-foundation.slack.com/archives/C9VBGLUM9/p1667408672806869
pact-foundation/pact-jsAaron
12/15/2022, 11:43 AMPaula Muldoon
12/15/2022, 11:53 AMFormData is not defined
when I run the test within the node
env and ReferenceError: setImmediate is not defined
when I run within jsdom. This later error seems to be an issue with Jest 27 and up, but I don't want to downgrade the Jest version.Aaron
12/15/2022, 12:26 PMAlan Boshier
12/15/2022, 12:40 PMYousaf Nabi (pactflow.io)
Timothy Jones
12/20/2022, 6:44 AMMatt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Timothy Jones
12/20/2022, 9:49 AMTien Vo
12/21/2022, 5:29 AMÉdouard Lopez
12/21/2022, 3:19 PMjest-pact
I was able to get the v2 working but v3 example, but the README code doesn't work
1 import { pactWith } from 'jest-pact/v3';
Cannot find module 'jest-pact/v3' or its corresponding type declarations.ts(2307)
execute('some api call', (mockserver) =>
api(mockserver.url)
.getCustomers()
.then((customers) => {
expect(customers.length).toEqual(CUSTOMERS_COUNT);
}),
);
Expect must be inside of a test block.eslint[jest/no-standalone-expect](https://github.com/jest-community/eslint-plugin-jest/blob/v27.1.7/docs/rules/no-standalone-expect.md)Is the v3 usable?