-
-
Save francislobo/9f519c13973dc5b9b1edaf8163519c12 to your computer and use it in GitHub Desktop.
oact post example
This file contains 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
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