Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(verifier): consumerVersionTag should support multiple tags #155

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,7 @@ pact.verifyPacts({
| `providerBaseUrl` | true | string | Running API provider host endpoint. |
| `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 |
| `tags` | false | array | Array of tags, used to filter pacts from the Broker |
| `consumerVersionTag` | false | string | Retrieve the latest pacts with this consumer version tag |
| `consumerVersionTag` | false | string | array | Retrieve the latest pacts with this consumer version tag(s) |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The extra pipe denoting the union type here will actually try and create a new table column. Need to escape the | or problem just use or instead.

| `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
12 changes: 11 additions & 1 deletion src/verifier.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ describe("Verifier Spec", () => {
});
});

context("when consumerVersionTag is provided", () => {
context("when consumerVersionTag is provided as a string", () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test needs to check the transformation of consumerVersionTag

it("should not fail", () => {
expect(() => verifierFactory({
providerBaseUrl: "http://localhost",
Expand All @@ -218,4 +218,14 @@ describe("Verifier Spec", () => {
})).to.not.throw(Error);
});
});

context("when consumerVersionTag is provided as an array", () => {
it("should not fail", () => {
expect(() => verifierFactory({
providerBaseUrl: "http://localhost",
pactUrls: [path.dirname(currentDir)],
consumerVersionTag: ["tag-1"]
})).to.not.throw(Error);
});
});
});
12 changes: 3 additions & 9 deletions src/verifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ export class Verifier {
constructor(options: VerifierOptions) {
options = options || {};
options.pactBrokerUrl = options.pactBrokerUrl || "";
options.consumerVersionTag = options.consumerVersionTag || "";
options.tags = options.tags || [];
options.consumerVersionTag = _.toArray(options.consumerVersionTag);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will turn a string like "tag-1" into an array like [ 't', 'a', 'g', '-', '1' ]

options.pactUrls = options.pactUrls || [];
options.provider = options.provider || "";
options.providerStatesSetupUrl = options.providerStatesSetupUrl || "";
Expand Down Expand Up @@ -93,17 +92,13 @@ export class Verifier {
}

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

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

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

if (options.providerBaseUrl) {
checkTypes.assert.string(options.providerBaseUrl);
}
Expand Down Expand Up @@ -174,11 +169,10 @@ export interface VerifierOptions extends SpawnArguments {
pactBrokerUsername?: string;
pactBrokerPassword?: string;
pactBrokerToken?: string;
consumerVersionTag?: string;
consumerVersionTag?: string | string[];
customProviderHeaders?: string[];
publishVerificationResult?: boolean;
providerVersion?: string;
tags?: string[];
timeout?: number;
monkeypatch?: string;
format?: "json" | "RspecJunitFormatter";
Expand Down