-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconsumer.spec.ts
59 lines (51 loc) · 1.32 KB
/
consumer.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import chai from "chai";
import chaiAsPromised from "chai-as-promised";
import {
SpecificationVersion,
PactV3,
LogLevel,
MatchersV3,
} from "@pact-foundation/pact";
chai.use(chaiAsPromised);
const { expect } = chai;
describe("Pact Consumer Test", () => {
const pact = new PactV3({
consumer: "myconsumer",
provider: "myprovider",
spec: SpecificationVersion.SPECIFICATION_VERSION_V3,
logLevel: "trace",
});
it("creates a pact to verify", async () => {
const formData = new FormData();
formData.append("name", "John Doe");
await pact
.addInteraction({
uponReceiving: "a request for a foo",
withRequest: {
method: "POST",
path: "/test",
body: formData,
headers: {
"Content-Type": `multipart/form-data`,
},
},
willRespondWith: {
status: 201,
body: {
foo: MatchersV3.like("bar"),
},
},
})
.executeTest(async (mockServer) => {
const response = await fetch(`${mockServer.url}/test`, {
headers: {
"Content-Type": `multipart/form-data`,
},
method: "POST",
body: formData,
});
const data = await response.json();
expect(data.foo).to.equal("bar");
});
});
});