Skip to content

Commit

Permalink
feat: add provider version tag during verification
Browse files Browse the repository at this point in the history
  • Loading branch information
mefellows committed Nov 8, 2019
1 parent ccee4e2 commit 68b17d8
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
35 changes: 35 additions & 0 deletions src/verifier.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,4 +283,39 @@ describe('Verifier Spec', () => {
).to.not.throw(Error);
});
});

context('when providerVersionTag is not provided', () => {
it('should not fail', () => {
expect(() =>
verifierFactory({
providerBaseUrl: 'http://localhost',
pactUrls: [path.dirname(currentDir)],
}),
).to.not.throw(Error);
});
});

context('when providerVersionTag is provided as a string', () => {
it('should convert the argument to an array', () => {
const v = verifierFactory({
providerBaseUrl: 'http://localhost',
pactUrls: [path.dirname(currentDir)],
providerVersionTag: 'tag-1',
});

expect(v.options.providerVersionTag).to.deep.eq(['tag-1']);
});
});

context('when providerVersionTag is provided as an array', () => {
it('should not fail', () => {
expect(() =>
verifierFactory({
providerBaseUrl: 'http://localhost',
pactUrls: [path.dirname(currentDir)],
providerVersionTag: ['tag-1'],
}),
).to.not.throw(Error);
});
});
});
15 changes: 11 additions & 4 deletions src/verifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export class Verifier {
pactBrokerPassword: '--broker-password',
pactBrokerToken: '--broker-token',
consumerVersionTag: '--consumer-version-tag',
providerVersionTag: '--provider-version-tag',
publishVerificationResult: '--publish-verification-results',
providerVersion: '--provider-app-version',
provider: '--provider',
Expand All @@ -47,6 +48,7 @@ export class Verifier {
options.providerStatesSetupUrl = options.providerStatesSetupUrl || '';
options.timeout = options.timeout || 30000;
options.consumerVersionTag = options.consumerVersionTag || [];
options.providerVersionTag = options.providerVersionTag || [];

if (
options.consumerVersionTag &&
Expand All @@ -56,6 +58,14 @@ export class Verifier {
}
checkTypes.assert.array.of.string(options.consumerVersionTag);

if (
options.providerVersionTag &&
checkTypes.string(options.providerVersionTag)
) {
options.providerVersionTag = [options.providerVersionTag as string];
}
checkTypes.assert.array.of.string(options.providerVersionTag);

options.pactUrls = _.chain(options.pactUrls)
.map((uri: string) => {
// only check local files
Expand Down Expand Up @@ -112,10 +122,6 @@ export class Verifier {
checkTypes.assert.string(options.pactBrokerUrl);
}

if (options.consumerVersionTag) {
checkTypes.assert.array.of.string(options.consumerVersionTag);
}

if (options.pactUrls) {
checkTypes.assert.array.of.string(options.pactUrls);
}
Expand Down Expand Up @@ -210,6 +216,7 @@ export interface VerifierOptions {
pactBrokerPassword?: string;
pactBrokerToken?: string;
consumerVersionTag?: string | string[];
providerVersionTag?: string | string[];
customProviderHeaders?: string[];
publishVerificationResult?: boolean;
providerVersion?: string;
Expand Down

0 comments on commit 68b17d8

Please sign in to comment.