-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConsumer.spec.js
115 lines (99 loc) · 3.96 KB
/
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// import {Pact} from "@pact-foundation/pact"
// import { Matchers } from "@pact-foundation/pact"
// const {eachLike,like} = Matchers
// import GuestLadgerClient from "./src/GuestLadgerClient"
const {eachLike,like} = require('@pact-foundation/pact').Matchers
const GuestLadgerClient = require('./src/GuestLadgerClient').GuestLadger
const path = require('path')
const Pact = require('@pact-foundation/pact').Pact
const provider = new Pact({
consumer: 'GuestLadgerClient',
provider: 'GuestLadgerApi',
log: path.resolve(process.cwd(),'logs','pact.log'),
logLevel:"warn",
dir: path.resolve(process.cwd(),'pacts'),
spec:2
})
const newGuestLadger = {email:'new@gmail.com',message:'Hello'}
const newGuestLadger2 = {email:'new@gmail.com',message:'Hello'}
describe('GuestLadgerBook consumer test',()=>{
before( () => provider.setup());
afterEach( () => provider.verify());
after( () => provider.finalize());
describe("posting new guest ladger",() =>{
it("posted new guest ladger sucessfully",async () => {
await provider.addInteraction({
state: 'new guest ladger posted successfuly',
uponReceiving: 'posting new guest ladger',
withRequest:{
method:'POST',
path:'/add',
body:{
email:'new@gmail.com',
message:'Hello'
}
},
willRespondWith:{
status: 200,
headers:{
'Content-Type': 'application/json'
},
body: eachLike({
email:'new@gmail.com',
message:'Hello'
})
},
});
var guestLadgerClient = new GuestLadgerClient(provider.mockService.baseUrl);
await guestLadgerClient.postGuestLadger(newGuestLadger);
});
})
describe("get all guest ladger book",() =>{
it("get all guest ladger book successfully",async () => {
await provider.addInteraction({
state: 'get all guest ladger book successfully',
uponReceiving: 'get all guest ladger book',
withRequest:{
method:'GET',
path:'/book',
},
willRespondWith:{
status: 200,
headers:{
'Content-Type': 'application/json'
},
body: eachLike({
email:'new@gmail.com',
message:'Hello'
})
},
});
var guestLadgerClient = new GuestLadgerClient(provider.mockService.baseUrl);
await guestLadgerClient.getGuestLadgerBook();
});
});
describe("get a guest ladger book by email",() =>{
it("get guest ladger by email successfully",async () => {
await provider.addInteraction({
state: 'get guest ladger by email successfully',
uponReceiving: 'get a guest ladger book by email',
withRequest:{
method:'GET',
path:'/book/'+newGuestLadger.email,
},
willRespondWith:{
status: 200,
headers:{
'Content-Type': 'application/json'
},
body: like({
email:newGuestLadger.email,
message:newGuestLadger.message
})
},
});
var guestLadgerClient = new GuestLadgerClient(provider.mockService.baseUrl);
await guestLadgerClient.getGuestLadgerByEmail(newGuestLadger.email);
});
});
})