Skip to content

Commit

Permalink
feat(dashboard api): add pact tags
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Jan 23, 2018
1 parent 2b788b1 commit 0c79440
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 1 deletion.
16 changes: 16 additions & 0 deletions lib/pact_broker/api/decorators/dashboard_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def index_item_hash(consumer, provider, consumer_version, index_item, base_url)
consumer: consumer_hash(index_item, consumer, consumer_version, base_url),
provider: provider_hash(index_item, provider, base_url),
pact: pact_hash(index_item, base_url),
pactTags: pact_tags(index_item, base_url),
latestVerificationResult: verification_hash(index_item, base_url),
verificationStatus: index_item.verification_status.to_s,
webhookStatus: index_item.webhook_status.to_s,
Expand Down Expand Up @@ -109,6 +110,21 @@ def verification_hash(index_item, base_url)
end
end

def pact_tags(index_item, base_url)
index_item.tag_names.collect do | tag_name |
fake_tag = OpenStruct.new(name: tag_name, version: index_item.consumer_version)
{
name: tag_name,
latest: true,
_links: {
self: {
href: tag_url(base_url, fake_tag)
}
}
}
end
end

def latest_webhook_execution(index_item, base_url)
if index_item.last_webhook_execution_date
{
Expand Down
2 changes: 2 additions & 0 deletions lib/pact_broker/domain/index_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ def provider_version_number
@latest_verification ? @latest_verification.provider_version_number : nil
end

# these are the consumer tag names for which this pact publication
# is the latest with that tag
def tag_names
@tags
end
Expand Down
1 change: 1 addition & 0 deletions spec/features/get_dashboard_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
.create_consumer("Foo")
.create_provider("Bar")
.create_consumer_version("1.2.3")
.create_consumer_version_tag("prod")
.create_pact
.create_verification
.create_webhook
Expand Down
11 changes: 11 additions & 0 deletions spec/fixtures/dashboard.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@
"latestWebhookExecution": {
"triggeredAt": "2018-01-01T00:00:00+00:00"
},
"pactTags": [
{
"name": "prod",
"latest": true,
"_links": {
"self": {
"href": "pact_prod_tag_url"
}
}
}
],
"pact": {
"_links": {
"self": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ module Decorators
webhook_status: 'blah',
verification_status: 'wiffle',
provider_version_number: provider_version.number,
consumer_version_number: consumer_version.number
consumer_version_number: consumer_version.number,
tag_names: ['prod']
)
end
let(:consumer) { instance_double('PactBroker::Domain::Pacticipant', name: 'Foo') }
Expand All @@ -40,6 +41,12 @@ module Decorators
allow_any_instance_of(DashboardDecorator).to receive(:pacticipant_url).with(base_url, provider).and_return('provider_url')
allow_any_instance_of(DashboardDecorator).to receive(:version_url).with(base_url, consumer_version).and_return('consumer_version_url')
allow_any_instance_of(DashboardDecorator).to receive(:webhooks_status_url).with(consumer, provider, base_url).and_return('webhooks_status_url')
allow_any_instance_of(DashboardDecorator).to receive(:tag_url) do | instance, base_url, tag |
expect(tag.name).to eq 'prod'
expect(tag.version).to be consumer_version
expect(base_url).to eq base_url
'pact_prod_tag_url'
end
end

let(:expected_hash) { JSON.parse(File.read('spec/fixtures/dashboard.json')) }
Expand Down

0 comments on commit 0c79440

Please sign in to comment.