pact_broker 2.80.0 → 2.81.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -2
- data/CHANGELOG.md +21 -0
- data/db/ddl_statements/latest_verifications_for_pact_versions.rb +28 -0
- data/db/migrations/20210711_add_consumer_version_order_to_pact_publication.rb +12 -0
- data/db/migrations/20210712_add_interaction_count_to_pact_versions.rb +8 -0
- data/lib/db.rb +4 -0
- data/lib/pact_broker/api.rb +8 -10
- data/lib/pact_broker/api/contracts/verifiable_pacts_json_query_schema.rb +25 -5
- data/lib/pact_broker/api/contracts/verifiable_pacts_query_schema.rb +0 -1
- data/lib/pact_broker/api/decorators/verifiable_pacts_query_decorator.rb +24 -0
- data/lib/pact_broker/api/resources/dashboard.rb +4 -1
- data/lib/pact_broker/api/resources/deployed_versions_for_version_and_environment.rb +3 -7
- data/lib/pact_broker/api/resources/index.rb +10 -12
- data/lib/pact_broker/api/resources/latest_provider_pacts.rb +1 -1
- data/lib/pact_broker/api/resources/pagination_methods.rb +14 -0
- data/lib/pact_broker/api/resources/tag.rb +14 -0
- data/lib/pact_broker/configuration.rb +4 -1
- data/lib/pact_broker/db/data_migrations/set_consumer_version_order_for_pact_publications.rb +28 -0
- data/lib/pact_broker/db/data_migrations/set_interactions_counts.rb +41 -0
- data/lib/pact_broker/db/migrate_data.rb +2 -0
- data/lib/pact_broker/db/seed_example_data.rb +5 -0
- data/lib/pact_broker/deployments/deployed_version_service.rb +13 -9
- data/lib/pact_broker/domain/verification.rb +40 -0
- data/lib/pact_broker/domain/version.rb +4 -0
- data/lib/pact_broker/index/service.rb +4 -5
- data/lib/pact_broker/integrations/integration.rb +27 -6
- data/lib/pact_broker/logging.rb +10 -0
- data/lib/pact_broker/matrix/unresolved_selector.rb +1 -1
- data/lib/pact_broker/metrics/service.rb +17 -0
- data/lib/pact_broker/pacts/all_pact_publications.rb +4 -2
- data/lib/pact_broker/pacts/content.rb +2 -2
- data/lib/pact_broker/pacts/metadata.rb +11 -5
- data/lib/pact_broker/pacts/pact_publication.rb +41 -6
- data/lib/pact_broker/pacts/pact_publication_dataset_module.rb +55 -11
- data/lib/pact_broker/pacts/pact_publication_selector_dataset_module.rb +20 -0
- data/lib/pact_broker/pacts/pact_version.rb +14 -15
- data/lib/pact_broker/pacts/pacts_for_verification_repository.rb +86 -31
- data/lib/pact_broker/pacts/parse.rb +1 -0
- data/lib/pact_broker/pacts/repository.rb +51 -41
- data/lib/pact_broker/pacts/selector.rb +18 -2
- data/lib/pact_broker/pacts/service.rb +13 -22
- data/lib/pact_broker/pacts/verifiable_pact_messages.rb +11 -0
- data/lib/pact_broker/repositories/helpers.rb +4 -0
- data/lib/pact_broker/repositories/scopes.rb +15 -0
- data/lib/pact_broker/test/test_data_builder.rb +2 -1
- data/lib/pact_broker/ui/helpers/matrix_helper.rb +1 -0
- data/lib/pact_broker/ui/views/index/show-with-tags.haml +1 -1
- data/lib/pact_broker/ui/views/matrix/show.haml +2 -0
- data/lib/pact_broker/verifications/latest_verification_for_pact_version.rb +2 -2
- data/lib/pact_broker/verifications/repository.rb +9 -10
- data/lib/pact_broker/version.rb +1 -1
- data/public/javascripts/matrix.js +3 -0
- data/spec/features/create_tag_spec.rb +10 -0
- data/spec/features/execute_webhook_spec.rb +1 -3
- data/spec/features/get_integrations_spec.rb +2 -2
- data/spec/features/get_provider_pacts_for_verification_spec.rb +5 -3
- data/spec/features/metadata_spec.rb +66 -0
- data/spec/features/publish_verification_results_and_version_spec.rb +70 -0
- data/spec/fixtures/approvals/get_provider_pacts_for_verification.approved.json +2 -2
- data/spec/lib/pact_broker/api/contracts/verifiable_pacts_json_query_schema_combinations_spec.rb +9 -0
- data/spec/lib/pact_broker/api/contracts/verifiable_pacts_json_query_schema_spec.rb +15 -0
- data/spec/lib/pact_broker/api/decorators/verifiable_pacts_query_decorator_spec.rb +12 -0
- data/spec/lib/pact_broker/api/resources/dashboard_spec.rb +23 -2
- data/spec/lib/pact_broker/api/resources/latest_provider_pacts_spec.rb +3 -3
- data/spec/lib/pact_broker/api/resources/provider_pacts_spec.rb +1 -1
- data/spec/lib/pact_broker/api/resources/tag_spec.rb +39 -13
- data/spec/lib/pact_broker/db/data_migrations/set_interactions_counts_spec.rb +38 -0
- data/spec/lib/pact_broker/deployments/deployed_version_service_spec.rb +42 -0
- data/spec/lib/pact_broker/domain/verification_spec.rb +17 -0
- data/spec/lib/pact_broker/index/service_spec.rb +28 -16
- data/spec/lib/pact_broker/integrations/integration_spec.rb +21 -10
- data/spec/lib/pact_broker/metrics/service_spec.rb +25 -0
- data/spec/lib/pact_broker/pacts/content_spec.rb +1 -1
- data/spec/lib/pact_broker/pacts/metadata_spec.rb +95 -29
- data/spec/lib/pact_broker/pacts/pact_publication_selector_dataset_module_spec.rb +39 -0
- data/spec/lib/pact_broker/pacts/pact_version_spec.rb +68 -12
- data/spec/lib/pact_broker/pacts/repository_find_wip_pact_versions_for_provider_branch_spec.rb +1 -1
- data/spec/lib/pact_broker/pacts/repository_find_wip_pact_versions_for_provider_spec.rb +1 -1
- data/spec/lib/pact_broker/pacts/repository_spec.rb +59 -52
- data/spec/lib/pact_broker/pacts/verifiable_pact_messages_spec.rb +9 -0
- data/spec/lib/pact_broker/verifications/latest_verification_for_pact_version_spec.rb +18 -0
- data/spec/support/shared_context.rb +0 -1
- metadata +20 -3
@@ -5,7 +5,7 @@ module PactBroker
|
|
5
5
|
class Selector < Hash
|
6
6
|
using PactBroker::HashRefinements
|
7
7
|
|
8
|
-
PROPERTY_NAMES = [:latest, :tag, :branch, :consumer, :consumer_version, :environment_name, :fallback_tag, :fallback_branch, :currently_supported, :currently_deployed]
|
8
|
+
PROPERTY_NAMES = [:latest, :tag, :branch, :consumer, :consumer_version, :environment_name, :fallback_tag, :fallback_branch, :main_branch, :currently_supported, :currently_deployed]
|
9
9
|
|
10
10
|
def initialize(properties = {})
|
11
11
|
properties.without(*PROPERTY_NAMES).tap { |it| warn("WARN: Unsupported property for #{self.class.name}: #{it.keys.join(", ")} at #{caller[0..3]}") if it.any? }
|
@@ -48,6 +48,10 @@ module PactBroker
|
|
48
48
|
end
|
49
49
|
# rubocop: enable Metrics/CyclomaticComplexity
|
50
50
|
|
51
|
+
def main_branch= main_branch
|
52
|
+
self[:main_branch] = main_branch
|
53
|
+
end
|
54
|
+
|
51
55
|
def tag= tag
|
52
56
|
self[:tag] = tag
|
53
57
|
end
|
@@ -128,6 +132,10 @@ module PactBroker
|
|
128
132
|
Selector.new(latest: true)
|
129
133
|
end
|
130
134
|
|
135
|
+
def self.for_main_branch
|
136
|
+
Selector.new(main_branch: true)
|
137
|
+
end
|
138
|
+
|
131
139
|
def self.latest_for_tag(tag)
|
132
140
|
Selector.new(latest: true, tag: tag)
|
133
141
|
end
|
@@ -196,6 +204,10 @@ module PactBroker
|
|
196
204
|
Selector.new(hash)
|
197
205
|
end
|
198
206
|
|
207
|
+
def latest_for_main_branch?
|
208
|
+
!!main_branch
|
209
|
+
end
|
210
|
+
|
199
211
|
def fallback_tag?
|
200
212
|
!!fallback_tag
|
201
213
|
end
|
@@ -204,6 +216,10 @@ module PactBroker
|
|
204
216
|
!!fallback_branch
|
205
217
|
end
|
206
218
|
|
219
|
+
def main_branch
|
220
|
+
self[:main_branch]
|
221
|
+
end
|
222
|
+
|
207
223
|
def tag
|
208
224
|
self[:tag]
|
209
225
|
end
|
@@ -213,7 +229,7 @@ module PactBroker
|
|
213
229
|
end
|
214
230
|
|
215
231
|
def overall_latest?
|
216
|
-
!!(latest? && !tag && !branch && !currently_deployed && !currently_supported && !environment_name)
|
232
|
+
!!(latest? && !tag && !branch && !main_branch && !currently_deployed && !currently_supported && !environment_name)
|
217
233
|
end
|
218
234
|
|
219
235
|
# Not sure if the fallback_tag logic is needed
|
@@ -85,8 +85,8 @@ module PactBroker
|
|
85
85
|
pact_repository.delete_all_pact_versions_between consumer, options
|
86
86
|
end
|
87
87
|
|
88
|
-
def
|
89
|
-
pact_repository.
|
88
|
+
def find_latest_pacts_for_provider provider_name, options = {}
|
89
|
+
pact_repository.find_latest_pacts_for_provider provider_name, options[:tag]
|
90
90
|
end
|
91
91
|
|
92
92
|
def find_pact_versions_for_provider provider_name, options = {}
|
@@ -116,33 +116,23 @@ module PactBroker
|
|
116
116
|
end
|
117
117
|
|
118
118
|
def find_for_verification(provider_name, provider_version_branch, provider_version_tags, consumer_version_selectors, options)
|
119
|
-
|
119
|
+
explicitly_specified_verifiable_pacts = pact_repository
|
120
120
|
.find_for_verification(provider_name, consumer_version_selectors)
|
121
121
|
.collect do | selected_pact |
|
122
|
+
# Todo move this into the repository
|
122
123
|
squash_pacts_for_verification(provider_version_tags, selected_pact, options[:include_pending_status])
|
123
124
|
end
|
124
125
|
|
125
|
-
verifiable_wip_pacts =
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
end
|
126
|
+
verifiable_wip_pacts = if options[:include_wip_pacts_since]
|
127
|
+
specified_pact_version_shas = explicitly_specified_verifiable_pacts.collect(&:pact_version_sha)
|
128
|
+
pact_repository.find_wip_pact_versions_for_provider(provider_name, provider_version_branch, provider_version_tags, specified_pact_version_shas, options)
|
129
|
+
else
|
130
|
+
[]
|
131
|
+
end
|
132
132
|
|
133
|
-
|
133
|
+
explicitly_specified_verifiable_pacts + verifiable_wip_pacts
|
134
134
|
end
|
135
135
|
|
136
|
-
def exclude_specified_pacts(wip_pacts, specified_pacts)
|
137
|
-
wip_pacts.reject do | wip_pact |
|
138
|
-
specified_pacts.any? do | specified_pact |
|
139
|
-
wip_pact.pact_version_sha == specified_pact.pact_version_sha
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
private :exclude_specified_pacts
|
145
|
-
|
146
136
|
# Overwriting an existing pact with the same consumer/provider/consumer version number
|
147
137
|
def update_pact params, existing_pact
|
148
138
|
logger.info "Updating existing pact publication with params #{params.reject{ |k, _v| k == :json_content}}"
|
@@ -179,7 +169,8 @@ module PactBroker
|
|
179
169
|
provider_id: provider.id,
|
180
170
|
consumer_id: version.pacticipant_id,
|
181
171
|
pact_version_sha: pact_version_sha,
|
182
|
-
json_content: json_content
|
172
|
+
json_content: json_content,
|
173
|
+
version: version
|
183
174
|
)
|
184
175
|
|
185
176
|
event_params = { event_context: { consumer_version_tags: pact.consumer_version_tag_names }, pact: pact }
|
@@ -77,6 +77,10 @@ module PactBroker
|
|
77
77
|
|
78
78
|
attr_reader :verifiable_pact, :pact_version_url
|
79
79
|
|
80
|
+
def consumer_main_branch
|
81
|
+
verifiable_pact.consumer.main_branch
|
82
|
+
end
|
83
|
+
|
80
84
|
def join(list, last_joiner = " and ")
|
81
85
|
join_unquoted(list.collect { | word | "'#{word}'" }, last_joiner)
|
82
86
|
end
|
@@ -178,6 +182,7 @@ module PactBroker
|
|
178
182
|
end
|
179
183
|
|
180
184
|
# rubocop: disable Metrics/CyclomaticComplexity
|
185
|
+
# rubocop: disable Metrics/MethodLength
|
181
186
|
def selector_description selector
|
182
187
|
description = if selector.overall_latest?
|
183
188
|
consumer_label = selector.consumer ? selector.consumer : "a consumer"
|
@@ -189,6 +194,9 @@ module PactBroker
|
|
189
194
|
else
|
190
195
|
"latest #{version_label} tagged '#{selector.tag}'"
|
191
196
|
end
|
197
|
+
elsif selector.latest_for_main_branch?
|
198
|
+
version_label = selector.consumer ? "version of #{selector.consumer}" : "version"
|
199
|
+
"latest #{version_label} from the main branch '#{consumer_main_branch}'"
|
192
200
|
elsif selector.latest_for_branch?
|
193
201
|
version_label = selector.consumer ? "version of #{selector.consumer}" : "version"
|
194
202
|
if selector.fallback_branch?
|
@@ -209,6 +217,7 @@ module PactBroker
|
|
209
217
|
"#{description} (#{selector.consumer_version.number})"
|
210
218
|
end
|
211
219
|
# rubocop: enable Metrics/CyclomaticComplexity
|
220
|
+
# rubocop: enable Metrics/MethodLength
|
212
221
|
|
213
222
|
def currently_deployed_selectors_description(selectors)
|
214
223
|
selectors.group_by(&:consumer).flat_map do | consumer_name, consumer_selectors |
|
@@ -253,6 +262,8 @@ module PactBroker
|
|
253
262
|
"one of #{selector.tag}"
|
254
263
|
elsif selector.currently_deployed?
|
255
264
|
"deployed to #{selector.environment.name}"
|
265
|
+
elsif selector.currently_supported?
|
266
|
+
"released in #{selector.environment.name}"
|
256
267
|
else
|
257
268
|
selector.to_json
|
258
269
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module PactBroker
|
2
|
+
module Repositories
|
3
|
+
module Scopes
|
4
|
+
def scope_for(scope)
|
5
|
+
PactBroker.policy_scope!(scope)
|
6
|
+
end
|
7
|
+
|
8
|
+
# For the times when it doesn't make sense to use the scoped class, this is a way to
|
9
|
+
# indicate that it is an intentional use
|
10
|
+
def unscoped(scope)
|
11
|
+
scope
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -243,6 +243,7 @@ module PactBroker
|
|
243
243
|
provider_id: @provider.id,
|
244
244
|
pact_version_sha: pact_version_sha,
|
245
245
|
json_content: prepare_json_content(json_content),
|
246
|
+
version: @consumer_version
|
246
247
|
)
|
247
248
|
pact_versions_count_after = PactBroker::Pacts::PactVersion.count
|
248
249
|
set_created_at_if_set(params[:created_at], :pact_publications, id: @pact.id)
|
@@ -542,7 +543,7 @@ module PactBroker
|
|
542
543
|
|
543
544
|
def create_deployed_version(uuid: , currently_deployed: , version:, environment_name: , target: nil, created_at: nil)
|
544
545
|
env = find_environment(environment_name)
|
545
|
-
@deployed_version = PactBroker::Deployments::DeployedVersionService.
|
546
|
+
@deployed_version = PactBroker::Deployments::DeployedVersionService.find_or_create(uuid, version, env, target)
|
546
547
|
PactBroker::Deployments::DeployedVersionService.record_version_undeployed(deployed_version) unless currently_deployed
|
547
548
|
set_created_at_if_set(created_at, :deployed_versions, id: deployed_version.id)
|
548
549
|
end
|
@@ -11,6 +11,7 @@ module PactBroker
|
|
11
11
|
o = OpenStruct.new(selector_hash)
|
12
12
|
o.specify_latest_tag = (o.tag && o.latest) ? "checked" : nil
|
13
13
|
o.specify_latest_branch = (o.branch && o.latest) ? "checked" : nil
|
14
|
+
o.specify_all_branch = (o.branch && !o.latest) ? "checked" : nil
|
14
15
|
o.specify_environment = o.environment_name ? "checked" : nil
|
15
16
|
o.specify_all_tagged = (o.tag && !o.latest) ? "checked" : nil
|
16
17
|
o.specify_latest = o.latest ? "checked" : nil
|
@@ -111,7 +111,7 @@
|
|
111
111
|
- if index_item.show_settings?
|
112
112
|
%span.integration-settings.kebab-horizontal{ 'aria-hidden': true }
|
113
113
|
|
114
|
-
%
|
114
|
+
%div.pagination.text-center
|
115
115
|
|
116
116
|
- pagination_locals = { page_number: page_number, page_size: page_size, pagination_record_count: pagination_record_count, current_page_size: current_page_size }
|
117
117
|
!= render :haml, :'index/_pagination', :layout => false, locals: pagination_locals
|
@@ -42,6 +42,8 @@
|
|
42
42
|
Version number ...
|
43
43
|
%option{ value: 'specify-latest-branch', selected: selector.specify_latest_branch }
|
44
44
|
Latest version from branch ...
|
45
|
+
%option{ value: 'specify-all-branch', selected: selector.specify_all_branch }
|
46
|
+
All versions from branch ...
|
45
47
|
%option{ value: 'specify-environment', selected: selector.specify_environment }
|
46
48
|
Version(s) in environment ...
|
47
49
|
%option{ value: 'specify-latest-tag', selected: selector.specify_latest_tag }
|
@@ -1,12 +1,13 @@
|
|
1
1
|
require "pact_broker/domain/verification"
|
2
2
|
|
3
|
+
# TODO delete this when AllPactPublications is deleted
|
4
|
+
|
3
5
|
module PactBroker
|
4
6
|
module Verifications
|
5
7
|
class LatestVerificationForPactVersion < PactBroker::Domain::Verification
|
6
8
|
set_dataset(:latest_verifications_for_pact_versions)
|
7
9
|
|
8
10
|
# this view doesn't have a consumer_id
|
9
|
-
# TODO add it
|
10
11
|
def consumer
|
11
12
|
PactBroker::Domain::Pacticipant.find(id: PactBroker::Pacts::AllPactPublications
|
12
13
|
.where(pact_version_id: pact_version_id)
|
@@ -14,7 +15,6 @@ module PactBroker
|
|
14
15
|
end
|
15
16
|
|
16
17
|
# this view doesn't have a provider_id
|
17
|
-
# TODO add it
|
18
18
|
def provider
|
19
19
|
PactBroker::Domain::Pacticipant.find(id: PactBroker::Pacts::AllPactPublications
|
20
20
|
.where(pact_version_id: pact_version_id)
|
@@ -67,24 +67,23 @@ module PactBroker
|
|
67
67
|
end
|
68
68
|
|
69
69
|
def search_for_latest consumer_name, provider_name
|
70
|
-
query =
|
71
|
-
|
72
|
-
|
73
|
-
query = query.consumer(consumer_name) if consumer_name
|
74
|
-
query = query.provider(provider_name) if provider_name
|
70
|
+
query = PactBroker::Domain::Verification.select_all_qualified
|
71
|
+
query = query.for_consumer_name(consumer_name) if consumer_name
|
72
|
+
query = query.for_provider_name(provider_name) if provider_name
|
75
73
|
query.reverse(:execution_date, :id).first
|
76
74
|
end
|
77
75
|
|
78
76
|
def find_latest_verifications_for_consumer_version consumer_name, consumer_version_number
|
79
77
|
# Use LatestPactPublicationsByConsumerVersion not AllPactPublcations because we don't
|
80
78
|
# want verifications for shadowed revisions as it would be misleading.
|
81
|
-
|
79
|
+
PactBroker::Domain::Verification
|
82
80
|
.select_all_qualified
|
83
|
-
.
|
84
|
-
.
|
85
|
-
.
|
86
|
-
.
|
81
|
+
.remove_verifications_for_overridden_consumer_versions
|
82
|
+
.for_consumer_name_and_consumer_version_number(consumer_name, consumer_version_number)
|
83
|
+
.latest_by_pact_version
|
84
|
+
.eager(:provider)
|
87
85
|
.all
|
86
|
+
.sort_by { | v | v.provider_name.downcase }
|
88
87
|
end
|
89
88
|
|
90
89
|
# The most recent verification for the latest revision of the pact
|
data/lib/pact_broker/version.rb
CHANGED
@@ -34,6 +34,9 @@ function showApplicableTextBoxes(selectorizor) {
|
|
34
34
|
else if( selectorizorType === 'specify-latest-branch') {
|
35
35
|
setTextboxVisibility(selectorizor, '.branch', true);
|
36
36
|
}
|
37
|
+
else if( selectorizorType === 'specify-all-branch') {
|
38
|
+
setTextboxVisibility(selectorizor, '.branch', true);
|
39
|
+
}
|
37
40
|
else if ( selectorizorType === 'specify-environment') {
|
38
41
|
setTextboxVisibility(selectorizor, '.environment', true);
|
39
42
|
}
|
@@ -29,4 +29,14 @@ describe "Creating a tag" do
|
|
29
29
|
expect(subject.status).to be 200
|
30
30
|
end
|
31
31
|
end
|
32
|
+
|
33
|
+
context "when there is an envionment with a matching name" do
|
34
|
+
before do
|
35
|
+
td.create_environment("foo")
|
36
|
+
end
|
37
|
+
|
38
|
+
it "creates a deployed version" do
|
39
|
+
expect { subject }.to change { PactBroker::Deployments::DeployedVersion.count }.by(1)
|
40
|
+
end
|
41
|
+
end
|
32
42
|
end
|
@@ -1,4 +1,3 @@
|
|
1
|
-
require "support/test_data_builder"
|
2
1
|
require "webmock/rspec"
|
3
2
|
require "rack/pact_broker/database_transaction"
|
4
3
|
|
@@ -8,7 +7,6 @@ describe "Execute a webhook" do
|
|
8
7
|
.create_webhook(method: "POST", body: "${pactbroker.pactUrl}")
|
9
8
|
end
|
10
9
|
|
11
|
-
let(:td) { TestDataBuilder.new }
|
12
10
|
let(:path) { "/webhooks/#{td.webhook.uuid}/execute" }
|
13
11
|
let(:response_body) { JSON.parse(last_response.body, symbolize_names: true)}
|
14
12
|
|
@@ -77,7 +75,7 @@ describe "Execute a webhook" do
|
|
77
75
|
PactBroker::Database.truncate
|
78
76
|
end
|
79
77
|
|
80
|
-
subject { post
|
78
|
+
subject { post(path) }
|
81
79
|
|
82
80
|
it "returns a 200 response" do
|
83
81
|
expect(subject.status).to be 200
|
@@ -11,8 +11,7 @@ describe "Get provider pacts for verification" do
|
|
11
11
|
|
12
12
|
context "when the provider exists" do
|
13
13
|
before do
|
14
|
-
|
15
|
-
.create_provider("Provider")
|
14
|
+
td.create_provider("Provider")
|
16
15
|
.create_consumer("Consumer")
|
17
16
|
.create_consumer_version("0.0.1")
|
18
17
|
.create_pact(json_content: { some: "content" }.to_json)
|
@@ -71,7 +70,10 @@ describe "Get provider pacts for verification" do
|
|
71
70
|
|
72
71
|
subject { post(path, request_body.to_json, request_headers) }
|
73
72
|
|
74
|
-
|
73
|
+
# The metadata is different when the database IDs are different
|
74
|
+
it "matches the expected body", skip: !DB.sqlite? do
|
75
|
+
Approvals.verify(fixture, :name => "get_provider_pacts_for_verification", format: :json)
|
76
|
+
end
|
75
77
|
|
76
78
|
it "returns a list of links to the pacts" do
|
77
79
|
expect(pacts.size).to eq 1
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require "webmock/rspec"
|
2
|
+
require "pact_broker/api/pact_broker_urls"
|
3
|
+
|
4
|
+
RSpec.describe "passing the pact selection criteria through the verification results to the triggered webhooks" do
|
5
|
+
before do
|
6
|
+
allow(PactBroker::Webhooks::Job).to receive(:perform_in)
|
7
|
+
end
|
8
|
+
|
9
|
+
let!(:pact) do
|
10
|
+
td.create_pact_with_hierarchy("Foo", "1", "Bar")
|
11
|
+
.create_consumer_version_tag("dev")
|
12
|
+
.create_consumer_version_tag("prod")
|
13
|
+
.create_global_verification_webhook
|
14
|
+
end
|
15
|
+
|
16
|
+
let(:verification_content) { load_fixture("verification.json") }
|
17
|
+
let(:event_context) { PactBroker::Webhooks::TriggeredWebhook.last.event_context }
|
18
|
+
|
19
|
+
context "when verifying the latest pact by URL" do
|
20
|
+
let(:pact_url) { PactBroker::Api::PactBrokerUrls.latest_pact_url("", pact) }
|
21
|
+
it "passes the consumer version number into the verification event context" do
|
22
|
+
response = get(pact_url)
|
23
|
+
publish_verification_results_url = JSON.parse(response.body)["_links"]["pb:publish-verification-results"]["href"]
|
24
|
+
post(publish_verification_results_url, verification_content, { "CONTENT_TYPE" => "application/json" })
|
25
|
+
expect(event_context["consumer_version_number"]).to eq "1"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "when verifying the latest pact for a tag by URL" do
|
30
|
+
let(:pact_url) { PactBroker::Api::PactBrokerUrls.latest_pact_url("", pact) + "/dev" }
|
31
|
+
let(:event_context) { PactBroker::Webhooks::TriggeredWebhook.last.event_context }
|
32
|
+
|
33
|
+
it "passes the consumer version number and tag into the triggered webhook event context" do
|
34
|
+
response = get(pact_url)
|
35
|
+
publish_verification_results_url = JSON.parse(response.body)["_links"]["pb:publish-verification-results"]["href"]
|
36
|
+
post(publish_verification_results_url, verification_content, { "CONTENT_TYPE" => "application/json" })
|
37
|
+
expect(event_context).to include "consumer_version_number" => "1", "consumer_version_tags" => ["dev"]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "when verifying pacts via the pacts for verification API" do
|
42
|
+
let(:request_body) do
|
43
|
+
{
|
44
|
+
consumerVersionSelectors: [ { tag: "dev", latest: true } ],
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
let(:request_headers) do
|
49
|
+
{
|
50
|
+
"CONTENT_TYPE" => "application/json",
|
51
|
+
"HTTP_ACCEPT" => "application/hal+json"
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
let(:path) { "/pacts/provider/Bar/for-verification" }
|
56
|
+
|
57
|
+
it "passes the consumer version number and tag into the triggered webhook event context" do
|
58
|
+
response = post(path, request_body.to_json, request_headers)
|
59
|
+
pact_url = JSON.parse(response.body)["_embedded"]["pacts"].first["_links"]["self"]["href"]
|
60
|
+
response = get(pact_url)
|
61
|
+
publish_verification_results_url = JSON.parse(response.body)["_links"]["pb:publish-verification-results"]["href"]
|
62
|
+
post(publish_verification_results_url, verification_content, { "CONTENT_TYPE" => "application/json" })
|
63
|
+
expect(event_context).to include "consumer_version_number" => "1", "consumer_version_tags" => ["dev"]
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|