-
-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tagged-pact-versions): add endpoint to view and delete a collect…
…ion of pact versions by tag
- Loading branch information
Showing
14 changed files
with
316 additions
and
15 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
46 changes: 46 additions & 0 deletions
46
lib/pact_broker/api/decorators/tagged_pact_versions_decorator.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,46 @@ | ||
require_relative 'base_decorator' | ||
require_relative 'pact_version_decorator' | ||
|
||
module PactBroker | ||
module Api | ||
module Decorators | ||
class TaggedPactVersionsDecorator < BaseDecorator | ||
|
||
collection :entries, as: :pacts, embedded: true, :extend => PactBroker::Api::Decorators::PactVersionDecorator | ||
|
||
link :self do | context | | ||
{ | ||
href: context[:resource_url], | ||
title: "All versions of the pact between #{context[:consumer_name]} and #{context[:provider_name]} with tag #{context[:tag]}" | ||
} | ||
end | ||
|
||
link :'pb:consumer' do | context | | ||
{ | ||
href: pacticipant_url(context[:base_url], OpenStruct.new(name: context[:consumer_name])), | ||
title: "Consumer", | ||
name: context[:consumer_name] | ||
} | ||
end | ||
|
||
link :'pb:provider' do | context | | ||
{ | ||
href: pacticipant_url(context[:base_url], OpenStruct.new(name: context[:provider_name])), | ||
title: "Provider", | ||
name: context[:provider_name] | ||
} | ||
end | ||
|
||
links :'pb:pact-versions' do | context | | ||
represented.collect do | pact | | ||
{ | ||
:href => pact_url(context[:base_url], pact), | ||
:title => "Pact version", | ||
:name => pact.version_and_updated_date | ||
} | ||
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
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,38 @@ | ||
require 'pact_broker/api/resources/base_resource' | ||
require 'pact_broker/configuration' | ||
require 'pact_broker/api/decorators/tagged_pact_versions_decorator' | ||
|
||
module PactBroker | ||
module Api | ||
module Resources | ||
class TaggedPactVersions < BaseResource | ||
|
||
def content_types_provided | ||
[["application/hal+json", :to_json]] | ||
end | ||
|
||
def allowed_methods | ||
["GET", "DELETE", "OPTIONS"] | ||
end | ||
|
||
def resource_exists? | ||
pacticipant_service.find_pacticipant_by_name(consumer_name) && | ||
pacticipant_service.find_pacticipant_by_name(provider_name) | ||
end | ||
|
||
def to_json | ||
PactBroker::Api::Decorators::TaggedPactVersionsDecorator.new(pacts).to_json(user_options: decorator_context(identifier_from_path)) | ||
end | ||
|
||
def delete_resource | ||
pact_service.delete_all_pact_versions_between consumer_name, and: provider_name, tag: identifier_from_path[:tag] | ||
true | ||
end | ||
|
||
def pacts | ||
pact_service.find_all_pact_versions_between consumer_name, and: provider_name, tag: identifier_from_path[:tag] | ||
end | ||
end | ||
end | ||
end | ||
end |
7 changes: 7 additions & 0 deletions
7
lib/pact_broker/doc/views/index/tagged-pact-versions.markdown
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,7 @@ | ||
# Tagged pact versions | ||
|
||
Allowed methods: `GET`, `DELETE` | ||
|
||
Lists all the pact versions with the specified consumer, provider and consumer version tag. | ||
|
||
Send a `DELETE` request to the resource to batch delete all the versions. |
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,22 @@ | ||
describe "retrieving tagged pact versions" do | ||
|
||
let(:path) { "/pacts/provider/Provider/consumer/Consumer/tag/prod"} | ||
|
||
subject { get path; last_response } | ||
let(:json_response_body) { JSON.parse(subject.body, symbolize_names: true) } | ||
|
||
before do | ||
TestDataBuilder.new | ||
.create_consumer("Consumer") | ||
.create_provider("Provider") | ||
.create_consumer_version("1.2.3") | ||
.create_consumer_version_tag("prod") | ||
.create_pact | ||
.create_consumer_version("4.5.6") | ||
.create_pact | ||
end | ||
|
||
it "returns the latest tagged pact version" do | ||
expect(json_response_body[:_links][:self][:href]).to end_with("1.2.3") | ||
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
38 changes: 38 additions & 0 deletions
38
spec/lib/pact_broker/api/decorators/tagged_pact_versions_decorator_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,38 @@ | ||
require 'pact_broker/api/decorators/tagged_pact_versions_decorator' | ||
|
||
def register_fixture name | ||
yield | ||
end | ||
|
||
|
||
module PactBroker | ||
module Api | ||
module Decorators | ||
describe TaggedPactVersionsDecorator do | ||
|
||
let(:user_options) do | ||
register_fixture(:tagged_pact_versions_decorator_args) do | ||
{ | ||
consumer_name: "Foo", | ||
provider_name: "Bar" | ||
} | ||
end | ||
end | ||
|
||
let(:pact_versions) { [pact_version] } | ||
let(:pact_version) do | ||
instance_double("PactBroker::Domain::Pact") | ||
end | ||
|
||
let(:decorator) { TaggedPactVersionsDecorator.new(pact_versions) } | ||
let(:json) { decorator.to_json(user_options: user_options) } | ||
subject { JSON.parse(json) } | ||
|
||
xit "" do | ||
subject(subject['_links']['pb:consumer']).to eq({}) | ||
end | ||
|
||
end | ||
end | ||
end | ||
end |
86 changes: 86 additions & 0 deletions
86
spec/lib/pact_broker/api/resources/tagged_pact_versions_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,86 @@ | ||
require 'pact_broker/api/resources/tagged_pact_versions' | ||
|
||
module PactBroker | ||
module Api | ||
module Resources | ||
describe TaggedPactVersions do | ||
include_context "stubbed services" | ||
|
||
before do | ||
allow(pacticipant_service).to receive(:find_pacticipant_by_name).with("Foo").and_return(consumer) | ||
allow(pacticipant_service).to receive(:find_pacticipant_by_name).with("Bar").and_return(provider) | ||
end | ||
|
||
let(:path) { "/pacts/provider/Bar/consumer/Foo/tag/prod" } | ||
let(:consumer) { double('Bar') } | ||
let(:provider) { double('Foo') } | ||
|
||
context "GET" do | ||
before do | ||
allow(PactBroker::Api::Decorators::TaggedPactVersionsDecorator).to receive(:new).and_return(decorator) | ||
allow(pact_service).to receive(:find_all_pact_versions_between).and_return(pact_versions) | ||
end | ||
|
||
let(:decorator) { instance_double(PactBroker::Api::Decorators::TaggedPactVersionsDecorator, to_json: 'json') } | ||
let(:pact_versions) { double('pacts') } | ||
|
||
subject { get(path) } | ||
|
||
let(:user_options) do | ||
{ | ||
base_url: "http://example.org", | ||
resource_url: "http://example.org/pacts/provider/Bar/consumer/Foo/tag/prod", | ||
consumer_name: "Foo", | ||
provider_name: "Bar", | ||
tag: "prod" | ||
} | ||
end | ||
|
||
it "finds all the pacts with the given consumer/provider/tag" do | ||
expect(pact_service).to receive(:find_all_pact_versions_between).with("Foo", and: "Bar", tag: "prod") | ||
subject | ||
end | ||
|
||
it "returns a 200 OK hal+json response" do | ||
expect(subject).to be_a_hal_json_success_response | ||
end | ||
|
||
it "creates a JSON representation of the pact versions" do | ||
expect(PactBroker::Api::Decorators::TaggedPactVersionsDecorator).to receive(:new).with(pact_versions) | ||
expect(decorator).to receive(:to_json).with(user_options: hash_including(user_options)) | ||
subject | ||
end | ||
|
||
it "returns the JSON representation of the pact versions" do | ||
expect(subject.body).to eq 'json' | ||
end | ||
|
||
context "with the consumer or provider do not exist" do | ||
let(:consumer) { nil } | ||
|
||
it "returns a 404" do | ||
expect(subject).to be_a_404_response | ||
end | ||
end | ||
end | ||
|
||
context "DELETE" do | ||
before do | ||
allow(pact_service).to receive(:delete_all_pact_versions_between) | ||
end | ||
|
||
subject { delete(path) } | ||
|
||
it "deletes all the pacts with the given consumer/provider/tag" do | ||
expect(pact_service).to receive(:delete_all_pact_versions_between).with("Foo", and: "Bar", tag: "prod") | ||
subject | ||
end | ||
|
||
it "returns a 204" do | ||
expect(subject.status).to eq 204 | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.