From 0c794409e8906934352c0f9a353ad686b70a9cf9 Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Tue, 23 Jan 2018 11:03:10 +1100 Subject: [PATCH] feat(dashboard api): add pact tags --- .../api/decorators/dashboard_decorator.rb | 16 ++++++++++++++++ lib/pact_broker/domain/index_item.rb | 2 ++ spec/features/get_dashboard_spec.rb | 1 + spec/fixtures/dashboard.json | 11 +++++++++++ .../api/decorators/dashboard_decorator_spec.rb | 9 ++++++++- 5 files changed, 38 insertions(+), 1 deletion(-) diff --git a/lib/pact_broker/api/decorators/dashboard_decorator.rb b/lib/pact_broker/api/decorators/dashboard_decorator.rb index d8bf4427c..db94b3d8f 100644 --- a/lib/pact_broker/api/decorators/dashboard_decorator.rb +++ b/lib/pact_broker/api/decorators/dashboard_decorator.rb @@ -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, @@ -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 { diff --git a/lib/pact_broker/domain/index_item.rb b/lib/pact_broker/domain/index_item.rb index 2f8b73c12..173af29e4 100644 --- a/lib/pact_broker/domain/index_item.rb +++ b/lib/pact_broker/domain/index_item.rb @@ -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 diff --git a/spec/features/get_dashboard_spec.rb b/spec/features/get_dashboard_spec.rb index 489fcf577..07d7883b0 100644 --- a/spec/features/get_dashboard_spec.rb +++ b/spec/features/get_dashboard_spec.rb @@ -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 diff --git a/spec/fixtures/dashboard.json b/spec/fixtures/dashboard.json index fc23e09f8..0922d4b8a 100644 --- a/spec/fixtures/dashboard.json +++ b/spec/fixtures/dashboard.json @@ -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": { diff --git a/spec/lib/pact_broker/api/decorators/dashboard_decorator_spec.rb b/spec/lib/pact_broker/api/decorators/dashboard_decorator_spec.rb index 632e4d574..e8deec820 100644 --- a/spec/lib/pact_broker/api/decorators/dashboard_decorator_spec.rb +++ b/spec/lib/pact_broker/api/decorators/dashboard_decorator_spec.rb @@ -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') } @@ -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')) }