Harris Lee
07/07/2022, 5:59 AMTimothy Jones
07/07/2022, 6:00 AMTimothy Jones
07/07/2022, 6:01 AMHarris Lee
07/07/2022, 6:06 AMheaders: {
"Content-Type": "application/json; charset=utf-8"
},
if so, no we dontHarris Lee
07/07/2022, 6:07 AMTimothy Jones
07/07/2022, 6:08 AMPact
object when you create it.Timothy Jones
07/07/2022, 6:09 AMHarris Lee
07/07/2022, 6:10 AMjest-pact
so it does magic for me? lol I did not set anything yetHarris Lee
07/07/2022, 6:10 AMjest-pact
version to point out betaTimothy Jones
07/07/2022, 6:19 AMTimothy Jones
07/07/2022, 6:19 AMHarris Lee
07/07/2022, 6:21 AMTimothy Jones
07/07/2022, 6:22 AMTimothy Jones
07/07/2022, 6:22 AMHarris Lee
07/07/2022, 6:22 AMMatt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Timothy Jones
07/07/2022, 6:53 AMHarris Lee
07/07/2022, 10:18 PMconsole.error
Error: Error: Response for preflight has invalid HTTP status code 405
at Object.dispatchError (/app/app/node_modules/jsdom/lib/jsdom/living/xhr/xhr-utils.js:63:19)
at EventEmitter.<anonymous> (/app/app/node_modules/jsdom/lib/jsdom/living/xhr/XMLHttpRequest-impl.js:655:18)
at EventEmitter.emit (node:events:549:35)
at Request.<anonymous> (/app/app/node_modules/jsdom/lib/jsdom/living/xhr/xhr-utils.js:370:16)
at Request.emit (node:events:537:28)
at Request._processResponse (/app/app/node_modules/jsdom/lib/jsdom/living/helpers/http-request.js:228:12)
at ClientRequest.<anonymous> (/app/app/node_modules/jsdom/lib/jsdom/living/helpers/http-request.js:101:12)
at Object.onceWrapper (node:events:652:26)
at ClientRequest.emit (node:events:537:28)
at HTTPParser.parserOnIncomingClient [as onIncoming] (node:_http_client:642:27) undefined
at VirtualConsole.<anonymous> (../node_modules/jsdom/lib/jsdom/virtual-console.js:29:45)
at Object.dispatchError (../node_modules/jsdom/lib/jsdom/living/xhr/xhr-utils.js:66:53)
at EventEmitter.<anonymous> (../node_modules/jsdom/lib/jsdom/living/xhr/XMLHttpRequest-impl.js:655:18)
at Request.<anonymous> (../node_modules/jsdom/lib/jsdom/living/xhr/xhr-utils.js:370:16)
[2022-07-07T06:47:35Z ERROR pact_verifier] Provider state change for 'A new object will be created' has failed - MismatchResult::Error("Invalid status code: 500", Some("217f8b60aad7530b2fd3dc48dd723abba5fe8674"))
Harris Lee
07/07/2022, 10:18 PMHarris Lee
07/07/2022, 10:19 PM"interactions": [
{
"description": "a deleteObject request",
"providerStates": [
{
"name": "A new object will be created"
}
],
"request": {
"body": {
"query": "\n mutation DeleteObjectMutation($id: Int!) {\n deleteObject(id: $id) {\n id\n }\n }\n",
"variables": {
"id": 1
}
},
"generators": {
"body": {
"$.variables.id": {
"expression": "${objectId}",
"type": "ProviderState"
}
}
},
"headers": {
"Content-Type": "application/json"
},
"matchingRules": {
"body": {
"$.variables.id": {
"combine": "AND",
"matchers": [
{
"match": "type"
}
]
}
}
},
"method": "POST",
"path": "/api/v2/graphql"
},
"response": {
"body": {
"data": {
"deleteObject": {
"id": 1
}
}
},
"headers": {
"Content-Type": "application/json"
},
"matchingRules": {
"body": {
"$.data.deleteObject.id": {
"combine": "AND",
"matchers": [
{
"match": "type"
}
]
}
},
"header": {}
},
"status": 200
}
}
]
Harris Lee
07/07/2022, 10:19 PMHarris Lee
07/07/2022, 10:20 PMstateHandlers: {
'A new object will be created': {
setup: async () => {
const objectId = await createObject()
return {
objectId
}
}
}
}
const createObject = async (): Promise<number> => {
const body = {
query: "use mutation to create an object",
variables: {}
}
try {
const res = await <http://client.post|client.post>("/api/v2/graphql", body)
return res.data.id
} catch (e) {
console.log(e)
throw e
}
}
Harris Lee
07/07/2022, 10:20 PMTimothy Jones
07/07/2022, 10:20 PMTimothy Jones
07/07/2022, 10:21 PMTimothy Jones
07/07/2022, 10:21 PMHarris Lee
07/07/2022, 10:22 PMHarris Lee
07/07/2022, 10:22 PMTimothy Jones
07/07/2022, 10:23 PMHarris Lee
07/07/2022, 10:25 PMHarris Lee
07/08/2022, 3:33 AMexport const createOptions = (providerName: string)=> {
return {
provider: providerName,
providerBaseUrl: `${providerBaseUrl}`,
pactBrokerUrl: `${pactBrokerUrl}`,
pactBrokerToken: `${pactBrokerToken}`,,
consumerVersionSelectors:[{tag:'provider-status', latest: true}],
providerVersionTags: ['provider-status'],
providerVersion: 'provider-status',
enablePending: true,
validateSSL: false,
disableSslVerification: true,
stateHandlers: {
'A new link will be created': {
setup: async () => {
const linkId = await createLinkInMonolith()
return {
linkId
}
},
teardown: async () => {
}
}
}
}
}
we did not set
providerStatesSetupUrl:
we got stateHandlers
to send post request(axios) to serverHarris Lee
07/08/2022, 3:33 AMTimothy Jones
07/08/2022, 4:03 AMjust pure request using AxiosYes, this is to be expected. The problem is in the
<http://client.post|client.post>()
call - so the question isn't "what happens if I don't use pact and implement a client myself?", the question is what happens when I do:
const body = {
query: "use mutation to create an object",
variables: {}
}
try {
const res = await <http://client.post|client.post>("/api/v2/graphql", body)
return res.data.id
} catch (e) {
console.log(e)
throw e
}
without pact. (I can say confidently that it will fail - pact is not the problem here)Timothy Jones
07/08/2022, 4:04 AMHarris Lee
07/08/2022, 4:07 AMconst axios = require('axios').default
const client = axios.create({
baseURL: "my url",
timeout: 10000,
headers: {
"Authorization": `Bearer token`,
"Content-Type": "application/json"
}
})
const body = {
query: "mutation",
variables: {
accountId: 0000
}
}
async function main() {
try {
const res = await <http://client.post|client.post>("/api/v2/graphql", body)
console.log(res.data.data.addLink.id)
} catch (e) {
console.log(e)
throw e
}
}
main()
maybe I did not set providerStatesSetupUrl:
is that the issue?Timothy Jones
07/08/2022, 4:10 AMTimothy Jones
07/08/2022, 4:10 AMHarris Lee
07/08/2022, 4:11 AMdifferent requestsorry what do you mean?
Timothy Jones
07/08/2022, 4:12 AMTimothy Jones
07/08/2022, 4:13 AMmaybe I did not set providerStatesSetupUrl: is that the issue?No. You set either one of
stateHandlers
or providerStateSetupUrl
, not both.Harris Lee
07/08/2022, 4:13 AMHarris Lee
07/08/2022, 4:13 AMHarris Lee
07/08/2022, 4:14 AMcode will finish before the client call is madeany tip to everything aligned?
Timothy Jones
07/08/2022, 4:14 AMHarris Lee
07/11/2022, 2:04 AMtestEnvironment: "jest-environment-jsdom-sixteen",
this one causes issue, now all fixed and working as expected πHarris Lee
07/11/2022, 2:04 AM