Skip to content

Commit

Permalink
feat: deprecate consumerVersionTag and providerVersionTag. Fixes #218
Browse files Browse the repository at this point in the history
  • Loading branch information
mefellows committed Apr 9, 2020
1 parent b0eb190 commit 3e932bd
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 18 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ pact.verifyPacts({
| `pactBrokerUrl` | false | string | Base URL of the Pact Broker from which to retrieve the pacts. Required if `pactUrls` not given. |
| `provider` | false | string | Name of the provider if fetching from a Broker |
| `consumerVersionSelectors` | false | ConsumerVersionSelector\|array | Use [Selectors](https://docs.pact.io/selectors) to is a way we specify which pacticipants and versions we want to use when configuring verifications. |
| `consumerVersionTag` | false | string\|array | Retrieve the latest pacts with given tag(s) |
| `providerVersionTag` | false | string\|array | Tag(s) to apply to the provider application |
| `consumerVersionTags` | false | string\|array | Retrieve the latest pacts with given tag(s) |
| `providerVersionTags` | false | string\|array | Tag(s) to apply to the provider application |
| `pactUrls` | false | array | Array of local pact file paths or HTTP-based URLs. Required if _not_ using a Pact Broker. |
| `providerStatesSetupUrl` | false | string | URL to send PUT requests to setup a given provider state |
| `pactBrokerUsername` | false | string | Username for Pact Broker basic authentication |
Expand Down
74 changes: 66 additions & 8 deletions src/verifier.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import path = require('path');
import chai = require('chai');
import chaiAsPromised = require('chai-as-promised');
import verifierFactory, { VerifierOptions } from './verifier';
import verifierFactory, {
VerifierOptions,
DeprecatedVerifierOptions,
} from './verifier';

const expect = chai.expect;
chai.use(chaiAsPromised);
Expand Down Expand Up @@ -57,7 +60,7 @@ describe('Verifier Spec', () => {
expect(() =>
verifierFactory({
providerStatesSetupUrl: 'http://foo/provider-states/setup',
} as VerifierOptions),
} as VerifierOptions & DeprecatedVerifierOptions),
).to.throw(Error);
});
});
Expand Down Expand Up @@ -249,7 +252,7 @@ describe('Verifier Spec', () => {
});
});

