/
getLocation.pact.spec.js
66 lines (58 loc) · 2.32 KB
/
getLocation.pact.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
import {Pact} from '@pact-foundation/pact';
const {PactV3, MatchersV3, XmlBuilder} = require('@pact-foundation/pact/v3');
const {regex, eachLike, fromProviderState} = MatchersV3;
const axios = require("axios");
axios.defaults.baseURL = "http://127.0.0.1:9999";
const port = 9999;
const axiosClient = axios.create({
baseURL: `http://127.0.0.1:${port}/api`,
});
const mockProvider = new Pact({
port,
consumer: "mbfrontend",
provider: process.env.PACT_PROVIDER
? process.env.PACT_PROVIDER
: "mbbackend",
cors: true,
});
describe('API Pact test', () => {
beforeAll(() => mockProvider.setup());
afterEach(() => mockProvider.verify());
afterAll(() => mockProvider.finalize());
describe('retrieving a location', () => {
test('location exists', async () => {
// set up Pact interactions
const expectedLocation = {id: '10', title: 'a title'}
await mockProvider.addInteraction({
state: 'location exist',
uponReceiving: 'a request to get a location',
withRequest: {
method: 'GET',
path: '/api/mb/location/1bfff94a-b70e-4b39-bd2a-be1c0f898589',
query: {accountNumber: fromProviderState('${accountNumber}', '1bfff94a-b70e-4b39-bd2a-be1c0f898589')},
// headers: {
// Authorization: like('Bearer 2019-01-14T11:34:18.045Z'),
// },
},
willRespondWith: {
status: 200,
headers: {
'Content-Type': regex({
generate: 'application/json; charset=utf-8',
matcher: 'application/json;?.*'
}),
},
body: eachLike(expectedLocation),
},
});
const locations = await axiosClient.request({
method: "GET",
url: `/mb/location/1bfff94a-b70e-4b39-bd2a-be1c0f898589`,
headers: {Accept: "application/json"},
});
console.log("## locations", locations);
// // assert that we got the expected response
// expect(products).toStrictEqual([new Product(expectedProduct)]);
});
});
});