Skip to content

Commit

Permalink
feat: add self relations for tags in matrix resource
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Dec 7, 2020
1 parent a560ce6 commit 727cee9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
13 changes: 9 additions & 4 deletions lib/pact_broker/api/decorators/matrix_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def consumer_hash(line, consumer, consumer_version, base_url)
href: version_url(base_url, consumer_version)
}
},
tags: tags(line.consumer_version_tags)
tags: tags(line.consumer_version_tags, base_url)
},
_links: {
self: {
Expand All @@ -86,11 +86,16 @@ def consumer_hash(line, consumer, consumer_version, base_url)
}
end

def tags(tags)
def tags(tags, base_url)
tags.collect do | tag |
{
name: tag.name,
latest: tag.latest?
latest: tag.latest?,
_links: {
self: {
href: tag_url(base_url, tag)
}
}
}
end
end
Expand All @@ -114,7 +119,7 @@ def provider_hash(line, provider, provider_version, base_url)
href: version_url(base_url, provider_version)
}
},
tags: tags(line.provider_version_tags)
tags: tags(line.provider_version_tags, base_url)
}
end

Expand Down
28 changes: 20 additions & 8 deletions spec/lib/pact_broker/api/decorators/matrix_decorator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,12 @@ module Decorators
tags: [
{
name: 'prod',
latest: true

latest: true,
_links: {
self: {
href: 'http://example.org/pacticipants/Consumer/versions/1.0.0/tags/prod'
}
}
}
]
}
Expand All @@ -92,10 +96,14 @@ module Decorators
tags: [
{
name: 'master',
latest: false
latest: false,
_links: {
self: {
href: 'http://example.org/pacticipants/Provider/versions/4.5.6/tags/master'
}
}
}
]

}
}
end
Expand Down Expand Up @@ -123,15 +131,19 @@ module Decorators
}
end

let(:consumer_version) { double("consumer version", number: "1.0.0", pacticipant: double("consumer", name: "Consumer")) }

let(:consumer_version_tags) do
[
double('tag', name: 'prod', latest?: true)
double("tag", name: "prod", latest?: true, version: consumer_version)
]
end

let(:provider_version) { double("provider version", number: "4.5.6", pacticipant: double("provider", name: "Provider")) }

let(:provider_version_tags) do
[
double('tag', name: 'master', latest?: false)
double("tag", name: "master", latest?: false, version: provider_version)
]
end

Expand All @@ -158,11 +170,11 @@ module Decorators
let(:parsed_json) { JSON.parse(json, symbolize_names: true) }

it "includes the consumer details" do
expect(parsed_json[:matrix][0][:consumer]).to eq consumer_hash
expect(parsed_json[:matrix][0][:consumer]).to match_pact consumer_hash
end

it "includes the provider details" do
expect(parsed_json[:matrix][0][:provider]).to eq provider_hash
expect(parsed_json[:matrix][0][:provider]).to match_pact provider_hash
end

it "includes the verification details" do
Expand Down

0 comments on commit 727cee9

Please sign in to comment.