context('when consumerVersionTag is not provided', () => {
context('when consumerVersionTags is not provided', () => {
it('should not fail', () => {
expect(() =>
verifierFactory({
Expand All @@ -260,6 +263,17 @@ describe('Verifier Spec', () => {
});
});

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

expect(v.options.consumerVersionTags).to.deep.eq(['tag-1']);
});
});
context('when consumerVersionTag is provided as a string', () => {
it('should convert the argument to an array', () => {
const v = verifierFactory({
Expand All @@ -272,19 +286,35 @@ describe('Verifier Spec', () => {
});
});

context('when consumerVersionTag is provided as an array', () => {
context('when consumerVersionTags is provided as an array', () => {
it('should not fail', () => {
expect(() =>
verifierFactory({
providerBaseUrl: 'http://localhost',
pactUrls: [path.dirname(currentDir)],
consumerVersionTag: ['tag-1'],
consumerVersionTags: ['tag-1'],
}),
).to.not.throw(Error);
});
});

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

context('when providerVersionTags is not provided', () => {
it('should not fail', () => {
expect(() =>
verifierFactory({
Expand All @@ -295,6 +325,18 @@ describe('Verifier Spec', () => {
});
});

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

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

context('when providerVersionTag is provided as a string', () => {
it('should convert the argument to an array', () => {
const v = verifierFactory({
Expand All @@ -307,18 +349,34 @@ describe('Verifier Spec', () => {
});
});

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

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

context('when using a bearer token', () => {
context('and specifies a username or password', () => {
it('should fail with an error', () => {
Expand Down
70 changes: 62 additions & 8 deletions src/verifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class Verifier {
'Create function will be removed in future release, please use the default export function or use `new Verifier()`',
);

public readonly options: VerifierOptions;
public readonly options: VerifierOptions & DeprecatedVerifierOptions;
private readonly __argMapping = {
pactUrls: DEFAULT_ARG,
providerBaseUrl: '--provider-base-url',
Expand All @@ -31,6 +31,8 @@ export class Verifier {
pactBrokerToken: '--broker-token',
consumerVersionTag: '--consumer-version-tag',
providerVersionTag: '--provider-version-tag',
consumerVersionTags: '--consumer-version-tag',
providerVersionTags: '--provider-version-tag',
consumerVersionSelector: '--consumer-version-selector',
publishVerificationResult: '--publish-verification-results',
providerVersion: '--provider-app-version',
Expand All @@ -43,7 +45,7 @@ export class Verifier {
out: '--out',
};

constructor(options: VerifierOptions) {
constructor(options: VerifierOptions & DeprecatedVerifierOptions) {
options = options || {};
options.pactBrokerUrl = options.pactBrokerUrl || '';
options.pactUrls = options.pactUrls || [];
Expand All @@ -52,8 +54,44 @@ export class Verifier {
options.timeout = options.timeout || 30000;
options.consumerVersionTag = options.consumerVersionTag || [];
options.providerVersionTag = options.providerVersionTag || [];
options.consumerVersionTags = options.consumerVersionTags || [];
options.providerVersionTags = options.providerVersionTags || [];
options.consumerVersionSelector = options.consumerVersionSelector || [];

if (
!_.isEmpty(options.consumerVersionTag) &&
!_.isEmpty(options.consumerVersionTags)
) {
throw new Error(
"Must not use both 'consumerVersionTags' and 'consumerVersionTag'. Please use 'consumerVersionTags' instead",
);
}

if (
!_.isEmpty(options.providerVersionTag) &&
!_.isEmpty(options.providerVersionTags)
) {
throw new Error(
"Must not use both 'providerVersionTags' and 'providerVersionTag'. Please use 'providerVersionTags' instead",
);
}

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

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

if (
options.consumerVersionTag &&
checkTypes.string(options.consumerVersionTag)
Expand All @@ -70,6 +108,15 @@ export class Verifier {
}
checkTypes.assert.array.of.string(options.providerVersionTag);

if (
!_.isEmpty(options.consumerVersionTag) ||
!_.isEmpty(options.providerVersionTag)
) {
logger.warn(
"'consumerVersionTag' and 'providerVersionTag' have been deprecated, please use 'consumerVersionTags' or 'providerVersionTags' instead",
);
}

options.pactUrls = _.chain(options.pactUrls)
.map((uri: string) => {
// only check local files
Expand Down Expand Up @@ -178,7 +225,7 @@ export class Verifier {

if (options.tags) {
logger.warn(
"'tags' has been deprecated as at v8.0.0, please use 'consumerVersionTag' instead",
"'tags' has been deprecated as at v8.0.0, please use 'consumerVersionTags' instead",
);
}

Expand Down Expand Up @@ -224,7 +271,9 @@ export class Verifier {
}

// Creates a new instance of the pact server with the specified option
export default (options: VerifierOptions): Verifier => new Verifier(options);
export default (
options: VerifierOptions & DeprecatedVerifierOptions,
): Verifier => new Verifier(options);

// A ConsumerVersionSelector is a way we specify which pacticipants and
// versions we want to use when configuring verifications.
Expand All @@ -243,21 +292,26 @@ export interface VerifierOptions {
provider?: string;
pactUrls?: string[];
pactBrokerUrl?: string;
providerStatesSetupUrl?: string;
pactBrokerUsername?: string;
pactBrokerPassword?: string;
pactBrokerToken?: string;
consumerVersionTag?: string | string[];
providerVersionTag?: string | string[];
consumerVersionTags?: string | string[];
providerVersionTags?: string | string[];
consumerVersionSelector?: ConsumerVersionSelector[];
customProviderHeaders?: string[];
publishVerificationResult?: boolean;
providerVersion?: string;
enablePending?: boolean;
timeout?: number;
tags?: string[];
verbose?: boolean;
monkeypatch?: string;
format?: 'json' | 'xml' | 'progress' | 'RspecJunitFormatter';
out?: string;
}

export interface DeprecatedVerifierOptions {
consumerVersionTag?: string | string[];
providerStatesSetupUrl?: string;
providerVersionTag?: string | string[];
tags?: string[];
}

0 comments on commit 3e932bd

Please sign in to comment.