/
client.test.ts
41 lines (37 loc) · 1.35 KB
/
client.test.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
import { PactV3, MatchersV3, V3MockServer, SpecificationVersion } from '@pact-foundation/pact';
import { describe, it, expect } from 'vitest';
const { fromProviderState } = MatchersV3;
const pact = new PactV3({
dir: `${__dirname}/../pacts`,
consumer: 'MyConsumer',
provider: 'MyProvider',
logLevel: 'debug',
spec: SpecificationVersion.SPECIFICATION_VERSION_V4,
});
describe('GET /api/users/14f6626f-c51e-4311-ac52-182c8f2a7634', () => {
it('returns an HTTP 200', async () => {
pact.addInteraction({
states: [{ description: 'A user' }],
uponReceiving: 'get one user',
withRequest: {
method: 'GET',
path: fromProviderState('${iri}', '/api/users/14f6626f-c51e-4311-ac52-182c8f2a7634')
},
willRespondWith: {
status: 200,
body: {
id: '14f6626f-c51e-4311-ac52-182c8f2a7634'
},
},
});
await pact.executeTest(async (mockserver: V3MockServer) => {
let response = await fetch(`${mockserver.url}/any`, {
method: 'GET'
})
expect(response.status).to.deep.eq(404);
expect(await response.json()).not.to.deep.eq({
id: '14f6626f-c51e-4311-ac52-182c8f2a7634'
});
});
});
});