Skip to content

Commit 0c79440

Browse files
committed
feat(dashboard api): add pact tags
1 parent 2b788b1 commit 0c79440

File tree

5 files changed

+38
-1
lines changed

5 files changed

+38
-1
lines changed

lib/pact_broker/api/decorators/dashboard_decorator.rb

+16
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def index_item_hash(consumer, provider, consumer_version, index_item, base_url)
3636
consumer: consumer_hash(index_item, consumer, consumer_version, base_url),
3737
provider: provider_hash(index_item, provider, base_url),
3838
pact: pact_hash(index_item, base_url),
39+
pactTags: pact_tags(index_item, base_url),
3940
latestVerificationResult: verification_hash(index_item, base_url),
4041
verificationStatus: index_item.verification_status.to_s,
4142
webhookStatus: index_item.webhook_status.to_s,
@@ -109,6 +110,21 @@ def verification_hash(index_item, base_url)
109110
end
110111
end
111112

113+
def pact_tags(index_item, base_url)
114+
index_item.tag_names.collect do | tag_name |
115+
fake_tag = OpenStruct.new(name: tag_name, version: index_item.consumer_version)
116+
{
117+
name: tag_name,
118+
latest: true,
119+
_links: {
120+
self: {
121+
href: tag_url(base_url, fake_tag)
122+
}
123+
}
124+
}
125+
end
126+
end
127+
112128
def latest_webhook_execution(index_item, base_url)
113129
if index_item.last_webhook_execution_date
114130
{

lib/pact_broker/domain/index_item.rb

+2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ def provider_version_number
6666
@latest_verification ? @latest_verification.provider_version_number : nil
6767
end
6868

69+
# these are the consumer tag names for which this pact publication
70+
# is the latest with that tag
6971
def tag_names
7072
@tags
7173
end

spec/features/get_dashboard_spec.rb

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
.create_consumer("Foo")
99
.create_provider("Bar")
1010
.create_consumer_version("1.2.3")
11+
.create_consumer_version_tag("prod")
1112
.create_pact
1213
.create_verification
1314
.create_webhook

spec/fixtures/dashboard.json

+11
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@
3535
"latestWebhookExecution": {
3636
"triggeredAt": "2018-01-01T00:00:00+00:00"
3737
},
38+
"pactTags": [
39+
{
40+
"name": "prod",
41+
"latest": true,
42+
"_links": {
43+
"self": {
44+
"href": "pact_prod_tag_url"
45+
}
46+
}
47+
}
48+
],
3849
"pact": {
3950
"_links": {
4051
"self": {

spec/lib/pact_broker/api/decorators/dashboard_decorator_spec.rb

+8-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ module Decorators
1919
webhook_status: 'blah',
2020
verification_status: 'wiffle',
2121
provider_version_number: provider_version.number,
22-
consumer_version_number: consumer_version.number
22+
consumer_version_number: consumer_version.number,
23+
tag_names: ['prod']
2324
)
2425
end
2526
let(:consumer) { instance_double('PactBroker::Domain::Pacticipant', name: 'Foo') }
@@ -40,6 +41,12 @@ module Decorators
4041
allow_any_instance_of(DashboardDecorator).to receive(:pacticipant_url).with(base_url, provider).and_return('provider_url')
4142
allow_any_instance_of(DashboardDecorator).to receive(:version_url).with(base_url, consumer_version).and_return('consumer_version_url')
4243
allow_any_instance_of(DashboardDecorator).to receive(:webhooks_status_url).with(consumer, provider, base_url).and_return('webhooks_status_url')
44+
allow_any_instance_of(DashboardDecorator).to receive(:tag_url) do | instance, base_url, tag |
45+
expect(tag.name).to eq 'prod'
46+
expect(tag.version).to be consumer_version
47+
expect(base_url).to eq base_url
48+
'pact_prod_tag_url'
49+
end
4350
end
4451

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

0 commit comments

Comments
 (0)