pact_broker 2.85.1 → 2.86.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/release_gem.yml +1 -1
- data/.github/workflows/trigger_pact_docs_update.yml +22 -0
- data/CHANGELOG.md +10 -0
- data/DEVELOPER_DOCUMENTATION.md +0 -2
- data/db/migrations/20210914_add_labels_to_webhooks.rb +14 -0
- data/db/migrations/20210915_add_verified_by_to_verification.rb +6 -0
- data/docker-compose-ci-mysql.yml +1 -0
- data/docs/CONFIGURATION.md +255 -66
- data/docs/configuration.yml +166 -101
- data/lib/db.rb +0 -1
- data/lib/pact_broker/api/contracts/webhook_contract.rb +24 -2
- data/lib/pact_broker/api/decorators/verification_decorator.rb +4 -0
- data/lib/pact_broker/api/decorators/webhook_decorator.rb +27 -4
- data/lib/pact_broker/api/pact_broker_urls.rb +4 -0
- data/lib/pact_broker/api/resources/all_webhooks.rb +2 -2
- data/lib/pact_broker/config/runtime_configuration.rb +4 -0
- data/lib/pact_broker/config/runtime_configuration_database_methods.rb +1 -1
- data/lib/pact_broker/db/clean.rb +1 -2
- data/lib/pact_broker/doc/views/pacticipant/label.markdown +12 -0
- data/lib/pact_broker/doc/views/webhooks.markdown +17 -0
- data/lib/pact_broker/domain/pacticipant.rb +4 -0
- data/lib/pact_broker/domain/verification.rb +16 -4
- data/lib/pact_broker/domain/webhook.rb +5 -5
- data/lib/pact_broker/domain/webhook_pacticipant.rb +6 -0
- data/lib/pact_broker/locale/en.yml +1 -0
- data/lib/pact_broker/matrix/head_row.rb +1 -1
- data/lib/pact_broker/matrix/quick_row.rb +0 -1
- data/lib/pact_broker/matrix/repository.rb +0 -1
- data/lib/pact_broker/matrix/row.rb +2 -2
- data/lib/pact_broker/pacts/latest_pact_publication_id_for_consumer_version.rb +0 -1
- data/lib/pact_broker/pacts/pact_publication.rb +7 -0
- data/lib/pact_broker/pacts/pact_publication_clean_selector_dataset_module.rb +19 -0
- data/lib/pact_broker/pacts/pact_publication_dataset_module.rb +30 -2
- data/lib/pact_broker/pacts/pact_version.rb +24 -1
- data/lib/pact_broker/pacts/pacts_for_verification_repository.rb +2 -2
- data/lib/pact_broker/pacts/repository.rb +50 -47
- data/lib/pact_broker/test/http_test_data_builder.rb +37 -10
- data/lib/pact_broker/test/test_data_builder.rb +22 -5
- data/lib/pact_broker/verifications/repository.rb +5 -2
- data/lib/pact_broker/verifications/service.rb +4 -1
- data/lib/pact_broker/version.rb +1 -1
- data/lib/pact_broker/webhooks/event_listener.rb +4 -2
- data/lib/pact_broker/webhooks/pact_and_verification_parameters.rb +1 -0
- data/lib/pact_broker/webhooks/repository.rb +10 -4
- data/lib/pact_broker/webhooks/webhook.rb +66 -8
- data/script/data/verify-pact-for-multiple-selectors.rb +30 -0
- data/script/docs/generate-configuration-docs.rb +24 -3
- data/script/generate-erd +55 -0
- data/spec/features/create_webhook_spec.rb +55 -10
- data/spec/features/get_pact_spec.rb +2 -3
- data/spec/fixtures/verification.json +4 -0
- data/spec/integration/webhooks/pact_publication_spec.rb +51 -0
- data/spec/lib/pact_broker/api/contracts/webhook_contract_spec.rb +50 -0
- data/spec/lib/pact_broker/api/decorators/verification_decorator_spec.rb +8 -1
- data/spec/lib/pact_broker/api/decorators/verification_summary_decorator_spec.rb +3 -1
- data/spec/lib/pact_broker/api/decorators/webhook_decorator_spec.rb +4 -4
- data/spec/lib/pact_broker/config/runtime_configuration_documentation_spec.rb +30 -0
- data/spec/lib/pact_broker/deployments/environment_service_spec.rb +1 -1
- data/spec/lib/pact_broker/matrix/head_row_spec.rb +9 -5
- data/spec/lib/pact_broker/pacts/{latest_tagged_pact_publications_spec.rb → pact_publication_clean_selector_dataset_module_spec.rb} +7 -9
- data/spec/lib/pact_broker/pacts/pact_version_spec.rb +32 -0
- data/spec/lib/pact_broker/pacts/repository_spec.rb +33 -0
- data/spec/lib/pact_broker/verifications/service_spec.rb +16 -2
- data/spec/lib/pact_broker/webhooks/repository_spec.rb +158 -15
- data/spec/lib/pact_broker/webhooks/webhook_spec.rb +8 -5
- metadata +16 -11
- data/lib/pact_broker/pacts/all_pact_publications.rb +0 -158
- data/lib/pact_broker/pacts/latest_pact_publications.rb +0 -48
- data/lib/pact_broker/pacts/latest_pact_publications_by_consumer_version.rb +0 -26
- data/lib/pact_broker/pacts/latest_tagged_pact_publications.rb +0 -45
- data/lib/pact_broker/verifications/latest_verification_for_pact_version.rb +0 -39
- data/spec/lib/pact_broker/verifications/latest_verification_for_pact_version_spec.rb +0 -18
@@ -85,6 +85,31 @@ module PactBroker
|
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
88
|
+
context "with a consumer label" do
|
89
|
+
let(:json) do
|
90
|
+
valid_webhook_with do |hash|
|
91
|
+
hash["consumer"].delete("name")
|
92
|
+
hash["consumer"]["label"] = "my_label"
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
it "contains no errors" do
|
97
|
+
expect(subject.errors).to be_empty
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
context "with a consumer label and name provided" do
|
102
|
+
let(:json) do
|
103
|
+
valid_webhook_with do |hash|
|
104
|
+
hash["consumer"]["label"] = "my_label"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
it "contains consumer.label error" do
|
109
|
+
expect(subject.errors.messages).to eq({:'consumer.label' => ["cannot be provided"]})
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
88
113
|
context "with a nil provider name" do
|
89
114
|
let(:json) do
|
90
115
|
valid_webhook_with do |hash|
|
@@ -131,6 +156,31 @@ module PactBroker
|
|
131
156
|
end
|
132
157
|
end
|
133
158
|
|
159
|
+
context "with provider label" do
|
160
|
+
let(:json) do
|
161
|
+
valid_webhook_with do |hash|
|
162
|
+
hash["provider"].delete("name")
|
163
|
+
hash["provider"]["label"] = "my_label"
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
it "contains no errors" do
|
168
|
+
expect(subject.errors).to be_empty
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
context "with a provider label and name" do
|
173
|
+
let(:json) do
|
174
|
+
valid_webhook_with do |hash|
|
175
|
+
hash["provider"]["label"] = "my_label"
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
it "contains provider.label error" do
|
180
|
+
expect(subject.errors.messages).to eq({:'provider.label' => ["cannot be provided"]})
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
134
184
|
context "with no request defined" do
|
135
185
|
let(:json) { {}.to_json }
|
136
186
|
|
@@ -20,7 +20,9 @@ module PactBroker
|
|
20
20
|
pact_version_sha: "1234",
|
21
21
|
latest_pact_publication: pact_publication,
|
22
22
|
execution_date: DateTime.now,
|
23
|
-
provider_version_tags: provider_version_tags
|
23
|
+
provider_version_tags: provider_version_tags,
|
24
|
+
verified_by_implementation: "Ruby",
|
25
|
+
verified_by_version: "1234")
|
24
26
|
end
|
25
27
|
|
26
28
|
let(:pact_publication) do
|
@@ -67,6 +69,11 @@ module PactBroker
|
|
67
69
|
it "includes a link to the triggered webhooks" do
|
68
70
|
expect(subject[:_links][:'pb:triggered-webhooks'][:href]).to eq "http://triggered-webhooks"
|
69
71
|
end
|
72
|
+
|
73
|
+
it "includes the framework that did the verification" do
|
74
|
+
expect(subject[:verifiedBy][:implementation]).to eq "Ruby"
|
75
|
+
expect(subject[:verifiedBy][:version]).to eq "1234"
|
76
|
+
end
|
70
77
|
end
|
71
78
|
end
|
72
79
|
end
|
@@ -21,7 +21,9 @@ module PactBroker
|
|
21
21
|
latest_pact_publication: pact,
|
22
22
|
test_results: nil,
|
23
23
|
execution_date: DateTime.now,
|
24
|
-
provider_version_tags: provider_version_tags
|
24
|
+
provider_version_tags: provider_version_tags,
|
25
|
+
verified_by_implementation: "Ruby",
|
26
|
+
verified_by_version: "1234")
|
25
27
|
end
|
26
28
|
|
27
29
|
let(:pact_version) do
|
@@ -20,8 +20,8 @@ module PactBroker
|
|
20
20
|
Webhooks::WebhookRequestTemplate.new(request)
|
21
21
|
end
|
22
22
|
|
23
|
-
let(:consumer) { Domain::
|
24
|
-
let(:provider) { Domain::
|
23
|
+
let(:consumer) { Domain::WebhookPacticipant.new(name: "Consumer") }
|
24
|
+
let(:provider) { Domain::WebhookPacticipant.new(name: "Provider") }
|
25
25
|
let(:event) { Webhooks::WebhookEvent.new(name: "something_happened") }
|
26
26
|
let(:created_at) { DateTime.now }
|
27
27
|
let(:updated_at) { created_at + 1 }
|
@@ -193,8 +193,8 @@ module PactBroker
|
|
193
193
|
context "when the decorated object has a consumer/provider but the incoming JSON does not" do
|
194
194
|
let(:webhook) do
|
195
195
|
Domain::Webhook.new(
|
196
|
-
consumer: Domain::
|
197
|
-
provider: Domain::
|
196
|
+
consumer: Domain::WebhookPacticipant.new(name: "consumer"),
|
197
|
+
provider: Domain::WebhookPacticipant.new(name: "provider")
|
198
198
|
)
|
199
199
|
end
|
200
200
|
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require "pact_broker/config/runtime_configuration"
|
2
|
+
|
3
|
+
module PactBroker
|
4
|
+
module Config
|
5
|
+
describe RuntimeConfiguration do
|
6
|
+
ATTRIBUTES = RuntimeConfiguration.config_attributes
|
7
|
+
DOCUMENTATION = File.read("docs/configuration.yml")
|
8
|
+
DOCUMENTED_ATTRIBUTES = YAML.load(DOCUMENTATION)["groups"].flat_map{ | group | group["vars"].keys.collect(&:to_sym) }
|
9
|
+
DELIBERATELY_UNDOCUMENTED_ATTRIBUTES = [
|
10
|
+
:warning_error_class_names,
|
11
|
+
:log_configuration_on_startup,
|
12
|
+
:use_hal_browser,
|
13
|
+
:use_rack_protection,
|
14
|
+
:use_case_sensitive_resource_names,
|
15
|
+
:order_versions_by_date,
|
16
|
+
:base_equality_only_on_content_that_affects_verification_results,
|
17
|
+
:semver_formats,
|
18
|
+
:seed_example_data,
|
19
|
+
:use_first_tag_as_branch_time_limit,
|
20
|
+
:validate_database_connection_config
|
21
|
+
]
|
22
|
+
|
23
|
+
(ATTRIBUTES - DELIBERATELY_UNDOCUMENTED_ATTRIBUTES).each do | attribute_name |
|
24
|
+
it "has documentation for #{attribute_name}" do
|
25
|
+
expect(DOCUMENTED_ATTRIBUTES & [attribute_name]).to include(attribute_name)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -13,18 +13,22 @@ module PactBroker
|
|
13
13
|
.create_provider("Bar")
|
14
14
|
.create_consumer_version
|
15
15
|
.create_pact
|
16
|
-
.create_global_webhook
|
17
|
-
.create_consumer_webhook
|
18
|
-
.create_provider_webhook
|
16
|
+
.create_global_webhook(description: "global")
|
17
|
+
.create_consumer_webhook(description: "consumer")
|
18
|
+
.create_provider_webhook(description: "provider")
|
19
19
|
.create_provider("Wiffle")
|
20
|
-
.create_provider_webhook
|
20
|
+
.create_provider_webhook(description: "wiffle")
|
21
21
|
end
|
22
22
|
|
23
23
|
let(:row) { HeadRow.where(consumer_name: "Foo", provider_name: "Bar").single_record }
|
24
24
|
|
25
25
|
it "returns all the webhooks" do
|
26
26
|
rows = HeadRow.eager(:webhooks).all
|
27
|
-
expect(rows.first.webhooks
|
27
|
+
expect(rows.first.webhooks).to contain_exactly(
|
28
|
+
have_attributes(description: "global"),
|
29
|
+
have_attributes(description: "provider"),
|
30
|
+
have_attributes(description: "consumer")
|
31
|
+
)
|
28
32
|
end
|
29
33
|
end
|
30
34
|
|
@@ -1,9 +1,7 @@
|
|
1
|
-
require "pact_broker/pacts/latest_tagged_pact_publications"
|
2
|
-
|
3
1
|
module PactBroker
|
4
2
|
module Pacts
|
5
|
-
describe
|
6
|
-
subject {
|
3
|
+
describe PactPublicationCleanSelectorDatasetModule do
|
4
|
+
subject { PactPublication.latest_by_consumer_tag_for_clean_selector(selector).all.sort_by{ | pp | [pp.consumer_name, pp.consumer_version_number]} }
|
7
5
|
|
8
6
|
context "for latest for a specified tag" do
|
9
7
|
before do
|
@@ -15,7 +13,7 @@ module PactBroker
|
|
15
13
|
.create_consumer_version_tag("prod")
|
16
14
|
end
|
17
15
|
|
18
|
-
let(:selector) { PactBroker::
|
16
|
+
let(:selector) { PactBroker::DB::Clean::Selector.new(tag: "dev", latest: true) }
|
19
17
|
|
20
18
|
it "returns matching rows" do
|
21
19
|
expect(subject.count).to eq 1
|
@@ -33,7 +31,7 @@ module PactBroker
|
|
33
31
|
.create_consumer_version_tag("dev")
|
34
32
|
end
|
35
33
|
|
36
|
-
let(:selector) { PactBroker::
|
34
|
+
let(:selector) { PactBroker::DB::Clean::Selector.new(tag: "dev", latest: true, pacticipant_name: "Foo") }
|
37
35
|
|
38
36
|
it "returns matching rows" do
|
39
37
|
expect(subject.count).to eq 1
|
@@ -51,7 +49,7 @@ module PactBroker
|
|
51
49
|
.create_consumer_version_tag("prod")
|
52
50
|
end
|
53
51
|
|
54
|
-
let(:selector) { PactBroker::
|
52
|
+
let(:selector) { PactBroker::DB::Clean::Selector.new(tag: "dev") }
|
55
53
|
|
56
54
|
it "returns matching rows (which are only the latest)" do
|
57
55
|
expect(subject.count).to eq 1
|
@@ -69,7 +67,7 @@ module PactBroker
|
|
69
67
|
.create_consumer_version_tag("prod")
|
70
68
|
end
|
71
69
|
|
72
|
-
let(:selector) { PactBroker::
|
70
|
+
let(:selector) { PactBroker::DB::Clean::Selector.new(tag: true, latest: true) }
|
73
71
|
|
74
72
|
it "returns matching rows" do
|
75
73
|
expect(subject.count).to eq 2
|
@@ -87,7 +85,7 @@ module PactBroker
|
|
87
85
|
.create_consumer_version_tag("dev")
|
88
86
|
end
|
89
87
|
|
90
|
-
let(:selector) { PactBroker::
|
88
|
+
let(:selector) { PactBroker::DB::Clean::Selector.new(tag: true, latest: true, max_age: 5) }
|
91
89
|
|
92
90
|
it "returns matching rows" do
|
93
91
|
expect(subject.count).to eq 1
|
@@ -65,6 +65,38 @@ module PactBroker
|
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
|
+
describe "#latest_main_branch_verification" do
|
69
|
+
before do
|
70
|
+
td.create_pact_with_verification("Foo", "1", "Bar", "2")
|
71
|
+
.create_verification(provider_version: "3", number: 2, branch: "main")
|
72
|
+
.create_verification(provider_version: "3", number: 3)
|
73
|
+
.create_verification(provider_version: "3", number: 4)
|
74
|
+
.create_pact_with_verification("NotFoo", "1", "Bar", "4")
|
75
|
+
.create_verification(provider_version: "5", number: 5)
|
76
|
+
.create_pact_with_verification("NotFoo2", "1", "NotBar", "4")
|
77
|
+
.create_verification(provider_version: "6", number: 6)
|
78
|
+
.create_pact_with_verification("NotFoo3", "2", "NotBar", "5")
|
79
|
+
.create_verification(provider_version: "7", number: 7)
|
80
|
+
end
|
81
|
+
|
82
|
+
context "lazy loading" do
|
83
|
+
it "lazy loads" do
|
84
|
+
expect(PactPublication.order(:id).all.first.pact_version.latest_main_branch_verification).to have_attributes(provider_version_number: "3", number: 4)
|
85
|
+
expect(PactPublication.order(:id).all.last.pact_version.latest_main_branch_verification).to be_nil
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context "eager loading" do
|
90
|
+
let(:pact_version_1) { PactVersion.eager(:latest_main_branch_verification).order(:id).all.first }
|
91
|
+
let(:pact_version_2) { PactVersion.eager(:latest_main_branch_verification).order(:id).all.last }
|
92
|
+
|
93
|
+
it "eager loads" do
|
94
|
+
expect(PactPublication.order(:id).all.first.pact_version.latest_main_branch_verification).to have_attributes(provider_version_number: "3", number: 4)
|
95
|
+
expect(pact_version_2.associations[:latest_main_branch_verification]).to be_nil
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
68
100
|
describe "latest_consumer_version" do
|
69
101
|
before do
|
70
102
|
td.create_consumer("consumer")
|
@@ -967,6 +967,9 @@ module PactBroker
|
|
967
967
|
before do
|
968
968
|
td.create_consumer("Consumer")
|
969
969
|
.create_provider("Provider")
|
970
|
+
.create_consumer_version("0")
|
971
|
+
.create_consumer_version_tag("main")
|
972
|
+
.create_pact
|
970
973
|
.create_consumer_version("1")
|
971
974
|
.create_pact
|
972
975
|
.create_provider("Another Provider")
|
@@ -997,6 +1000,36 @@ module PactBroker
|
|
997
1000
|
expect(pact.consumer_version.number).to eq("2")
|
998
1001
|
end
|
999
1002
|
end
|
1003
|
+
|
1004
|
+
context "with a tag" do
|
1005
|
+
let(:pact) { Repository.new.search_for_latest_pact("Consumer", "Provider", "main") }
|
1006
|
+
|
1007
|
+
it "returns the latest" do
|
1008
|
+
expect(pact.consumer_version.number).to eq("0")
|
1009
|
+
end
|
1010
|
+
end
|
1011
|
+
|
1012
|
+
context "untagged" do
|
1013
|
+
before do
|
1014
|
+
td.create_consumer("Foo")
|
1015
|
+
.create_provider("Bar")
|
1016
|
+
.create_consumer_version("0")
|
1017
|
+
.create_consumer_version_tag("main")
|
1018
|
+
.create_pact
|
1019
|
+
.create_consumer_version("1")
|
1020
|
+
.create_pact
|
1021
|
+
.create_consumer_version("2")
|
1022
|
+
.create_consumer_version_tag("main")
|
1023
|
+
.create_pact
|
1024
|
+
|
1025
|
+
end
|
1026
|
+
|
1027
|
+
let(:pact) { Repository.new.search_for_latest_pact("Foo", "Bar", :untagged) }
|
1028
|
+
|
1029
|
+
it "returns the latest" do
|
1030
|
+
expect(pact.consumer_version.number).to eq("1")
|
1031
|
+
end
|
1032
|
+
end
|
1000
1033
|
end
|
1001
1034
|
end
|
1002
1035
|
|
@@ -21,7 +21,19 @@ module PactBroker
|
|
21
21
|
|
22
22
|
let(:event_context) { { some: "data", consumer_version_selectors: [{ foo: "bar" }] } }
|
23
23
|
let(:expected_event_context) { { some: "data", provider_version_tags: ["dev"] } }
|
24
|
-
let(:params)
|
24
|
+
let(:params) do
|
25
|
+
{
|
26
|
+
"success" => success,
|
27
|
+
"providerApplicationVersion" => "4.5.6",
|
28
|
+
"wip" => true,
|
29
|
+
"pending" => is_pending,
|
30
|
+
"testResults" => { "some" => "results" },
|
31
|
+
"verifiedBy" => {
|
32
|
+
"implementation" => "Ruby",
|
33
|
+
"version" => "1234"
|
34
|
+
}
|
35
|
+
}
|
36
|
+
end
|
25
37
|
let(:is_pending) { true }
|
26
38
|
let(:success) { true }
|
27
39
|
let(:pact) do
|
@@ -34,7 +46,7 @@ module PactBroker
|
|
34
46
|
let(:create_verification) { subject.create 3, params, selected_pacts, event_context }
|
35
47
|
|
36
48
|
it "logs the creation" do
|
37
|
-
expect(logger).to receive(:info).with(/.*verification.*3/, payload:
|
49
|
+
expect(logger).to receive(:info).with(/.*verification.*3/, payload: hash_including("providerApplicationVersion"=>"4.5.6", "success"=>true, "wip"=>true, "pending" => is_pending))
|
38
50
|
create_verification
|
39
51
|
end
|
40
52
|
|
@@ -47,6 +59,8 @@ module PactBroker
|
|
47
59
|
expect(verification.test_results).to eq "some" => "results"
|
48
60
|
expect(verification.consumer_version_selector_hashes).to eq [{ foo: "bar" }]
|
49
61
|
expect(verification.tag_names).to eq ["dev"]
|
62
|
+
expect(verification.verified_by_implementation).to eq "Ruby"
|
63
|
+
expect(verification.verified_by_version).to eq "1234"
|
50
64
|
end
|
51
65
|
|
52
66
|
it "sets the pact content for the verification" do
|
@@ -23,6 +23,8 @@ module PactBroker
|
|
23
23
|
let(:webhook) { Domain::Webhook.new(request: request, events: events) }
|
24
24
|
let(:consumer) { td.create_pacticipant("Consumer").and_return(:pacticipant) }
|
25
25
|
let(:provider) { td.create_pacticipant("Provider").and_return(:pacticipant) }
|
26
|
+
let(:webhook_consumer) { Domain::WebhookPacticipant.new(name: consumer.name) }
|
27
|
+
let(:webhook_provider) { Domain::WebhookPacticipant.new(name: provider.name) }
|
26
28
|
let(:uuid) { "the-uuid" }
|
27
29
|
let(:created_webhook_record) { ::DB::PACT_BROKER_DB[:webhooks].order(:id).last }
|
28
30
|
let(:created_events) { ::DB::PACT_BROKER_DB[:webhook_events].where(webhook_id: created_webhook_record[:id]).order(:name).all }
|
@@ -57,13 +59,13 @@ module PactBroker
|
|
57
59
|
end
|
58
60
|
|
59
61
|
context "when consumer and provider domain objects are set on the object rather than passed in" do
|
60
|
-
let(:webhook) { Domain::Webhook.new(request: request, events: events, consumer:
|
62
|
+
let(:webhook) { Domain::Webhook.new(request: request, events: events, consumer: webhook_consumer, provider: webhook_provider) }
|
61
63
|
|
62
64
|
subject { Repository.new.create(uuid, webhook, nil, nil) }
|
63
65
|
|
64
66
|
it "sets the consumer and provider relationships" do
|
65
|
-
expect(subject.consumer.
|
66
|
-
expect(subject.provider.
|
67
|
+
expect(subject.consumer.name).to eq consumer.name
|
68
|
+
expect(subject.provider.name).to eq provider.name
|
67
69
|
end
|
68
70
|
end
|
69
71
|
end
|
@@ -185,12 +187,10 @@ module PactBroker
|
|
185
187
|
end
|
186
188
|
|
187
189
|
it "returns a webhook with the consumer set" do
|
188
|
-
expect(subject.consumer.id).to eq consumer.id
|
189
190
|
expect(subject.consumer.name).to eq consumer.name
|
190
191
|
end
|
191
192
|
|
192
193
|
it "returns a webhook with the provider set" do
|
193
|
-
expect(subject.provider.id).to eq provider.id
|
194
194
|
expect(subject.provider.name).to eq provider.name
|
195
195
|
end
|
196
196
|
|
@@ -286,7 +286,7 @@ module PactBroker
|
|
286
286
|
let(:new_event) do
|
287
287
|
PactBroker::Webhooks::WebhookEvent.new(name: "something_else")
|
288
288
|
end
|
289
|
-
let(:new_consumer) {
|
289
|
+
let(:new_consumer) { Domain::WebhookPacticipant.new(name: "Foo2") }
|
290
290
|
let(:new_webhook) do
|
291
291
|
PactBroker::Domain::Webhook.new(
|
292
292
|
consumer: new_consumer,
|
@@ -423,11 +423,13 @@ module PactBroker
|
|
423
423
|
subject { Repository.new.find_webhooks_to_trigger(consumer: td.consumer, provider: td.provider, event_name: "contract_published") }
|
424
424
|
|
425
425
|
it "does not use a policy" do
|
426
|
-
td.create_webhook(event_names: ["contract_published"], enabled: enabled)
|
426
|
+
td.create_webhook(event_names: ["contract_published"], enabled: enabled, description: "Enabled webhook")
|
427
427
|
.create_consumer("Foo")
|
428
428
|
.create_provider("Bar")
|
429
429
|
expect(PactBroker).to_not receive(:policy_scope!)
|
430
|
-
|
430
|
+
is_expected.to contain_exactly(
|
431
|
+
have_attributes(description: "Enabled webhook")
|
432
|
+
)
|
431
433
|
end
|
432
434
|
|
433
435
|
context "when the webhook is disabled" do
|
@@ -437,21 +439,25 @@ module PactBroker
|
|
437
439
|
.create_provider("Bar")
|
438
440
|
end
|
439
441
|
let(:enabled) { false }
|
440
|
-
|
442
|
+
|
443
|
+
it "finds no webhooks to trigger" do
|
444
|
+
is_expected.to be_empty
|
445
|
+
end
|
441
446
|
end
|
442
447
|
|
443
448
|
context "when the webhook is specified for a consumer and all providers" do
|
444
449
|
before do
|
445
450
|
td.create_consumer("Foo1")
|
446
451
|
.create_provider("Bar1")
|
447
|
-
.create_webhook(provider: nil, event_names: ["contract_published"])
|
452
|
+
.create_webhook(provider: nil, event_names: ["contract_published"], description: "Right webhook")
|
448
453
|
end
|
449
454
|
|
450
|
-
|
455
|
+
let(:webhook_consumer) { Domain::WebhookPacticipant.new(name: td.consumer.name) }
|
451
456
|
|
452
|
-
it "
|
453
|
-
|
454
|
-
|
457
|
+
it "finds one webhook to trigger" do
|
458
|
+
is_expected.to contain_exactly(
|
459
|
+
have_attributes(description: "Right webhook")
|
460
|
+
)
|
455
461
|
end
|
456
462
|
end
|
457
463
|
|
@@ -463,7 +469,144 @@ module PactBroker
|
|
463
469
|
.create_provider("Bar3")
|
464
470
|
end
|
465
471
|
|
466
|
-
|
472
|
+
it "finds no webhooks to trigger" do
|
473
|
+
is_expected.to be_empty
|
474
|
+
end
|
475
|
+
end
|
476
|
+
|
477
|
+
context "when the webhook is specified for matching consumer label" do
|
478
|
+
before do
|
479
|
+
td.create_webhook(
|
480
|
+
event_names: ["contract_published"],
|
481
|
+
consumer_label: "my_label",
|
482
|
+
description: "Labeled webhook"
|
483
|
+
)
|
484
|
+
.create_consumer("Consumer")
|
485
|
+
.create_label("my_label")
|
486
|
+
.create_provider("Provider")
|
487
|
+
end
|
488
|
+
|
489
|
+
it "finds one webhook to trigger" do
|
490
|
+
is_expected.to contain_exactly(
|
491
|
+
have_attributes(description: "Labeled webhook")
|
492
|
+
)
|
493
|
+
end
|
494
|
+
end
|
495
|
+
|
496
|
+
context "when the webhook is specified for matching consumer label and specific provider" do
|
497
|
+
before do
|
498
|
+
td.create_provider("Provider")
|
499
|
+
.create_webhook(
|
500
|
+
event_names: ["contract_published"],
|
501
|
+
consumer_label: "my_label",
|
502
|
+
description: "Labeled webhook"
|
503
|
+
)
|
504
|
+
.create_consumer("Consumer")
|
505
|
+
.create_label("my_label")
|
506
|
+
end
|
507
|
+
|
508
|
+
it "finds one webhook to trigger" do
|
509
|
+
is_expected.to contain_exactly(
|
510
|
+
have_attributes(description: "Labeled webhook")
|
511
|
+
)
|
512
|
+
end
|
513
|
+
end
|
514
|
+
|
515
|
+
context "when the webhook is specified for consumer label that does not match" do
|
516
|
+
before do
|
517
|
+
td.create_webhook(event_names: ["contract_published"], consumer_label: "my_label")
|
518
|
+
.create_consumer("Consumer")
|
519
|
+
.create_label("other_label")
|
520
|
+
.create_provider("Provider")
|
521
|
+
end
|
522
|
+
|
523
|
+
it "finds no webhooks to trigger" do
|
524
|
+
is_expected.to be_empty
|
525
|
+
end
|
526
|
+
end
|
527
|
+
|
528
|
+
context "when the webhook is specified for matching provider label" do
|
529
|
+
before do
|
530
|
+
td.create_webhook(
|
531
|
+
event_names: ["contract_published"],
|
532
|
+
provider_label: "my_label",
|
533
|
+
description: "Labeled webhook"
|
534
|
+
)
|
535
|
+
.create_consumer("Consumer")
|
536
|
+
.create_provider("Provider")
|
537
|
+
.create_label("my_label")
|
538
|
+
end
|
539
|
+
|
540
|
+
it "finds one webhook to trigger" do
|
541
|
+
is_expected.to contain_exactly(
|
542
|
+
have_attributes(description: "Labeled webhook")
|
543
|
+
)
|
544
|
+
end
|
545
|
+
end
|
546
|
+
|
547
|
+
context "when the webhook is specified for matching provider label and specific consumer" do
|
548
|
+
before do
|
549
|
+
td.create_consumer("Consumer")
|
550
|
+
.create_webhook(
|
551
|
+
event_names: ["contract_published"],
|
552
|
+
provider_label: "my_label",
|
553
|
+
description: "Labeled webhook"
|
554
|
+
)
|
555
|
+
.create_provider("Provider")
|
556
|
+
.create_label("my_label")
|
557
|
+
end
|
558
|
+
|
559
|
+
it "finds one webhook to trigger" do
|
560
|
+
is_expected.to contain_exactly(
|
561
|
+
have_attributes(description: "Labeled webhook")
|
562
|
+
)
|
563
|
+
end
|
564
|
+
end
|
565
|
+
|
566
|
+
context "when the webhook is specified for provider label that does not match" do
|
567
|
+
before do
|
568
|
+
td.create_webhook(event_names: ["contract_published"], provider_label: "my_label")
|
569
|
+
.create_consumer("Consumer")
|
570
|
+
.create_provider("Provider")
|
571
|
+
.create_label("other_label")
|
572
|
+
end
|
573
|
+
|
574
|
+
it "find no webhooks to trigger" do
|
575
|
+
is_expected.to be_empty
|
576
|
+
end
|
577
|
+
end
|
578
|
+
|
579
|
+
context "when the webhook is specified for consumer and provider label" do
|
580
|
+
before do
|
581
|
+
td.create_webhook(
|
582
|
+
event_names: ["contract_published"],
|
583
|
+
consumer_label: "clabel",
|
584
|
+
provider_label: "plabel",
|
585
|
+
description: "Labeled webhook"
|
586
|
+
)
|
587
|
+
.create_webhook(
|
588
|
+
event_names: ["contract_published"],
|
589
|
+
consumer_label: "clabel",
|
590
|
+
provider_label: "plabel2",
|
591
|
+
description: "Labeled consumer webhook"
|
592
|
+
)
|
593
|
+
.create_webhook(
|
594
|
+
event_names: ["contract_published"],
|
595
|
+
consumer_label: "clabel2",
|
596
|
+
provider_label: "plabel",
|
597
|
+
description: "Labeled provider webhook"
|
598
|
+
)
|
599
|
+
.create_consumer("Consumer")
|
600
|
+
.create_label("clabel")
|
601
|
+
.create_provider("Provider")
|
602
|
+
.create_label("plabel")
|
603
|
+
end
|
604
|
+
|
605
|
+
it "finds one webhook to trigger" do
|
606
|
+
is_expected.to contain_exactly(
|
607
|
+
have_attributes(description: "Labeled webhook")
|
608
|
+
)
|
609
|
+
end
|
467
610
|
end
|
468
611
|
end
|
469
612
|
|