Skip to content

Commit

Permalink
feat(matrix): add tags to json response
Browse files Browse the repository at this point in the history
See: #288
  • Loading branch information
bethesque committed Oct 29, 2019
1 parent 9e84ce7 commit 6d099f5
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 8 deletions.
31 changes: 25 additions & 6 deletions lib/pact_broker/api/decorators/matrix_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,15 @@ def matrix(base_url)
provider = OpenStruct.new(name: line.provider_name)
consumer = OpenStruct.new(name: line.consumer_name)
consumer_version = OpenStruct.new(number: line.consumer_version_number, pacticipant: consumer)
line_hash(consumer, provider, consumer_version, line, base_url)
provider_version = line.provider_version_number ? OpenStruct.new(number: line.provider_version_number, pacticipant: provider) : nil
line_hash(consumer, provider, consumer_version, provider_version, line, base_url)
end
end

def line_hash(consumer, provider, consumer_version, line, base_url)
def line_hash(consumer, provider, consumer_version, provider_version, line, base_url)
{
consumer: consumer_hash(line, consumer, consumer_version, base_url),
provider: provider_hash(line, provider, base_url),
provider: provider_hash(line, provider, provider_version, base_url),
pact: pact_hash(line, base_url),
verificationResult: verification_hash(line, base_url)
}
Expand All @@ -74,7 +75,8 @@ def consumer_hash(line, consumer, consumer_version, base_url)
self: {
href: version_url(base_url, consumer_version)
}
}
},
tags: tags(line.consumer_version_tags)
},
_links: {
self: {
Expand All @@ -84,7 +86,16 @@ def consumer_hash(line, consumer, consumer_version, base_url)
}
end

def provider_hash(line, provider, base_url)
def tags(tags)
tags.collect do | tag |
{
name: tag.name,
latest: tag.latest?
}
end
end

def provider_hash(line, provider, provider_version, base_url)
hash = {
name: line.provider_name,
version: nil,
Expand All @@ -96,7 +107,15 @@ def provider_hash(line, provider, base_url)
}

if !line.provider_version_number.nil?
hash[:version] = { number: line.provider_version_number }
hash[:version] = {
number: line.provider_version_number,
_links: {
self: {
href: version_url(base_url, provider_version)
}
},
tags: tags(line.provider_version_tags)
}
end

hash
Expand Down
38 changes: 36 additions & 2 deletions spec/lib/pact_broker/api/decorators/matrix_decorator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ module Decorators
{
consumer_name: "Consumer",
consumer_version_number: "1.0.0",
consumer_version_tags: consumer_version_tags,
provider_version_tags: provider_version_tags,
pact_version_sha: "1234",
pact_created_at: pact_created_at,
provider_version_number: "4.5.6",
Expand All @@ -33,6 +35,7 @@ module Decorators
{
consumer_name: "Consumer",
consumer_version_number: "1.0.0",
consumer_version_tags: [],
pact_version_sha: "1234",
pact_created_at: pact_created_at,
provider_version_number: nil,
Expand All @@ -59,7 +62,14 @@ module Decorators
self: {
href: 'http://example.org/pacticipants/Consumer/versions/1.0.0'
}
}
},
tags: [
{
name: 'prod',
latest: true

}
]
}
}
end
Expand All @@ -73,7 +83,19 @@ module Decorators
}
},
version: {
number: '4.5.6'
number: '4.5.6',
_links: {
self: {
href: 'http://example.org/pacticipants/Provider/versions/4.5.6'
}
},
tags: [
{
name: 'master',
latest: false
}
]

}
}
end
Expand Down Expand Up @@ -101,6 +123,18 @@ module Decorators
}
end

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

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

let(:query_results){ PactBroker::Matrix::QueryResultsWithDeploymentStatusSummary.new([row_1, row_2], selectors, options, resolved_selectors, integrations, deployment_status_summary)}
let(:selectors) { nil }
let(:integrations){ [] }
Expand Down

0 comments on commit 6d099f5

Please sign in to comment.