Skip to content

Commit

Permalink
tests: add tests for pact versions decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Sep 21, 2018
1 parent f91fc91 commit 8624861
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 21 deletions.
12 changes: 8 additions & 4 deletions spec/features/get_tagged_pact_versions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

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) }
subject { get(path) }
let(:json_response_body) { JSON.parse(subject.body) }

before do
TestDataBuilder.new
Expand All @@ -16,7 +16,11 @@
.create_pact
end

it "returns the latest tagged pact version" do
expect(json_response_body[:_links][:self][:href]).to end_with("1.2.3")
it "returns a 200 HAL JSON response" do
expect(subject).to be_a_hal_json_success_response
end

it "returns the list of tagged pact versions" do
expect(json_response_body['_links']['pb:pact-versions']).to be_a Array
end
end
Original file line number Diff line number Diff line change
@@ -1,37 +1,78 @@
require 'pact_broker/api/decorators/tagged_pact_versions_decorator'

def register_fixture name
yield
end


module PactBroker
module Api
module Decorators
describe TaggedPactVersionsDecorator do
before do
allow(PactBroker::Api::Decorators::PactVersionDecorator).to receive(:new).and_return(_version_decorator)
allow_any_instance_of(TaggedPactVersionsDecorator).to receive(:pact_url).and_return('pact_url')
allow_any_instance_of(TaggedPactVersionsDecorator).to receive(:pacticipant_url).and_return('pacticipant_url')
allow_any_instance_of(TaggedPactVersionsDecorator).to receive(:pacticipant_url).and_return('pacticipant_url')
end

let(:user_options) do
register_fixture(:tagged_pact_versions_decorator_args) do
register_fixture(:tagged_pact_versions_decorator_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"
provider_name: "Bar",
tag: "prod"
}
end
end

let(:_version_decorator) do
instance_double(PactBroker::Api::Decorators::VersionDecorator, to_hash: { some: "pact" } )
end
let(:pact_versions) { [pact_version] }
let(:pact_version) do
instance_double("PactBroker::Domain::Pact")
instance_double("PactBroker::Domain::Pact").as_null_object
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({})
let(:expected) do
{
"_embedded" => {
"pacts" => [
{
"some" => "pact"
}
]
},
"_links" => {
"self" => {
"href" => "http://example.org/pacts/provider/Bar/consumer/Foo/tag/prod",
"title" => "All versions of the pact between Foo and Bar with tag prod"
},
"pb:consumer" => {
"href" => "pacticipant_url",
"title" => "Consumer",
"name" => "Foo"
},
"pb:provider" => {
"href" => "pacticipant_url",
"title" => "Provider",
"name" => "Bar"
},
"pb:pact-versions" => [
{
"href" => "pact_url",
"title" => "Pact version",
"name" => "#[InstanceDouble(PactBroker::Domain::Pact) (anonymous)]"
}
]
}
}
end

it "matches the expected JSON" do
expect(subject).to match_pact(expected, allow_unexpected_keys: false)
end
end
end
end
Expand Down
16 changes: 9 additions & 7 deletions spec/lib/pact_broker/api/resources/tagged_pact_versions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ module Resources
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"
}
register_fixture(:tagged_pact_versions_decorator_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
end

it "finds all the pacts with the given consumer/provider/tag" do
Expand Down

0 comments on commit 8624861

Please sign in to comment.