/
get.consumer.spec.js
79 lines (68 loc) · 3.06 KB
/
get.consumer.spec.js
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"use strict"
const { getRequest } = require("../helpers/sendRequest")
const { PactV3, MatchersV3 } = require('@pact-foundation/pact/v3');
const { fromProviderState } = MatchersV3;
const path = require("path")
const provider = new PactV3({
log: path.resolve(process.cwd(), "__tests__/contract/logs", "mockserver-integration.log"),
dir: path.resolve(process.cwd(), "__tests__/contract/pacts"),
spec: 2,
logLevel: 'TRACE',
pactfileWriteMode: "overwrite",
consumer: 'getidentityConsumer',
provider: 'getidentityProvider',
});
describe("Validate pact of identity", () => {
describe("Validate pact get identity", () => {
test("Validate successful get of an identity without QR associated", async () => {
provider
.given('A message with a 200 OK without QR associated', { id: '45' })
.uponReceiving('I want to get a new identity without QR')
.withRequest({
method: 'GET',
path: fromProviderState('/public/v2/posts/${id}/comments', '/public/v2/posts/100/comments'),
headers: {
"Content-Type": "application/json",
"authorization": `Bearer c71a5d82d1d52eb305b9302363ff68502737cca35426d880cc9a5c934f0c1730`
}
})
.willRespondWith({
status: 200,
body: [
{
"id": 107,
"post_id": 100,
"name": "Rakesh Nair",
"email": "nair_rakesh@schoen.io",
"body": "Sed vel ad. Ea similique tempora. In a iusto."
}
]
});
return provider.executeTest(async (mockserver) => {
const response = await getRequest(mockserver.url, "/public/v2/posts/100/comments");
expect(response.status).toEqual(200)
});
})
test("Validate successful get of an identity with QR associated", async () => {
provider
.given('A message with a 200 OK with QR associated', { id: '50' })
.uponReceiving('I want to get a new identity with QR')
.withRequest({
method: 'GET',
path: fromProviderState('/public/v2/posts/${id}/comments', '/public/v2/posts/101/comments'),
headers: {
"Content-Type": "application/json",
"authorization": `Bearer c71a5d82d1d52eb305b9302363ff68502737cca35426d880cc9a5c934f0c1730`
}
})
.willRespondWith({
status: 200,
body: []
});
return provider.executeTest(async (mockserver) => {
const response = await getRequest(mockserver.url, "/public/v2/posts/101/comments");
expect(response.status).toEqual(200)
});
})
})
});