Skip to content

Commit

Permalink
fix: accept multiple values for headers in V2 interface. Fixes #1031
Browse files Browse the repository at this point in the history
  • Loading branch information
mefellows committed Dec 23, 2022
1 parent 593dd68 commit 229aadd
Show file tree
Hide file tree
Showing 7 changed files with 5,344 additions and 2,343 deletions.
9 changes: 8 additions & 1 deletion examples/mocha/index.js
Expand Up @@ -10,7 +10,14 @@ exports.getMeDogs = (endpoint) => {
method: 'GET',
baseURL: `${url}:${port}`,
url: '/dogs',
headers: { Accept: 'application/json' },
headers: {
Accept: [
'application/problem+json',
'application/json',
'text/plain',
'*/*',
],
},
});
};

Expand Down
70 changes: 19 additions & 51 deletions examples/mocha/test/get-dogs.spec.js
Expand Up @@ -2,7 +2,7 @@

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

Expand All @@ -14,10 +14,9 @@ describe('The Dog API', () => {
port: port,
log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'),
dir: path.resolve(process.cwd(), 'pacts'),
spec: 2,
spec: 3,
consumer: 'MyConsumer',
provider: 'MyProvider',
pactfileWriteMode: 'merge',
logLevel: LOG_LEVEL,
});

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

describe('get /dogs', () => {
before((done) => {
before(() => {
const interaction = {
state: 'i have a list of dogs',
uponReceiving: 'a request for all dogs',
withRequest: {
method: 'GET',
path: '/dogs',
headers: {
Accept: 'application/json',
Accept:
'application/problem+json, application/json, text/plain, */*',
// Accept: [
// 'application/problem+json',
// 'application/json',
// 'text/plain',
// '*/*',
// ],
},
},
willRespondWith: {
status: 200,
headers: {
'Content-Type': 'application/json',
'Content-Type': Matchers.term({
generate: 'application/json',
matcher: 'application/json.*',
}),
},
body: EXPECTED_BODY,
},
};
provider.addInteraction(interaction).then(() => {
done();
});
return provider.addInteraction(interaction);
});

it('returns the correct response', (done) => {
it('returns the correct response', async () => {
const urlAndPort = {
url: url,
port: port,
};
getMeDogs(urlAndPort).then((response) => {
expect(response.data).to.eql(EXPECTED_BODY);
done();
}, done);
});
});

describe('get /dog/1', () => {
before((done) => {
const interaction = {
state: 'i have a list of dogs',
uponReceiving: 'a request for a single dog',
withRequest: {
method: 'GET',
path: '/dogs/1',
headers: {
Accept: 'application/json',
},
},
willRespondWith: {
status: 200,
headers: {
'Content-Type': 'application/json',
},
body: EXPECTED_BODY,
},
};
provider.addInteraction(interaction).then(() => {
done();
});
});

it('returns the correct response', (done) => {
const urlAndPort = {
url: url,
port: port,
};
getMeDog(urlAndPort).then((response) => {
expect(response.data).to.eql(EXPECTED_BODY);
done();
}, done);
const response = await getMeDogs(urlAndPort);
expect(response.data).to.eql(EXPECTED_BODY);
});
});
});

0 comments on commit 229aadd

Please sign in to comment.