/
getLocationV3.pact.spec.js
41 lines (37 loc) · 1.39 KB
/
getLocationV3.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
const path = require('path');
const {PactV3, MatchersV3} = require('@pact-foundation/pact/v3');
const {expect} = require('chai');
const {getLocation} = require("../api");
const {string, fromProviderState} = MatchersV3;
describe('Retrieve a location', () => {
const provider = new PactV3({
consumer: 'mbfrontend',
provider: 'mbbackend',
logLevel: 'trace',
dir: path.resolve(process.cwd(), 'pacts'),
});
it('queries the backend service for the location details', () => {
provider
.given('A location exist with a matching id exists')
.uponReceiving('a request to get the location details')
.withRequest({
method: 'GET',
path: fromProviderState('/api/mb/location/${id}', '/api/mb/location/100'),
headers: {Accept: 'application/json'},
})
.willRespondWith({
status: 200,
headers: {'Content-Type': 'application/json'},
body: {
title: string('Test'),
},
});
return provider.executeTest(async (mockserver) => {
return getLocation(mockserver.url, '100')
.then((result) => {
expect(result.status).to.equal(200);
expect(result.title).to.equal('Test');
});
});
});
});