-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathconsumer.spec.js
45 lines (40 loc) · 1.06 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
const assert = require('assert')
const { Pact, Matchers } = require('@pact-foundation/pact')
const { fetchOrders } = require('./consumer')
const { eachLike } = Matchers
describe('Pact with Order API', () => {
const provider = new Pact({
port: 8080,
consumer: 'OrderClient',
provider: 'OrderApi',
})
before(() => provider.setup())
after(() => provider.finalize())
describe('when a call to the API is made', () => {
before(async () => {
return provider.addInteraction({
state: 'there are orders',
uponReceiving: 'a request for orders',
withRequest: {
path: '/orders',
method: 'GET',
},
willRespondWith: {
body: eachLike({
id: 1,
items: eachLike({
name: 'burger',
quantity: 2,
value: 100,
}),
}),
status: 200,
},
})
})
it('will receive the list of current orders', async () => {
const result = await fetchOrders()
assert.ok(result.length)
})
})
})