-
-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create endpoints for retrieving all pact versions for a provide…
…r, with and without a tag.
- Loading branch information
Showing
11 changed files
with
326 additions
and
40 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
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,45 @@ | ||
require 'pact_broker/api/resources/base_resource' | ||
require 'pact_broker/configuration' | ||
require 'pact_broker/api/decorators/provider_pacts_decorator' | ||
|
||
module PactBroker | ||
module Api | ||
module Resources | ||
class ProviderPacts < BaseResource | ||
|
||
def content_types_provided | ||
[["application/hal+json", :to_json]] | ||
end | ||
|
||
def allowed_methods | ||
["GET"] | ||
end | ||
|
||
def resource_exists? | ||
pacticipant_service.find_pacticipant_by_name(provider_name) | ||
end | ||
|
||
def to_json | ||
PactBroker::Api::Decorators::ProviderPactsDecorator.new(pacts).to_json(to_json_options) | ||
end | ||
|
||
private | ||
|
||
def pacts | ||
pact_service.find_pact_versions_for_provider provider_name, tag: identifier_from_path[:tag] | ||
end | ||
|
||
def to_json_options | ||
{ | ||
user_options: decorator_context(identifier_from_path.merge(title: resource_title)) | ||
} | ||
end | ||
|
||
def resource_title | ||
suffix = identifier_from_path[:tag] ? " with consumer version tag '#{identifier_from_path[:tag]}'" : "" | ||
"All pact versions for the provider #{identifier_from_path[:provider_name]}#{suffix}" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,93 @@ | ||
require 'spec/support/test_data_builder' | ||
|
||
describe "Get provider pacts" do | ||
|
||
let(:path) { "/pacts/provider/Provider/latest" } | ||
let(:last_response_body) { JSON.parse(subject.body, symbolize_names: true) } | ||
|
||
let(:pact_links) { last_response_body[:_links][:'pb:pacts'] } | ||
subject { get path; last_response } | ||
|
||
context "when the provider exists" do | ||
|
||
before do | ||
TestDataBuilder.new | ||
.create_provider("Provider") | ||
.create_consumer("Consumer") | ||
.create_consumer_version("0.0.1") | ||
.create_consumer_version_tag("prod") | ||
.create_pact | ||
.create_consumer_version("1.0.0") | ||
.create_consumer_version_tag("prod") | ||
.create_pact | ||
.create_consumer_version("1.2.3") | ||
.create_pact | ||
.create_consumer("Consumer 2") | ||
.create_consumer_version("4.5.6") | ||
.create_consumer_version_tag("prod") | ||
.create_pact | ||
end | ||
|
||
context "with no tag specified" do | ||
let(:path) { "/pacts/provider/Provider/latest" } | ||
|
||
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(last_response_body[:_links][:pacts].size).to eq 2 | ||
expect(pact_links.size).to eq 2 | ||
end | ||
end | ||
|
||
context "with a tag specified" do | ||
|
||
let(:path) { "/pacts/provider/Provider/latest/prod" } | ||
|
||
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(last_response_body[:_links][:pacts].size).to eq 1 | ||
expect(pact_links.size).to eq 2 | ||
end | ||
end | ||
|
||
context "with a tag with no pacts" do | ||
|
||
let(:path) { "/pacts/provider/Provider/latest/foo" } | ||
|
||
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(last_response_body[:_links][:pacts].size).to eq 0 | ||
expect(pact_links.size).to eq 0 | ||
end | ||
end | ||
|
||
context "with a tag for all pacts" do | ||
let(:path) { "/pacts/provider/Provider/tag/prod" } | ||
|
||
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 3 | ||
end | ||
end | ||
|
||
context "with no tag for all pacts" do | ||
let(:path) { "/pacts/provider/Provider" } | ||
|
||
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(last_response_body[:_links][:'pb:pacts'].size).to eq 4 | ||
end | ||
end | ||
end | ||
|
||
context "when the provider does not exist" do | ||
let(:path) { "/pacts/provider/Provider" } | ||
|
||
it "returns a 404 response" do | ||
expect(subject).to be_a_404_response | ||
end | ||
|
||
end | ||
end |
52 changes: 52 additions & 0 deletions
52
spec/lib/pact_broker/api/resources/latest_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,52 @@ | ||
require 'pact_broker/api/resources/latest_provider_pacts' | ||
|
||
module PactBroker | ||
module Api | ||
module Resources | ||
describe LatestProviderPacts do | ||
before do | ||
allow(PactBroker::Pacts::Service).to receive(:find_latest_pact_versions_for_provider).and_return(pacts) | ||
allow(PactBroker::Api::Decorators::ProviderPactsDecorator).to receive(:new).and_return(decorator) | ||
allow_any_instance_of(LatestProviderPacts).to receive(:resource_exists?).and_return(provider) | ||
end | ||
|
||
let(:provider) { double('provider') } | ||
let(:pacts) { double('pacts') } | ||
let(:path) { '/pacts/provider/Bar/latest' } | ||
let(:decorator) { instance_double('PactBroker::Api::Decorators::ProviderPactsDecorator') } | ||
|
||
subject { get path; last_response } | ||
|
||
context "with no tag" do | ||
it "finds the pacts" do | ||
expect(PactBroker::Pacts::Service).to receive(:find_latest_pact_versions_for_provider).with("Bar", tag: nil) | ||
subject | ||
end | ||
|
||
it "sets the correct resource title" do | ||
expect(decorator).to receive(:to_json) do | options | | ||
expect(options[:user_options][:title]).to eq "Latest pact versions for the provider Bar" | ||
end | ||
subject | ||
end | ||
end | ||
|
||
context "with a tag" do | ||
let(:path) { '/pacts/provider/Bar/latest/prod' } | ||
|
||
it "finds the pacts with a tag" do | ||
expect(PactBroker::Pacts::Service).to receive(:find_latest_pact_versions_for_provider).with("Bar", tag: "prod") | ||
subject | ||
end | ||
|
||
it "sets the correct resource title" do | ||
expect(decorator).to receive(:to_json) do | options | | ||
expect(options[:user_options][:title]).to eq "Latest pact versions for the provider Bar with consumer version tag 'prod'" | ||
end | ||
subject | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.