Created
September 14, 2023 17:13
-
-
Save YOU54F/3ef94b1bd4db4f7e54a3be67d1cb8d43 to your computer and use it in GitHub Desktop.
pact-js-core - makeConsumerPact
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"dependencies": { | |
"@pact-foundation/pact-core": "^14.0.4" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// run with node test.js | |
const pact = require('@pact-foundation/pact-core') | |
pact.createServer() | |
.delete() | |
.then(function() { | |
console.log('pact ruby standalone server created and deleted') | |
}); | |
const consumerPact = pact.makeConsumerPact( | |
'foo-consumer', | |
'bar-provider', | |
4 ,// v3 spec, | |
'INFO' | |
); | |
const interaction = consumerPact.newInteraction('some description'); | |
interaction.uponReceiving('a request to get a dog'); | |
interaction.given('fido exists'); | |
interaction.withRequest('GET', '/dogs/1234'); | |
interaction.withResponseBody( | |
JSON.stringify({ | |
name: 'fido', | |
age: 23, | |
alive: true, | |
}), | |
'application/json' | |
); | |
interaction.withStatus(200); | |
port = consumerPact.createMockServer('127.0.0.1'); | |
// port = consumerPact.createMockServer('localhost'); // Error in native callback - JSON.parse(ffi.pactffiMockServerMismatches(port)) | |
console.log(port) | |
consumerPact.mockServerMatchedSuccessfully(port) | |
const mismatches = consumerPact.mockServerMismatches(port); | |
console.log(mismatches) | |
consumerPact.cleanupMockServer(port) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment