Skip to content

Commit 229aadd

Browse files
committed
fix: accept multiple values for headers in V2 interface. Fixes #1031
1 parent 593dd68 commit 229aadd

File tree

7 files changed

+5344
-2343
lines changed

7 files changed

+5344
-2343
lines changed

examples/mocha/index.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,14 @@ exports.getMeDogs = (endpoint) => {
1010
method: 'GET',
1111
baseURL: `${url}:${port}`,
1212
url: '/dogs',
13-
headers: { Accept: 'application/json' },
13+
headers: {
14+
Accept: [
15+
'application/problem+json',
16+
'application/json',
17+
'text/plain',
18+
'*/*',
19+
],
20+
},
1421
});
1522
};
1623

examples/mocha/test/get-dogs.spec.js

+19-51
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const expect = require('chai').expect;
44
const path = require('path');
5-
const { Pact } = require('@pact-foundation/pact');
5+
const { Pact, Matchers } = require('@pact-foundation/pact');
66
const { getMeDogs, getMeDog } = require('../index');
77
const LOG_LEVEL = process.env.LOG_LEVEL || 'TRACE';
88

@@ -14,10 +14,9 @@ describe('The Dog API', () => {
1414
port: port,
1515
log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'),
1616
dir: path.resolve(process.cwd(), 'pacts'),
17-
spec: 2,
17+
spec: 3,
1818
consumer: 'MyConsumer',
1919
provider: 'MyProvider',
20-
pactfileWriteMode: 'merge',
2120
logLevel: LOG_LEVEL,
2221
});
2322

@@ -40,76 +39,45 @@ describe('The Dog API', () => {
4039
afterEach(() => provider.verify());
4140

4241
describe('get /dogs', () => {
43-
before((done) => {
42+
before(() => {
4443
const interaction = {
4544
state: 'i have a list of dogs',
4645
uponReceiving: 'a request for all dogs',
4746
withRequest: {
4847
method: 'GET',
4948
path: '/dogs',
5049
headers: {
51-
Accept: 'application/json',
50+
Accept:
51+
'application/problem+json, application/json, text/plain, */*',
52+
// Accept: [
53+
// 'application/problem+json',
54+
// 'application/json',
55+
// 'text/plain',
56+
// '*/*',
57+
// ],
5258
},
5359
},
5460
willRespondWith: {
5561
status: 200,
5662
headers: {
57-
'Content-Type': 'application/json',
63+
'Content-Type': Matchers.term({
64+
generate: 'application/json',
65+
matcher: 'application/json.*',
66+
}),
5867
},
5968
body: EXPECTED_BODY,
6069
},
6170
};
62-
provider.addInteraction(interaction).then(() => {
63-
done();
64-
});
71+
return provider.addInteraction(interaction);
6572
});
6673

67-
it('returns the correct response', (done) => {
74+
it('returns the correct response', async () => {
6875
const urlAndPort = {
6976
url: url,
7077
port: port,
7178
};
72-
getMeDogs(urlAndPort).then((response) => {
73-
expect(response.data).to.eql(EXPECTED_BODY);
74-
done();
75-
}, done);
76-
});
77-
});
78-
79-
describe('get /dog/1', () => {
80-
before((done) => {
81-
const interaction = {
82-
state: 'i have a list of dogs',
83-
uponReceiving: 'a request for a single dog',
84-
withRequest: {
85-
method: 'GET',
86-
path: '/dogs/1',
87-
headers: {
88-
Accept: 'application/json',
89-
},
90-
},
91-
willRespondWith: {
92-
status: 200,
93-
headers: {
94-
'Content-Type': 'application/json',
95-
},
96-
body: EXPECTED_BODY,
97-
},
98-
};
99-
provider.addInteraction(interaction).then(() => {
100-
done();
101-
});
102-
});
103-
104-
it('returns the correct response', (done) => {
105-
const urlAndPort = {
106-
url: url,
107-
port: port,
108-
};
109-
getMeDog(urlAndPort).then((response) => {
110-
expect(response.data).to.eql(EXPECTED_BODY);
111-
done();
112-
}, done);
79+
const response = await getMeDogs(urlAndPort);
80+
expect(response.data).to.eql(EXPECTED_BODY);
11381
});
11482
});
11583
});

0 commit comments

Comments
 (0)