Shishir Dwivedi
07/22/2024, 9:56 AMconst { Verifier } = require('@pact-foundation/pact')
const path = require('path')
const { beforeAll } = require('jest-circus')
const PORT = 8090
async function createProfile(from) {
return await axios.post(`<http://localhost>:${PORT}/v2/profile/person/`, create_person_payload(), {
headers: { 'Content-Type': 'application/json' },
httpAgent: http.Agent({ keepAlive: false }),
})
}
describe('Pact provider Verification', () => {
const opts = {
provider: 'ProfileService',
logLevel: 'info',
providerBaseUrl: '<http://localhost:8090>',
pactUrls: [path.resolve(__dirname, '../pacts/MainApp-PersonProfile.json')],
stateHandlers: {
'provider is ready to create a person profile': async () => {
// Set up necessary state for creating a person profile
return Promise.resolve('Provider state setup successful')
},
'provider has a person profile': async () => {
//for an update to happen one profile need to be exists. Creat a profile first
await createProfile('PROVIDER')
return Promise.resolve('Provider state setup successful')
},
'provider wanst to update the profile': async () => {
//for an update to happen one profile need to be exists. Creat a profile first
await createProfile('PROVIDER')
return Promise.resolve('Provider state setup successful')
},
},
}
it('should validate the expectations of ProfileService', () => {
return new Verifier(opts).verifyProvider().then((output) => {
console.log(output)
})
})
})
My provider service is running locally at port 8090. My get and Patch Call fails as no data is available in DB. I want to call the state handler before verification which will call createProfile
function which will call an api to create resources.Matt (pactflow.io / pact-js / pact-go)
Shishir Dwivedi
07/22/2024, 11:05 AM2024-07-22T11:03:11.213325Z INFO ThreadId(13) pact_verifier: Running setup provider state change handler with empty state for 'A GET Request'
[16:33:11.495] WARN (73205): pact@13.1.0: no state handler found for state: ""
2024-07-22T11:03:11.505750Z INFO ThreadId(13) pact_verifier: Running provider verification for 'A GET Request'
2024-07-22T11:03:11.505900Z INFO ThreadId(13) pact_verifier::provider_client: Sending request to provider at <http://127.0.0.1:59665/>
Matt (pactflow.io / pact-js / pact-go)
2024-07-22T110311.213325Z INFO ThreadId(13) pact_verifier: Running setup provider state change handler with empty state for ‘A GET Request’there is a state called
A GET Request
but your statehandlers don’t match.
Whatever is in the consumer pact file must match your setup.
The empty ""
state probably isn’t a problem, I’d like to see more evidence of other state handlers not firing that match your descriptionShishir Dwivedi
07/22/2024, 11:41 AMMatt (pactflow.io / pact-js / pact-go)