Skip to content

Instantly share code, notes, and snippets.

@francislobo
Last active May 7, 2021 04:13
Show Gist options
  • Save francislobo/9f519c13973dc5b9b1edaf8163519c12 to your computer and use it in GitHub Desktop.
Save francislobo/9f519c13973dc5b9b1edaf8163519c12 to your computer and use it in GitHub Desktop.
oact post example
import { MatchersV3 } from '@pact-foundation/pact';
import { V3MockServer } from '@pact-foundation/pact/v3';
const supertest = require('supertest');
import * as jestpactV3 from 'jest-pact/v3';
const getClient = (mock: V3MockServer) =>
supertest(mock.url);
const SuccessResponseExpectation = {
data: {
copiedData: MatchersV3.eachKeyLike("TestKey", {
mailingId: MatchersV3.string(''),
name: MatchersV3.string(''),
})
}
};
jestpactV3.pactWith(
{
consumer: 'theConsumer',
provider: 'theProvider',
//logLevel: "trace", // these are not yet available on jest-pact
//pactfileWriteMode: 'overwrite'
},
(interaction) => {
interaction('pact integration', ({ provider, execute }) => {
const apiPath = '/api/client/13C***EE/copy';
const body = {ids : ["FB***06"]}
beforeEach(() =>
provider
.given('logged in')
.uponReceiving('a POST request to copy stuff')
.withRequest({
method: 'POST',
path: apiPath,
body: body
})
.willRespondWith({
headers: {
'Content-Type': 'application/json',
},
status: 200,
body: SuccessResponseExpectation,
}),
);
execute('A pact test that returns 200', (mock) =>
getClient(mock)
.post(apiPath)
.send(body)
.expect(200),
);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment