forked from pact-foundation/pact_broker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add resource for "work in progress" pacts for a provider
- Loading branch information
Showing
10 changed files
with
199 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require 'pact_broker/api/resources/provider_pacts' | ||
require 'pact_broker/configuration' | ||
require 'pact_broker/api/decorators/provider_pacts_decorator' | ||
|
||
module PactBroker | ||
module Api | ||
module Resources | ||
class WipProviderPacts < ProviderPacts | ||
private | ||
|
||
def pacts | ||
pact_service.find_wip_pact_versions_for_provider provider_name | ||
end | ||
|
||
def resource_title | ||
"WIP pact versions for the provider #{provider_name}" | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
describe "Get WIP provider pacts" do | ||
subject { get path; last_response } | ||
|
||
let(:last_response_body) { JSON.parse(subject.body, symbolize_names: true) } | ||
let(:pact_links) { last_response_body[:_links][:'pb:pacts'] } | ||
|
||
context "when the provider exists" do | ||
before do | ||
TestDataBuilder.new | ||
.create_provider("Provider") | ||
.create_consumer("Consumer") | ||
.create_consumer_version("0.0.1") | ||
.create_pact | ||
end | ||
|
||
let(:path) { "/pacts/provider/Provider/wip" } | ||
|
||
it "returns a 200 HAL JSON response" do | ||
expect(subject).to be_a_hal_json_success_response | ||
end | ||
|
||
it "returns a list of links to the pacts" do | ||
expect(pact_links.size).to eq 1 | ||
end | ||
end | ||
end |
34 changes: 34 additions & 0 deletions
34
spec/lib/pact_broker/api/resources/wip_provider_pacts_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require 'pact_broker/api/resources/latest_provider_pacts' | ||
|
||
module PactBroker | ||
module Api | ||
module Resources | ||
describe WipProviderPacts do | ||
before do | ||
allow(PactBroker::Pacts::Service).to receive(:find_wip_pact_versions_for_provider).and_return(pacts) | ||
allow(PactBroker::Api::Decorators::ProviderPactsDecorator).to receive(:new).and_return(decorator) | ||
allow_any_instance_of(WipProviderPacts).to receive(:resource_exists?).and_return(provider) | ||
end | ||
|
||
let(:provider) { double('provider') } | ||
let(:pacts) { double('pacts') } | ||
let(:path) { '/pacts/provider/Bar/wip' } | ||
let(:decorator) { instance_double('PactBroker::Api::Decorators::ProviderPactsDecorator') } | ||
|
||
subject { get path; last_response } | ||
|
||
it "finds the wip pacts for the provider" do | ||
expect(PactBroker::Pacts::Service).to receive(:find_wip_pact_versions_for_provider).with("Bar") | ||
subject | ||
end | ||
|
||
it "sets the correct resource title" do | ||
expect(decorator).to receive(:to_json) do | options | | ||
expect(options[:user_options][:title]).to eq "WIP pact versions for the provider Bar" | ||
end | ||
subject | ||
end | ||
end | ||
end | ||
end | ||
end |
94 changes: 94 additions & 0 deletions
94
spec/lib/pact_broker/pacts/repository_find_wip_pact_versions_for_provider_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
require 'pact_broker/pacts/repository' | ||
|
||
module PactBroker | ||
module Pacts | ||
describe Repository do | ||
let(:td) { TestDataBuilder.new } | ||
|
||
describe "find_wip_pact_versions_for_provider" do | ||
subject { Repository.new.find_wip_pact_versions_for_provider("bar") } | ||
|
||
context "when the latest pact for a tag has been successfully verified" do | ||
before do | ||
td.create_pact_with_hierarchy("foo", "1", "bar") | ||
.comment("above not included because it's not the latest prod") | ||
.create_consumer_version("2") | ||
.create_consumer_version_tag("prod") | ||
.create_pact | ||
.create_verification(provider_version: "3", comment: "not included because already verified") | ||
end | ||
|
||
it "is not included" do | ||
expect(subject.size).to be 0 | ||
end | ||
end | ||
|
||
context "when the latest pact without a tag has failed verification" do | ||
before do | ||
td.create_pact_with_hierarchy("foo", "1", "bar") | ||
.create_verification(provider_version: "3", success: false) | ||
end | ||
|
||
it "is included" do | ||
expect(subject.size).to be 1 | ||
end | ||
end | ||
|
||
context "when the latest pact without a tag has not been verified" do | ||
before do | ||
td.create_pact_with_hierarchy("foo", "1", "bar") | ||
.create_consumer_version("2") | ||
.create_pact | ||
end | ||
|
||
it "is included" do | ||
expect(subject.first.consumer_version_number).to eq "2" | ||
expect(subject.size).to be 1 | ||
end | ||
end | ||
|
||
context "when the latest pact for a tag has failed verification" do | ||
before do | ||
td.create_pact_with_hierarchy("foo", "1", "bar") | ||
.create_consumer_version_tag("prod") | ||
.create_verification(provider_version: "3", success: true) | ||
.create_consumer_version("2", tag_names: ["prod"]) | ||
.create_pact | ||
.create_verification(provider_version: "5", success: false) | ||
end | ||
|
||
it "is included" do | ||
expect(subject.first.consumer_version_number).to eq "2" | ||
expect(subject.size).to be 1 | ||
end | ||
end | ||
|
||
context "when the latest pact for a tag has not been verified" do | ||
before do | ||
td.create_pact_with_hierarchy("foo", "1", "bar") | ||
.create_consumer_version_tag("prod") | ||
.create_verification(provider_version: "5") | ||
.create_consumer_version("2", tag_names: ["prod"]) | ||
.create_pact | ||
end | ||
|
||
it "is included" do | ||
expect(subject.first.consumer_version_number).to eq "2" | ||
expect(subject.size).to be 1 | ||
end | ||
end | ||
|
||
context "when the provider name does not match the given provider name" do | ||
before do | ||
td.create_pact_with_hierarchy("foo", "1", "baz") | ||
.create_provider("bar") | ||
end | ||
|
||
it "is not included" do | ||
expect(subject.size).to be 0 | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters