pact_broker 2.31.0 → 2.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +40 -0
- data/db/migrations/20190509_create_version_sequence.rb +8 -0
- data/db/migrations/20190510_set_version_sequence.rb +9 -0
- data/db/migrations/20190511_create_integrations_view.rb +19 -0
- data/db/migrations/20190523_add_enabled_column_to_webhooks.rb +5 -0
- data/db/migrations/20190524_set_webhooks_enabled.rb +10 -0
- data/db/migrations/20190525_add_description_column_to_webhooks.rb +5 -0
- data/lib/pact_broker/api.rb +3 -0
- data/lib/pact_broker/api/decorators/base_decorator.rb +0 -3
- data/lib/pact_broker/api/decorators/integration_decorator.rb +40 -0
- data/lib/pact_broker/api/decorators/integrations_decorator.rb +19 -0
- data/lib/pact_broker/api/decorators/pact_decorator.rb +1 -1
- data/lib/pact_broker/api/decorators/pact_details_decorator.rb +1 -6
- data/lib/pact_broker/api/decorators/verifiable_pact_decorator.rb +12 -0
- data/lib/pact_broker/api/decorators/verifiable_pacts_decorator.rb +20 -0
- data/lib/pact_broker/api/decorators/webhook_decorator.rb +5 -1
- data/lib/pact_broker/api/decorators/webhook_execution_result_decorator.rb +0 -1
- data/lib/pact_broker/api/decorators/webhooks_decorator.rb +2 -2
- data/lib/pact_broker/api/pact_broker_urls.rb +37 -3
- data/lib/pact_broker/api/resources/base_resource.rb +4 -0
- data/lib/pact_broker/api/resources/dashboard.rb +1 -1
- data/lib/pact_broker/api/resources/integrations.rb +10 -2
- data/lib/pact_broker/api/resources/matrix_for_consumer_and_provider.rb +8 -14
- data/lib/pact_broker/api/resources/pact.rb +15 -3
- data/lib/pact_broker/api/resources/verification.rb +0 -2
- data/lib/pact_broker/api/resources/verifications.rb +18 -1
- data/lib/pact_broker/api/resources/webhook.rb +1 -1
- data/lib/pact_broker/api/resources/webhook_execution.rb +18 -9
- data/lib/pact_broker/app.rb +10 -11
- data/lib/pact_broker/db.rb +2 -2
- data/lib/pact_broker/db/data_migrations/helpers.rb +11 -0
- data/lib/pact_broker/db/data_migrations/set_latest_version_sequence_value.rb +29 -0
- data/lib/pact_broker/db/data_migrations/set_webhooks_enabled.rb +17 -0
- data/lib/pact_broker/db/migrate_data.rb +2 -0
- data/lib/pact_broker/db/seed_example_data.rb +6 -3
- data/lib/pact_broker/domain/order_versions.rb +14 -1
- data/lib/pact_broker/domain/verification.rb +4 -0
- data/lib/pact_broker/domain/webhook.rb +13 -3
- data/lib/pact_broker/domain/webhook_request.rb +3 -2
- data/lib/pact_broker/index/service.rb +3 -0
- data/lib/pact_broker/integrations/integration.rb +10 -0
- data/lib/pact_broker/integrations/service.rb +5 -0
- data/lib/pact_broker/matrix/parse_query.rb +2 -0
- data/lib/pact_broker/matrix/row.rb +8 -0
- data/lib/pact_broker/matrix/service.rb +1 -2
- data/lib/pact_broker/pacts/service.rb +16 -9
- data/lib/pact_broker/test/test_data_builder.rb +6 -2
- data/lib/pact_broker/verifications/sequence.rb +0 -2
- data/lib/pact_broker/verifications/service.rb +10 -2
- data/lib/pact_broker/version.rb +1 -1
- data/lib/pact_broker/versions/sequence.rb +38 -0
- data/lib/pact_broker/webhooks/job.rb +19 -7
- data/lib/pact_broker/webhooks/render.rb +30 -13
- data/lib/pact_broker/webhooks/repository.rb +3 -4
- data/lib/pact_broker/webhooks/service.rb +60 -34
- data/lib/pact_broker/webhooks/trigger_service.rb +6 -6
- data/lib/pact_broker/webhooks/webhook.rb +9 -1
- data/lib/pact_broker/webhooks/webhook_request_template.rb +11 -7
- data/lib/rack/pact_broker/database_transaction.rb +6 -2
- data/script/publish-new.sh +23 -1
- data/script/publish.sh +13 -4
- data/script/seed.rb +53 -52
- data/spec/features/create_webhook_spec.rb +2 -0
- data/spec/features/execute_webhook_spec.rb +4 -3
- data/spec/features/get_integrations_spec.rb +17 -0
- data/spec/features/get_pacts_to_verify_spec.rb +7 -3
- data/spec/features/publish_verification_spec.rb +8 -1
- data/spec/features/update_webhook_spec.rb +47 -0
- data/spec/integration/webhooks/certificate_spec.rb +1 -1
- data/spec/lib/pact_broker/api/contracts/webhook_contract_spec.rb +12 -0
- data/spec/lib/pact_broker/api/decorators/integration_decorator_spec.rb +82 -0
- data/spec/lib/pact_broker/api/decorators/integrations_decorator_spec.rb +29 -0
- data/spec/lib/pact_broker/api/decorators/pact_decorator_spec.rb +12 -4
- data/spec/lib/pact_broker/api/decorators/verifiable_pact_decorator_spec.rb +30 -0
- data/spec/lib/pact_broker/api/decorators/verifiable_pacts_decorator_spec.rb +29 -0
- data/spec/lib/pact_broker/api/decorators/webhook_decorator_spec.rb +20 -1
- data/spec/lib/pact_broker/api/decorators/webhook_execution_result_decorator_spec.rb +0 -4
- data/spec/lib/pact_broker/api/decorators/webhooks_decorator_spec.rb +5 -4
- data/spec/lib/pact_broker/api/pact_broker_urls_spec.rb +64 -1
- data/spec/lib/pact_broker/api/resources/pact_spec.rb +0 -3
- data/spec/lib/pact_broker/api/resources/verifications_spec.rb +40 -10
- data/spec/lib/pact_broker/api/resources/webhook_execution_spec.rb +13 -3
- data/spec/lib/pact_broker/app_spec.rb +28 -4
- data/spec/lib/pact_broker/db/data_migrations/set_latest_version_sequence_value_spec.rb +68 -0
- data/spec/lib/pact_broker/domain/order_versions_spec.rb +1 -4
- data/spec/lib/pact_broker/domain/webhook_spec.rb +10 -6
- data/spec/lib/pact_broker/matrix/parse_query_spec.rb +15 -7
- data/spec/lib/pact_broker/pacts/service_spec.rb +13 -5
- data/spec/lib/pact_broker/verifications/service_spec.rb +15 -3
- data/spec/lib/pact_broker/versions/repository_spec.rb +1 -1
- data/spec/lib/pact_broker/webhooks/job_spec.rb +52 -15
- data/spec/lib/pact_broker/webhooks/render_spec.rb +28 -7
- data/spec/lib/pact_broker/webhooks/repository_spec.rb +23 -32
- data/spec/lib/pact_broker/webhooks/service_spec.rb +186 -62
- data/spec/lib/pact_broker/webhooks/trigger_service_spec.rb +6 -5
- data/spec/lib/pact_broker/webhooks/webhook_request_template_spec.rb +12 -5
- data/spec/lib/rack/pact_broker/database_transaction_spec.rb +10 -0
- data/spec/lib/rack/pact_broker/ui_request_filter_spec.rb +9 -0
- data/spec/migrations/23_pact_versions_spec.rb +7 -1
- data/spec/support/database_cleaner.rb +11 -1
- data/spec/support/metadata_test_server.rb +40 -0
- data/spec/support/verification_job.rb +34 -0
- data/spec/support/webhook_endpoint_middleware.rb +22 -0
- metadata +37 -2
@@ -24,7 +24,7 @@ describe "executing a webhook to a server with a self signed certificate" do
|
|
24
24
|
|
25
25
|
let(:pact) { td.create_pact_with_hierarchy.and_return(:pact) }
|
26
26
|
|
27
|
-
subject { webhook_request.execute({}) }
|
27
|
+
subject { webhook_request.execute({ show_response: true }) }
|
28
28
|
|
29
29
|
context "without the correct cacert" do
|
30
30
|
it "fails" do
|
@@ -298,6 +298,18 @@ module PactBroker
|
|
298
298
|
expect(subject.errors[:"request.url"]).to eq ["cannot have a template parameter in the host"]
|
299
299
|
end
|
300
300
|
end
|
301
|
+
|
302
|
+
context "when enabled is not a boolean", pending: "I can't work out why this doesn't work" do
|
303
|
+
let(:json) do
|
304
|
+
valid_webhook_with do |hash|
|
305
|
+
hash['enabled'] = 'foo'
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
309
|
+
it "contains an error" do
|
310
|
+
expect(subject.errors[:enabled]).to eq ["cannot have a template parameter in the host"]
|
311
|
+
end
|
312
|
+
end
|
301
313
|
end
|
302
314
|
end
|
303
315
|
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'pact_broker/api/decorators/integration_decorator'
|
2
|
+
require 'pact_broker/integrations/integration'
|
3
|
+
|
4
|
+
module PactBroker
|
5
|
+
module Api
|
6
|
+
module Decorators
|
7
|
+
describe IntegrationDecorator do
|
8
|
+
before do
|
9
|
+
allow(integration_decorator).to receive(:dashboard_url_for_integration).and_return("/dashboard")
|
10
|
+
allow(integration_decorator).to receive(:matrix_url).and_return("/matrix")
|
11
|
+
allow(integration_decorator).to receive(:group_url).and_return("/group")
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:integration) do
|
15
|
+
instance_double(PactBroker::Integrations::Integration,
|
16
|
+
consumer: consumer,
|
17
|
+
provider: provider
|
18
|
+
)
|
19
|
+
end
|
20
|
+
let(:consumer) { double("consumer", name: "the consumer") }
|
21
|
+
let(:provider) { double("provider", name: "the provider") }
|
22
|
+
let(:options) { { user_options: { base_url: 'http://example.org' } } }
|
23
|
+
let(:expected_hash) do
|
24
|
+
{
|
25
|
+
"consumer" => {
|
26
|
+
"name" => "the consumer"
|
27
|
+
},
|
28
|
+
"provider" => {
|
29
|
+
"name" => "the provider"
|
30
|
+
},
|
31
|
+
"_links" => {
|
32
|
+
"pb:dashboard" => {
|
33
|
+
"href" => "/dashboard"
|
34
|
+
},
|
35
|
+
"pb:matrix" => {
|
36
|
+
"title" => "Matrix of pacts/verification results for the consumer and the provider",
|
37
|
+
"href" => "/matrix"
|
38
|
+
},
|
39
|
+
"pb:group" => {
|
40
|
+
"href" => "/group"
|
41
|
+
}
|
42
|
+
}
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
let(:integration_decorator) { IntegrationDecorator.new(integration) }
|
47
|
+
let(:json) { integration_decorator.to_json(options) }
|
48
|
+
subject { JSON.parse(json) }
|
49
|
+
|
50
|
+
it "generates a hash" do
|
51
|
+
expect(subject).to match_pact expected_hash
|
52
|
+
end
|
53
|
+
|
54
|
+
it "generates the correct link for the dashboard" do
|
55
|
+
expect(integration_decorator).to receive(:dashboard_url_for_integration).with(
|
56
|
+
"the consumer",
|
57
|
+
"the provider",
|
58
|
+
"http://example.org"
|
59
|
+
)
|
60
|
+
subject
|
61
|
+
end
|
62
|
+
|
63
|
+
it "generates the correct link for the matrix" do
|
64
|
+
expect(integration_decorator).to receive(:matrix_url).with(
|
65
|
+
"the consumer",
|
66
|
+
"the provider",
|
67
|
+
"http://example.org"
|
68
|
+
)
|
69
|
+
subject
|
70
|
+
end
|
71
|
+
|
72
|
+
it "generates the correct group url for the matrix" do
|
73
|
+
expect(integration_decorator).to receive(:group_url).with(
|
74
|
+
"the consumer",
|
75
|
+
"http://example.org"
|
76
|
+
)
|
77
|
+
subject
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'pact_broker/api/decorators/integrations_decorator'
|
2
|
+
|
3
|
+
module PactBroker
|
4
|
+
module Api
|
5
|
+
module Decorators
|
6
|
+
describe IntegrationsDecorator do
|
7
|
+
before do
|
8
|
+
allow(IntegrationDecorator).to receive(:new).and_return(integration_decorator)
|
9
|
+
end
|
10
|
+
let(:integration_decorator) { instance_double(IntegrationDecorator).as_null_object }
|
11
|
+
let(:integration) { double('integration') }
|
12
|
+
let(:integrations_decorator) { IntegrationsDecorator.new([integration]) }
|
13
|
+
let(:options) { { user_options: { resource_url: 'http://example.org/integrations' } } }
|
14
|
+
|
15
|
+
let(:json) { integrations_decorator.to_json(options) }
|
16
|
+
|
17
|
+
subject { JSON.parse(json) }
|
18
|
+
|
19
|
+
it "includes a list of integrations" do
|
20
|
+
expect(subject["_embedded"]["integrations"]).to be_an(Array)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "includes a link to itself" do
|
24
|
+
expect(subject["_links"]["self"]["href"]).to eq "http://example.org/integrations"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -7,7 +7,8 @@ module PactBroker
|
|
7
7
|
describe PactDecorator do
|
8
8
|
|
9
9
|
before do
|
10
|
-
|
10
|
+
allow(decorator).to receive(:templated_diff_url).and_return('templated-diff-url')
|
11
|
+
allow(decorator).to receive(:verification_publication_url).and_return('verification-publication-url')
|
11
12
|
end
|
12
13
|
let(:content_hash) {
|
13
14
|
{
|
@@ -34,11 +35,18 @@ module PactBroker
|
|
34
35
|
let(:consumer) { instance_double(PactBroker::Domain::Pacticipant, name: 'A Consumer')}
|
35
36
|
let(:provider) { instance_double(PactBroker::Domain::Pacticipant, name: 'A Provider')}
|
36
37
|
let(:consumer_version) { instance_double(PactBroker::Domain::Version, number: '1234', pacticipant: consumer)}
|
37
|
-
|
38
|
-
|
38
|
+
let(:metadata) { "abcd" }
|
39
|
+
let(:decorator) { PactDecorator.new(pact) }
|
40
|
+
let(:json) { decorator.to_json(user_options: { base_url: base_url, metadata: metadata }) }
|
41
|
+
subject { JSON.parse(json, symbolize_names: true) }
|
39
42
|
|
40
43
|
describe "#to_json" do
|
41
44
|
|
45
|
+
it "creates the verification link" do
|
46
|
+
expect(decorator).to receive(:verification_publication_url).with(pact, base_url, metadata)
|
47
|
+
subject
|
48
|
+
end
|
49
|
+
|
42
50
|
it "includes the json_content" do
|
43
51
|
expect(subject[:consumer]).to eq name: 'Consumer'
|
44
52
|
end
|
@@ -102,7 +110,7 @@ module PactBroker
|
|
102
110
|
end
|
103
111
|
|
104
112
|
it "includes a link to publish a verification" do
|
105
|
-
expect(subject[:_links][:'pb:publish-verification-results'][:href]).to
|
113
|
+
expect(subject[:_links][:'pb:publish-verification-results'][:href]).to eq "verification-publication-url"
|
106
114
|
end
|
107
115
|
|
108
116
|
it "includes a link to diff this pact version with another pact version" do
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'pact_broker/api/decorators/verifiable_pact_decorator'
|
2
|
+
|
3
|
+
module PactBroker
|
4
|
+
module Api
|
5
|
+
module Decorators
|
6
|
+
describe VerifiablePactDecorator do
|
7
|
+
|
8
|
+
let(:expected_hash) do
|
9
|
+
{
|
10
|
+
"pending" => true,
|
11
|
+
"_links" => {
|
12
|
+
"self" => "http://pact"
|
13
|
+
}
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:decorator) { VerifiablePactDecorator.new(pact) }
|
18
|
+
let(:pact) { double('pact') }
|
19
|
+
let(:json) { decorator.to_json(options) }
|
20
|
+
let(:options) { { user_options: { base_url: 'http://example.org' } } }
|
21
|
+
|
22
|
+
subject { JSON.parse(json) }
|
23
|
+
|
24
|
+
it "generates a matching hash", pending: true do
|
25
|
+
expect(subject).to match_pact(expected_hash)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'pact_broker/api/decorators/verifiable_pacts_decorator'
|
2
|
+
|
3
|
+
module PactBroker
|
4
|
+
module Api
|
5
|
+
module Decorators
|
6
|
+
describe VerifiablePactsDecorator do
|
7
|
+
before do
|
8
|
+
allow(VerifiablePactDecorator).to receive(:new).and_return(verifiable_pact_decorator)
|
9
|
+
end
|
10
|
+
let(:verifiable_pact_decorator) { instance_double(VerifiablePactDecorator).as_null_object }
|
11
|
+
let(:pact) { double('pact') }
|
12
|
+
let(:decorator) { VerifiablePactsDecorator.new([pact]) }
|
13
|
+
let(:options) { { user_options: { resource_url: 'http://example.org/pacts' } } }
|
14
|
+
|
15
|
+
let(:json) { decorator.to_json(options) }
|
16
|
+
|
17
|
+
subject { JSON.parse(json) }
|
18
|
+
|
19
|
+
it "includes a list of verifiable pacts" do
|
20
|
+
expect(subject["_embedded"]["pacts"]).to be_an(Array)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "includes a link to itself" do
|
24
|
+
expect(subject["_links"]["self"]["href"]).to eq "http://example.org/pacts"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -5,6 +5,7 @@ module PactBroker
|
|
5
5
|
module Api
|
6
6
|
module Decorators
|
7
7
|
describe WebhookDecorator do
|
8
|
+
let(:description) { "Trigger build" }
|
8
9
|
let(:headers) { { :'Content-Type' => 'application/json' } }
|
9
10
|
let(:request) do
|
10
11
|
{
|
@@ -27,13 +28,15 @@ module PactBroker
|
|
27
28
|
|
28
29
|
let(:webhook) do
|
29
30
|
Domain::Webhook.new(
|
31
|
+
description: description,
|
30
32
|
request: webhook_request,
|
31
33
|
uuid: 'some-uuid',
|
32
34
|
consumer: consumer,
|
33
35
|
provider: provider,
|
34
36
|
events: [event],
|
35
37
|
created_at: created_at,
|
36
|
-
updated_at: updated_at
|
38
|
+
updated_at: updated_at,
|
39
|
+
enabled: false
|
37
40
|
)
|
38
41
|
end
|
39
42
|
|
@@ -42,6 +45,10 @@ module PactBroker
|
|
42
45
|
describe 'to_json' do
|
43
46
|
let(:parsed_json) { JSON.parse(subject.to_json(user_options: { base_url: 'http://example.org' }), symbolize_names: true) }
|
44
47
|
|
48
|
+
it 'includes the description' do
|
49
|
+
expect(parsed_json[:description]).to eq "Trigger build"
|
50
|
+
end
|
51
|
+
|
45
52
|
it 'includes the request' do
|
46
53
|
expect(parsed_json[:request]).to eq request
|
47
54
|
end
|
@@ -90,6 +97,10 @@ module PactBroker
|
|
90
97
|
expect(parsed_json[:updatedAt]).to eq FormatDateTime.call(updated_at)
|
91
98
|
end
|
92
99
|
|
100
|
+
it 'includes the enabled flag' do
|
101
|
+
expect(parsed_json[:enabled]).to eq false
|
102
|
+
end
|
103
|
+
|
93
104
|
context 'when the headers are empty' do
|
94
105
|
let(:headers) { nil }
|
95
106
|
it 'does not include the headers' do
|
@@ -131,6 +142,14 @@ module PactBroker
|
|
131
142
|
expect(parsed_json[:request][:headers][:'Authorization']).to eq "**********"
|
132
143
|
end
|
133
144
|
end
|
145
|
+
|
146
|
+
context "when the description is empty" do
|
147
|
+
let(:description) { " " }
|
148
|
+
|
149
|
+
it 'uses the scope description' do
|
150
|
+
expect(parsed_json[:description]).to match /example.org/
|
151
|
+
end
|
152
|
+
end
|
134
153
|
end
|
135
154
|
|
136
155
|
describe 'from_json' do
|
@@ -43,10 +43,6 @@ module PactBroker
|
|
43
43
|
it "includes the message" do
|
44
44
|
expect(subject[:error][:message]).to eq 'message'
|
45
45
|
end
|
46
|
-
|
47
|
-
it "includes the backtrace" do
|
48
|
-
expect(subject[:error][:backtrace]).to eq ['blah','blah']
|
49
|
-
end
|
50
46
|
end
|
51
47
|
|
52
48
|
context "when there is a request" do
|
@@ -7,7 +7,10 @@ module PactBroker
|
|
7
7
|
describe WebhooksDecorator do
|
8
8
|
|
9
9
|
let(:webhook) do
|
10
|
-
instance_double(Domain::Webhook,
|
10
|
+
instance_double(Domain::Webhook,
|
11
|
+
uuid: 'some-uuid',
|
12
|
+
display_description: 'description'
|
13
|
+
)
|
11
14
|
end
|
12
15
|
let(:base_url) { 'http://example.org' }
|
13
16
|
let(:resource_url) { 'http://example.org/webhooks' }
|
@@ -31,15 +34,13 @@ module PactBroker
|
|
31
34
|
|
32
35
|
it "includes a list of links to the webhooks" do
|
33
36
|
expect(subject[:_links][:'pb:webhooks']).to be_instance_of(Array)
|
34
|
-
expect(subject[:_links][:'pb:webhooks'].first).to eq title: '
|
37
|
+
expect(subject[:_links][:'pb:webhooks'].first).to eq title: 'Webhook', name: 'description', href: 'http://example.org/webhooks/some-uuid'
|
35
38
|
end
|
36
39
|
|
37
40
|
it "includes curies" do
|
38
41
|
expect(subject[:_links][:curies]).to eq [{:name=>"pb", :href=>"http://example.org/doc/webhooks-{rel}", templated: true}]
|
39
42
|
end
|
40
|
-
|
41
43
|
end
|
42
|
-
|
43
44
|
end
|
44
45
|
end
|
45
46
|
end
|
@@ -10,7 +10,14 @@ module PactBroker
|
|
10
10
|
let(:base_url) { "http://example.org" }
|
11
11
|
let(:consumer_name) { "Foo/Foo" }
|
12
12
|
let(:provider_name) { "Bar/Bar" }
|
13
|
-
let(:pact)
|
13
|
+
let(:pact) do
|
14
|
+
double('pact',
|
15
|
+
consumer: consumer,
|
16
|
+
provider: provider,
|
17
|
+
consumer_version_number: "123/456",
|
18
|
+
pact_version_sha: "5hbfu",
|
19
|
+
consumer_version_tag_names: ["dev"])
|
20
|
+
end
|
14
21
|
let(:consumer) { double('pacticipant', name: consumer_name) }
|
15
22
|
let(:provider) { double('pacticipant', name: provider_name) }
|
16
23
|
let(:verification) do
|
@@ -21,9 +28,29 @@ module PactBroker
|
|
21
28
|
number: "1")
|
22
29
|
end
|
23
30
|
|
31
|
+
matcher :match_route_in_api do |api|
|
32
|
+
match do |url|
|
33
|
+
req = Webmachine::Request.new("GET", URI(url), Webmachine::Headers.new, "", nil)
|
34
|
+
api.application.routes.any?{ |route| route.match?(req) }
|
35
|
+
end
|
36
|
+
|
37
|
+
description do
|
38
|
+
"match route in API"
|
39
|
+
end
|
40
|
+
|
41
|
+
failure_message do |_|
|
42
|
+
"expected API to have route for path #{URI.parse(url).path}"
|
43
|
+
end
|
44
|
+
|
45
|
+
failure_message_when_negated do |_|
|
46
|
+
"expected API to not have route for path #{URI.parse(url).path}"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
24
50
|
describe "pact_url" do
|
25
51
|
subject { PactBrokerUrls.pact_url(base_url, pact) }
|
26
52
|
|
53
|
+
it { is_expected.to match_route_in_api(PactBroker::API) }
|
27
54
|
it { is_expected.to eq "http://example.org/pacts/provider/Bar%2FBar/consumer/Foo%2FFoo/version/123%2F456" }
|
28
55
|
end
|
29
56
|
|
@@ -36,20 +63,56 @@ module PactBroker
|
|
36
63
|
describe "pact_triggered_webhooks_url" do
|
37
64
|
subject { PactBrokerUrls.pact_triggered_webhooks_url(pact, base_url) }
|
38
65
|
|
66
|
+
it { is_expected.to match_route_in_api(PactBroker::API) }
|
39
67
|
it { is_expected.to eq "http://example.org/pacts/provider/Bar%2FBar/consumer/Foo%2FFoo/version/123%2F456/triggered-webhooks" }
|
40
68
|
end
|
41
69
|
|
42
70
|
describe "verification_triggered_webhooks_url" do
|
43
71
|
subject { PactBrokerUrls.verification_triggered_webhooks_url(verification, base_url) }
|
44
72
|
|
73
|
+
it { is_expected.to match_route_in_api(PactBroker::API) }
|
45
74
|
it { is_expected.to eq "http://example.org/pacts/provider/Bar%2FBar/consumer/Foo%2FFoo/pact-version/1234/verification-results/1/triggered-webhooks" }
|
46
75
|
end
|
47
76
|
|
77
|
+
describe "verification_publication_url" do
|
78
|
+
context "with no metadata" do
|
79
|
+
subject { PactBrokerUrls.verification_publication_url(verification, base_url) }
|
80
|
+
|
81
|
+
it { is_expected.to match_route_in_api(PactBroker::API) }
|
82
|
+
it { is_expected.to eq "http://example.org/pacts/provider/Bar%2FBar/consumer/Foo%2FFoo/pact-version/1234/metadata//verification-results" }
|
83
|
+
end
|
84
|
+
|
85
|
+
context "with metadata" do
|
86
|
+
subject { PactBrokerUrls.verification_publication_url(verification, base_url, "abcd") }
|
87
|
+
|
88
|
+
it { is_expected.to match_route_in_api(PactBroker::API) }
|
89
|
+
it { is_expected.to eq "http://example.org/pacts/provider/Bar%2FBar/consumer/Foo%2FFoo/pact-version/1234/metadata/abcd/verification-results" }
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
48
93
|
describe "templated_diff_url" do
|
49
94
|
subject { PactBrokerUrls.templated_diff_url(pact, base_url) }
|
50
95
|
|
51
96
|
it { is_expected.to eq "http://example.org/pacts/provider/Bar%2FBar/consumer/Foo%2FFoo/pact-version/5hbfu/diff/pact-version/{pactVersion}" }
|
52
97
|
end
|
98
|
+
|
99
|
+
describe "webhook metadata" do
|
100
|
+
let(:expected_metadata) do
|
101
|
+
{ consumer_version_number: "123/456", consumer_version_tags: %w[dev] }
|
102
|
+
end
|
103
|
+
|
104
|
+
it "builds the webhook metadata" do
|
105
|
+
expect(PactBrokerUrls.parse_webhook_metadata(PactBrokerUrls.build_webhook_metadata(pact))).to eq (expected_metadata)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe "parse_webhook_metadata" do
|
110
|
+
context "when the metadata is nil" do
|
111
|
+
it "returns an empty hash" do
|
112
|
+
expect(PactBrokerUrls.parse_webhook_metadata(nil)).to eq({})
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
53
116
|
end
|
54
117
|
end
|
55
118
|
end
|