pact_broker 2.34.0 → 2.35.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/.dockerignore +2 -0
  3. data/.github/FUNDING.yml +4 -0
  4. data/.travis.yml +1 -1
  5. data/CHANGELOG.md +34 -0
  6. data/DEVELOPER_DOCUMENTATION.md +24 -1
  7. data/DEVELOPER_SETUP.md +40 -20
  8. data/Dockerfile +22 -0
  9. data/db/migrations/000028_create_all_pact_publications.rb +0 -1
  10. data/db/migrations/20180311_optimise_head_matrix.rb +0 -1
  11. data/lib/pact/doc/doc_file.rb +0 -1
  12. data/lib/pact_broker/api/contracts/webhook_contract.rb +1 -1
  13. data/lib/pact_broker/api/decorators/decorator_context.rb +5 -5
  14. data/lib/pact_broker/api/decorators/pact_decorator.rb +0 -1
  15. data/lib/pact_broker/api/decorators/pact_pacticipant_decorator.rb +0 -1
  16. data/lib/pact_broker/api/decorators/tag_decorator.rb +0 -1
  17. data/lib/pact_broker/api/decorators/webhook_decorator.rb +0 -1
  18. data/lib/pact_broker/api/decorators/webhook_execution_result_decorator.rb +8 -5
  19. data/lib/pact_broker/api/decorators/webhook_request_template_decorator.rb +1 -4
  20. data/lib/pact_broker/api/decorators/webhooks_decorator.rb +1 -2
  21. data/lib/pact_broker/api/resources/base_resource.rb +0 -1
  22. data/lib/pact_broker/api/resources/error_handler.rb +14 -7
  23. data/lib/pact_broker/api/resources/pact.rb +4 -9
  24. data/lib/pact_broker/api/resources/pact_webhooks.rb +0 -1
  25. data/lib/pact_broker/api/resources/verifications.rb +4 -8
  26. data/lib/pact_broker/api/resources/webhook.rb +4 -8
  27. data/lib/pact_broker/api/resources/webhook_execution.rb +36 -17
  28. data/lib/pact_broker/api/resources/webhook_execution_methods.rb +13 -0
  29. data/lib/pact_broker/api/resources/webhook_resource_methods.rb +8 -15
  30. data/lib/pact_broker/api/resources/webhooks.rb +3 -12
  31. data/lib/pact_broker/api.rb +1 -1
  32. data/lib/pact_broker/app.rb +2 -0
  33. data/lib/pact_broker/domain/webhook.rb +29 -18
  34. data/lib/pact_broker/hash_refinements.rb +13 -0
  35. data/lib/pact_broker/locale/en.yml +16 -0
  36. data/lib/pact_broker/logging.rb +1 -1
  37. data/lib/pact_broker/pacts/diff.rb +0 -1
  38. data/lib/pact_broker/pacts/pact_version.rb +13 -7
  39. data/lib/pact_broker/pacts/repository.rb +4 -6
  40. data/lib/pact_broker/pacts/service.rb +3 -4
  41. data/lib/pact_broker/repositories/helpers.rb +1 -1
  42. data/lib/pact_broker/string_refinements.rb +13 -0
  43. data/lib/pact_broker/tags/repository.rb +0 -1
  44. data/lib/pact_broker/ui/views/index/_css_and_js.haml +1 -0
  45. data/lib/pact_broker/ui/views/index/show-with-tags.haml +8 -2
  46. data/lib/pact_broker/ui/views/matrix/show.haml +12 -2
  47. data/lib/pact_broker/verifications/repository.rb +0 -1
  48. data/lib/pact_broker/verifications/service.rb +7 -5
  49. data/lib/pact_broker/version.rb +1 -1
  50. data/lib/pact_broker/versions/parse_semantic_version.rb +0 -1
  51. data/lib/pact_broker/webhooks/execution.rb +0 -1
  52. data/lib/pact_broker/webhooks/execution_configuration.rb +45 -0
  53. data/lib/pact_broker/webhooks/job.rb +5 -8
  54. data/lib/pact_broker/webhooks/pact_and_verification_parameters.rb +39 -12
  55. data/lib/pact_broker/webhooks/redact_logs.rb +21 -4
  56. data/lib/pact_broker/webhooks/render.rb +11 -2
  57. data/lib/pact_broker/webhooks/repository.rb +11 -5
  58. data/lib/pact_broker/webhooks/service.rb +21 -27
  59. data/lib/pact_broker/webhooks/triggered_webhook.rb +0 -1
  60. data/lib/pact_broker/webhooks/webhook_request_logger.rb +13 -0
  61. data/lib/pact_broker/webhooks/webhook_request_template.rb +32 -18
  62. data/lib/rack/pact_broker/add_vary_header.rb +39 -0
  63. data/lib/rack/pact_broker/convert_file_extension_to_accept_header.rb +2 -0
  64. data/lib/webmachine/rack_adapter_monkey_patch.rb +0 -1
  65. data/public/javascripts/clipboard.js +73 -0
  66. data/public/javascripts/matrix.js +0 -2
  67. data/public/stylesheets/index.css +19 -0
  68. data/script/prod/clean-up.sql +11 -0
  69. data/script/query.rb +0 -1
  70. data/script/seed-matrix.rb +0 -1
  71. data/script/seed.rb +0 -1
  72. data/spec/features/delete_version_spec.rb +0 -1
  73. data/spec/features/execute_unsaved_webhook_spec.rb +56 -0
  74. data/spec/features/execute_webhook_spec.rb +2 -5
  75. data/spec/features/get_version_spec.rb +0 -1
  76. data/spec/lib/pact_broker/api/contracts/put_pact_params_contract_spec.rb +0 -1
  77. data/spec/lib/pact_broker/api/contracts/verification_contract_spec.rb +0 -1
  78. data/spec/lib/pact_broker/api/decorators/relationships_csv_decorator_spec.rb +0 -2
  79. data/spec/lib/pact_broker/api/decorators/verification_decorator_spec.rb +0 -1
  80. data/spec/lib/pact_broker/api/decorators/webhook_execution_result_decorator_spec.rb +26 -9
  81. data/spec/lib/pact_broker/api/decorators/webhook_request_template_decorator_spec.rb +3 -1
  82. data/spec/lib/pact_broker/api/decorators/webhooks_decorator_spec.rb +3 -2
  83. data/spec/lib/pact_broker/api/resources/badge_spec.rb +0 -2
  84. data/spec/lib/pact_broker/api/resources/dashboard_spec.rb +0 -1
  85. data/spec/lib/pact_broker/api/resources/error_handler_spec.rb +3 -0
  86. data/spec/lib/pact_broker/api/resources/group_spec.rb +0 -1
  87. data/spec/lib/pact_broker/api/resources/pact_spec.rb +0 -2
  88. data/spec/lib/pact_broker/api/resources/pacticipant_spec.rb +0 -1
  89. data/spec/lib/pact_broker/api/resources/tag_spec.rb +0 -2
  90. data/spec/lib/pact_broker/api/resources/verifications_spec.rb +9 -7
  91. data/spec/lib/pact_broker/api/resources/webhook_execution_spec.rb +13 -15
  92. data/spec/lib/pact_broker/api/resources/webhooks_spec.rb +0 -1
  93. data/spec/lib/pact_broker/certificates/service_spec.rb +11 -5
  94. data/spec/lib/pact_broker/domain/group_spec.rb +0 -1
  95. data/spec/lib/pact_broker/domain/webhook_spec.rb +11 -4
  96. data/spec/lib/pact_broker/feature_toggle_spec.rb +0 -1
  97. data/spec/lib/pact_broker/groups/service_spec.rb +0 -1
  98. data/spec/lib/pact_broker/hash_refinements_spec.rb +15 -0
  99. data/spec/lib/pact_broker/matrix/repository_spec.rb +0 -2
  100. data/spec/lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names_spec.rb +0 -1
  101. data/spec/lib/pact_broker/pacts/pact_version_spec.rb +16 -0
  102. data/spec/lib/pact_broker/pacts/repository_spec.rb +11 -0
  103. data/spec/lib/pact_broker/pacts/service_spec.rb +12 -5
  104. data/spec/lib/pact_broker/relationships/groupify_spec.rb +0 -2
  105. data/spec/lib/pact_broker/tags/repository_spec.rb +0 -1
  106. data/spec/lib/pact_broker/verifications/service_spec.rb +10 -3
  107. data/spec/lib/pact_broker/versions/repository_spec.rb +0 -1
  108. data/spec/lib/pact_broker/webhooks/execution_configuration_spec.rb +18 -0
  109. data/spec/lib/pact_broker/webhooks/job_spec.rb +21 -24
  110. data/spec/lib/pact_broker/webhooks/redact_logs_spec.rb +16 -5
  111. data/spec/lib/pact_broker/webhooks/repository_spec.rb +16 -1
  112. data/spec/lib/pact_broker/webhooks/service_spec.rb +23 -64
  113. data/spec/lib/pact_broker/webhooks/webhook_request_template_spec.rb +108 -24
  114. data/spec/migrations/23_pact_versions_spec.rb +3 -1
  115. data/spec/spec_helper.rb +4 -2
  116. data/spec/support/database_cleaner.rb +0 -1
  117. metadata +19 -5
  118. data/spec/support/jobs.rb +0 -12
@@ -5,10 +5,8 @@ module PactBroker
5
5
  module Api
6
6
  module Decorators
7
7
  describe WebhookExecutionResultDecorator do
8
-
9
8
  describe "to_json" do
10
-
11
- let(:webhook_execution_result) { PactBroker::Webhooks::WebhookExecutionResult.new(request, response, logs, error)}
9
+ let(:webhook_execution_result) { PactBroker::Webhooks::WebhookExecutionResult.new(request, response, logs, error) }
12
10
  let(:logs) { "logs" }
13
11
  let(:headers) { { "Something" => ["blah", "thing"]} }
14
12
  let(:request) do
@@ -20,21 +18,40 @@ module PactBroker
20
18
  let(:response) { double('http_response', code: '200', body: response_body, to_hash: headers) }
21
19
  let(:response_body) { 'body' }
22
20
  let(:error) { nil }
23
- let(:webhook) { instance_double(PactBroker::Domain::Webhook, uuid: 'some-uuid') }
21
+ let(:webhook) { instance_double(PactBroker::Domain::Webhook, uuid: uuid) }
22
+ let(:uuid) { 'some-uuid' }
24
23
  let(:show_response) { true }
25
24
  let(:json) {
26
25
  WebhookExecutionResultDecorator.new(webhook_execution_result)
27
- .to_json(user_options: { base_url: 'http://example.org', webhook: webhook, show_response: show_response })
26
+ .to_json(user_options: { resource_url: 'http://resource-url', base_url: 'http://example.org', webhook: webhook, show_response: show_response })
28
27
  }
29
28
 
30
- let(:subject) { JSON.parse(json, symbolize_names: true)}
29
+ let(:subject) { JSON.parse(json, symbolize_names: true) }
31
30
 
32
31
  it "includes a link to execute the webhook again" do
33
- expect(subject[:_links][:'try-again'][:href]).to eq 'http://example.org/webhooks/some-uuid/execute'
32
+ expect(subject[:_links][:'try-again'][:href]).to eq 'http://resource-url'
33
+ end
34
+
35
+ it "includes a success flag" do
36
+ expect(subject[:success]).to be true
37
+ end
38
+
39
+ it "includes the logs" do
40
+ expect(subject[:logs]).to eq logs
34
41
  end
35
42
 
36
- it "includes a link to the webhook" do
37
- expect(subject[:_links][:webhook][:href]).to eq 'http://example.org/webhooks/some-uuid'
43
+ context "when there is a uuid" do
44
+ it "include a link to the webhook" do
45
+ expect(subject[:_links][:webhook][:href]).to eq 'http://example.org/webhooks/some-uuid'
46
+ end
47
+ end
48
+
49
+ context "when there is a not uuid because this is an unsaved webhook" do
50
+ let(:uuid) { nil }
51
+
52
+ it "does not includes a link to the webhook" do
53
+ expect(subject[:_links]).to_not have_key(:webhook)
54
+ end
38
55
  end
39
56
 
40
57
  context "when there is an error" do
@@ -17,7 +17,9 @@ module PactBroker
17
17
  method: 'POST',
18
18
  url: 'url',
19
19
  body: 'body',
20
- headers: {})
20
+ redacted_headers: {
21
+ 'foo' => '***'
22
+ })
21
23
  end
22
24
 
23
25
  let(:json) { WebhookRequestTemplateDecorator.new(webhook_request).to_json }
@@ -9,7 +9,8 @@ module PactBroker
9
9
  let(:webhook) do
10
10
  instance_double(Domain::Webhook,
11
11
  uuid: 'some-uuid',
12
- display_description: 'description'
12
+ display_description: 'description',
13
+ scope_description: 'scope description'
13
14
  )
14
15
  end
15
16
  let(:base_url) { 'http://example.org' }
@@ -34,7 +35,7 @@ module PactBroker
34
35
 
35
36
  it "includes a list of links to the webhooks" do
36
37
  expect(subject[:_links][:'pb:webhooks']).to be_instance_of(Array)
37
- expect(subject[:_links][:'pb:webhooks'].first).to eq title: 'Webhook', name: 'description', href: 'http://example.org/webhooks/some-uuid'
38
+ expect(subject[:_links][:'pb:webhooks'].first).to eq title: 'scope description', name: 'description', href: 'http://example.org/webhooks/some-uuid'
38
39
  end
39
40
 
40
41
  it "includes curies" do
@@ -22,7 +22,6 @@ module PactBroker
22
22
  let(:verification) { double("verification", provider_version_number: "3", number: "7") }
23
23
  let(:verification_status) { instance_double("PactBroker::Verifications::Status", to_sym: :verified) }
24
24
 
25
-
26
25
  subject { get path, params, {'HTTP_ACCEPT' => 'image/svg+xml'}; last_response }
27
26
 
28
27
  context "when enable_public_badge_access is false and the request is not authenticated" do
@@ -142,7 +141,6 @@ module PactBroker
142
141
  subject
143
142
  end
144
143
 
145
-
146
144
  context "when a verification is found" do
147
145
  before do
148
146
  allow(PactBroker::Verifications::Service).to receive(:find_latest_verification_for_tags).and_return(verification)
@@ -9,7 +9,6 @@ module PactBroker
9
9
  let(:path) { "/dashboard" }
10
10
  subject { get path; last_response }
11
11
 
12
-
13
12
  end
14
13
  end
15
14
  end
@@ -9,6 +9,7 @@ module PactBroker
9
9
  before do
10
10
  allow(ErrorHandler).to receive(:logger).and_return(logger)
11
11
  allow(SecureRandom).to receive(:urlsafe_base64).and_return("bYWfn-+yWPlf")
12
+ allow(error).to receive(:backtrace).and_return(["backtrace"])
12
13
  end
13
14
 
14
15
  let(:logger) { double('logger').as_null_object }
@@ -71,6 +72,7 @@ module PactBroker
71
72
  subject
72
73
  end
73
74
  end
75
+
74
76
  context "when the error is not a PactBroker::Error or subclass" do
75
77
  it "invokes the api error reporters" do
76
78
  expect(thing).to receive(:call).with(error, options)
@@ -120,6 +122,7 @@ module PactBroker
120
122
  subject
121
123
  end
122
124
  end
125
+
123
126
  context "when the error is not a PactBroker::Error or subclass" do
124
127
  it "invokes the api error reporters" do
125
128
  expect(thing).to receive(:call).with(error, options)
@@ -72,7 +72,6 @@ module PactBroker::Api
72
72
  end
73
73
  end
74
74
 
75
-
76
75
  end
77
76
 
78
77
  end
@@ -4,7 +4,6 @@ require 'rack/test'
4
4
  require 'pact_broker/pacts/service'
5
5
  require 'pact_broker/pacticipants/service'
6
6
 
7
-
8
7
  module PactBroker::Api
9
8
  module Resources
10
9
  describe Pact do
@@ -59,7 +58,6 @@ module PactBroker::Api
59
58
  end
60
59
  end
61
60
 
62
-
63
61
  shared_examples "an update endpoint" do |http_method|
64
62
  subject { self.send http_method, "/pacts/provider/Provider/consumer/Consumer/version/1.2.3", json, {'CONTENT_TYPE' => "application/json"} ; last_response }
65
63
 
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
  require 'pact_broker/api/resources/pacticipant'
3
3
 
4
-
5
4
  module PactBroker::Api
6
5
 
7
6
  module Resources
@@ -138,7 +138,6 @@ module PactBroker
138
138
  allow(Tags::Service).to receive(:create).and_return(tag)
139
139
  end
140
140
 
141
-
142
141
  it "creates the tag" do
143
142
  expect(Tags::Service).to receive(:create).with(hash_including(tag_attributes))
144
143
  subject
@@ -157,7 +156,6 @@ module PactBroker
157
156
 
158
157
  end
159
158
 
160
-
161
159
  end
162
160
 
163
161
  end
@@ -19,11 +19,14 @@ module PactBroker
19
19
  let(:errors_empty) { true }
20
20
  let(:parsed_metadata) { { the: 'metadata' } }
21
21
  let(:base_url) { "http://example.org" }
22
+ let(:webhook_execution_configuration) { instance_double(PactBroker::Webhooks::ExecutionConfiguration) }
22
23
 
23
24
  before do
24
25
  allow(PactBroker::Verifications::Service).to receive(:create).and_return(verification)
25
26
  allow(PactBroker::Verifications::Service).to receive(:errors).and_return(double(:errors, messages: ['errors'], empty?: errors_empty))
26
27
  allow(PactBrokerUrls).to receive(:parse_webhook_metadata).and_return(parsed_metadata)
28
+ allow_any_instance_of(Verifications).to receive(:webhook_execution_configuration).and_return(webhook_execution_configuration)
29
+ allow(webhook_execution_configuration).to receive(:with_webhook_context).and_return(webhook_execution_configuration)
27
30
  end
28
31
 
29
32
  subject { post url, request_body, rack_env; last_response }
@@ -74,19 +77,18 @@ module PactBroker
74
77
  expect(subject.headers['Location']).to eq("http://example.org/pacts/provider/Provider/consumer/Consumer/pact-version/1234/verification-results/2")
75
78
  end
76
79
 
80
+ it "merges the upstream verification metdata into the webhook context" do
81
+ expect(webhook_execution_configuration).to receive(:with_webhook_context).with(parsed_metadata)
82
+ subject
83
+ end
84
+
77
85
  it "stores the verification in the database" do
78
86
  expect(PactBroker::Verifications::Service).to receive(:create).with(
79
87
  next_verification_number,
80
88
  hash_including('some' => 'params'),
81
89
  pact,
82
90
  {
83
- logging_options: {
84
- show_response: 'some-boolean'
85
- },
86
- webhook_context: {
87
- the: 'metadata',
88
- base_url: base_url,
89
- },
91
+ webhook_execution_configuration: webhook_execution_configuration,
90
92
  database_connector: database_connector
91
93
  }
92
94
  )
@@ -4,11 +4,8 @@ require 'pact_broker/api/resources/webhook_execution'
4
4
  module PactBroker
5
5
  module Api
6
6
  module Resources
7
-
8
7
  describe WebhookExecution do
9
-
10
8
  describe "POST" do
11
-
12
9
  before do
13
10
  allow(PactBroker::Webhooks::Service).to receive(:find_by_uuid).and_return(webhook)
14
11
  end
@@ -33,28 +30,29 @@ module PactBroker
33
30
  let(:pact) { instance_double("PactBroker::Domain::Pact") }
34
31
  let(:consumer_name) { "foo" }
35
32
  let(:provider_name) { "bar" }
36
- let(:webhook_options) do
37
- {
38
- logging_options: {
39
- show_response: false,
40
- },
41
- webhook_context: {
42
- base_url: "http://example.org"
43
- }
44
- }
45
- end
33
+ let(:webhook_execution_configuration) { instance_double(PactBroker::Webhooks::ExecutionConfiguration) }
46
34
 
47
35
  before do
48
36
  allow(PactBroker::Webhooks::Service).to receive(:test_execution).and_return(execution_result)
49
37
  allow(PactBroker::Api::Decorators::WebhookExecutionResultDecorator).to receive(:new).and_return(decorator)
38
+ allow_any_instance_of(WebhookExecution).to receive(:webhook_execution_configuration).and_return(webhook_execution_configuration)
50
39
  end
51
40
 
52
41
  it "executes the webhook" do
53
- expect(PactBroker::Webhooks::Service).to receive(:test_execution).with(webhook, webhook_options)
42
+ expect(PactBroker::Webhooks::Service).to receive(:test_execution).with(webhook, webhook_execution_configuration)
54
43
  subject
55
44
  end
56
45
 
57
46
  context "when execution is successful" do
47
+ let(:expected_user_options) do
48
+ {
49
+ resource_url: 'http://example.org/webhooks/some-uuid/execute',
50
+ base_url: 'http://example.org',
51
+ webhook: webhook,
52
+ show_response: 'foo',
53
+ }
54
+ end
55
+
58
56
  it "returns a 200 JSON response" do
59
57
  subject
60
58
  expect(last_response).to be_a_hal_json_success_response
@@ -62,7 +60,7 @@ module PactBroker
62
60
 
63
61
  it "generates a JSON response body for the execution result" do
64
62
  allow(PactBroker.configuration).to receive(:show_webhook_response?).and_return('foo')
65
- expect(decorator).to receive(:to_json).with(user_options: { base_url: 'http://example.org', webhook: webhook, show_response: 'foo' })
63
+ expect(decorator).to receive(:to_json).with(user_options: expected_user_options)
66
64
  subject
67
65
  end
68
66
 
@@ -171,7 +171,6 @@ module PactBroker::Api
171
171
  end
172
172
  end
173
173
 
174
-
175
174
  context "with invalid attributes" do
176
175
 
177
176
  let(:valid) { false }
@@ -4,7 +4,7 @@ module PactBroker
4
4
  module Certificates
5
5
  describe Service do
6
6
  let(:certificate_content) { File.read('spec/fixtures/certificate.pem') }
7
- let(:logger) { double('logger').as_null_object }
7
+ let(:logger) { spy('logger') }
8
8
 
9
9
  before do
10
10
  allow(Service).to receive(:logger).and_return(logger)
@@ -17,19 +17,25 @@ module PactBroker
17
17
  expect(subject).to be_instance_of(OpenSSL::X509::Store)
18
18
  end
19
19
 
20
- context "when there is a duplicate certificate" do
20
+ context "when there is an error adding certificate" do
21
+ let(:cert_store) { instance_spy(OpenSSL::X509::Store) }
22
+
21
23
  before do
22
24
  Certificate.create(uuid: '1234', content: certificate_content)
23
- Certificate.create(uuid: '5678', content: certificate_content)
25
+
26
+ allow(cert_store).to receive(:add_cert).and_raise(StandardError)
27
+ allow(OpenSSL::X509::Store).to receive(:new).and_return(cert_store)
24
28
  end
25
29
 
26
30
  it "logs the error" do
27
- expect(Service).to receive(:log_error).with(anything, /Error adding certificate/).at_least(1).times
28
31
  subject
32
+
33
+ expect(logger).to have_received(:error)
34
+ .with(/Error adding certificate/).at_least(1).times
29
35
  end
30
36
 
31
37
  it "returns an OpenSSL::X509::Store" do
32
- expect(subject).to be_instance_of(OpenSSL::X509::Store)
38
+ expect(subject).to be(cert_store)
33
39
  end
34
40
  end
35
41
  end
@@ -6,7 +6,6 @@ module PactBroker
6
6
  module Domain
7
7
  describe Group do
8
8
 
9
-
10
9
  describe "#include_pacticipant" do
11
10
 
12
11
  let(:consumer_a) { double('consumer a') }
@@ -8,6 +8,8 @@ module PactBroker
8
8
  let(:provider) { Pacticipant.new(name: 'Provider')}
9
9
  let(:request_template) { instance_double(PactBroker::Webhooks::WebhookRequestTemplate, build: webhook_request)}
10
10
  let(:webhook_request) { instance_double(PactBroker::Domain::WebhookRequest, execute: http_response, http_request: http_request) }
11
+ let(:webhook_template_parameters) { instance_double(PactBroker::Webhooks::PactAndVerificationParameters, to_hash: webhook_template_parameters_hash) }
12
+ let(:webhook_template_parameters_hash) { { 'foo' => 'bar' } }
11
13
  let(:http_request) { double('http request') }
12
14
  let(:http_response) { double('http response') }
13
15
  let(:webhook_context) { { some: 'things' } }
@@ -19,6 +21,7 @@ module PactBroker
19
21
 
20
22
  before do
21
23
  allow(webhook).to receive(:logger).and_return(logger)
24
+ allow(PactBroker::Webhooks::PactAndVerificationParameters).to receive(:new).and_return(webhook_template_parameters)
22
25
  end
23
26
 
24
27
  subject(:webhook) { Webhook.new(uuid: uuid, request: request_template, consumer: consumer, provider: provider) }
@@ -60,11 +63,15 @@ module PactBroker
60
63
 
61
64
  let(:execute) { subject.execute pact, verification, options }
62
65
 
66
+ it "creates the template parameters" do
67
+ expect(PactBroker::Webhooks::PactAndVerificationParameters).to receive(:new).with(
68
+ pact, verification, webhook_context
69
+ )
70
+ execute
71
+ end
72
+
63
73
  it "builds the request" do
64
- expect(request_template).to receive(:build).with(
65
- pact: pact,
66
- verification: verification,
67
- webhook_context: webhook_context)
74
+ expect(request_template).to receive(:build).with(webhook_template_parameters_hash)
68
75
  execute
69
76
  end
70
77
 
@@ -60,7 +60,6 @@ module PactBroker
60
60
  it { is_expected.to be true }
61
61
  end
62
62
 
63
-
64
63
  context "when PACT_BROKER_FEATURES does not include the given string" do
65
64
  before do
66
65
  allow(ENV).to receive(:[]).with('PACT_BROKER_FEATURES').and_return(nil)
@@ -7,7 +7,6 @@ module PactBroker
7
7
  module Groups
8
8
  describe Service do
9
9
 
10
-
11
10
  describe "#find_group_containing" do
12
11
 
13
12
  let(:consumer_a) { double('consumer a', name: 'consumer a', id: 1)}
@@ -0,0 +1,15 @@
1
+ require 'pact_broker/hash_refinements'
2
+
3
+ module PactBroker
4
+ describe HashRefinements do
5
+ using HashRefinements
6
+
7
+ let(:a) { { a: 1, b: { c: 3 }, d: 5, e: nil } }
8
+ let(:b) { { a: 2, b: { c: 4 } } }
9
+ let(:expected) { { a: 2, b: { c: 4 }, d: 5, e: nil } }
10
+
11
+ it "merges" do
12
+ expect(a.deep_merge(b)).to eq expected
13
+ end
14
+ end
15
+ end
@@ -44,7 +44,6 @@ module PactBroker
44
44
  subject { shorten_rows(rows) }
45
45
  let(:rows) { Repository.new.find(selectors, options) }
46
46
 
47
-
48
47
  let(:options) { { latestby: latestby } }
49
48
  let(:latestby) { nil }
50
49
  let(:a1_b1_n1) { "A1 B1 n1" }
@@ -784,7 +783,6 @@ module PactBroker
784
783
  end
785
784
  end
786
785
 
787
-
788
786
  end
789
787
 
790
788
  describe "#find_for_consumer_and_provider" do
@@ -30,7 +30,6 @@ module PactBroker
30
30
 
31
31
  subject { FindPotentialDuplicatePacticipantNames.call(new_name, existing_names) }
32
32
 
33
-
34
33
  CALL_TEST_CASES = [
35
34
  ["accounts", ["accounts-receivable"], []],
36
35
  ["Accounts", ["Accounts Receivable"], []],
@@ -92,6 +92,22 @@ module PactBroker
92
92
  expect(PactVersion.first.latest_consumer_version_number).to eq "1.0.1"
93
93
  end
94
94
  end
95
+
96
+ describe "#latest_verification" do
97
+ before do
98
+ td.create_pact_with_hierarchy
99
+ .create_verification
100
+ .create_verification(number: 2)
101
+ .create_verification(number: 3)
102
+ end
103
+ let(:pact_version) { PactVersion.last }
104
+
105
+ subject { pact_version.latest_verification }
106
+
107
+ it "returns the latest verification by execution date" do
108
+ expect(subject.number).to eq 3
109
+ end
110
+ end
95
111
  end
96
112
  end
97
113
  end
@@ -88,6 +88,17 @@ module PactBroker
88
88
  it "reuses the same PactVersion to save room" do
89
89
  expect { subject }.to_not change{ PactVersion.count }
90
90
  end
91
+
92
+ context "when there is a race condition and the pact version gets created by another request in between attempting to find and create" do
93
+ before do
94
+ allow(PactVersion).to receive(:find).and_return(nil)
95
+ end
96
+
97
+ it "doesn't blow up" do
98
+ expect(PactVersion).to receive(:find)
99
+ subject
100
+ end
101
+ end
91
102
  end
92
103
 
93
104
  context "when base_equality_only_on_content_that_affects_verification_results is true" do
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'pact_broker/pacts/service'
3
3
  require 'pact_broker/pacts/pact_params'
4
-
4
+ require 'pact_broker/webhooks/execution_configuration'
5
5
 
6
6
  module PactBroker
7
7
 
@@ -47,13 +47,15 @@ module PactBroker
47
47
  end
48
48
  let(:content) { double('content') }
49
49
  let(:content_with_interaction_ids) { double('content_with_interaction_ids', to_json: json_content_with_ids) }
50
- let(:webhook_options) { { the: 'options'} }
51
- let(:outgoing_webhook_options) { { the: 'options', webhook_context: { consumer_version_tags: %[dev] }} }
50
+ let(:webhook_options) { { webhook_execution_configuration: webhook_execution_configuration } }
51
+ let(:webhook_execution_configuration) { instance_double(PactBroker::Webhooks::ExecutionConfiguration) }
52
+
52
53
 
53
54
  before do
54
55
  allow(Content).to receive(:from_json).and_return(content)
55
56
  allow(content).to receive(:with_ids).and_return(content_with_interaction_ids)
56
57
  allow(PactBroker::Pacts::GenerateSha).to receive(:call).and_call_original
58
+ allow(webhook_execution_configuration).to receive(:with_webhook_context).and_return(webhook_execution_configuration)
57
59
  end
58
60
 
59
61
  subject { Service.create_or_update_pact(params, webhook_options) }
@@ -70,8 +72,13 @@ module PactBroker
70
72
  subject
71
73
  end
72
74
 
75
+ it "sets the consumer version tags" do
76
+ expect(webhook_execution_configuration).to receive(:with_webhook_context).with(consumer_version_tags: %[dev]).and_return(webhook_execution_configuration)
77
+ subject
78
+ end
79
+
73
80
  it "triggers webhooks" do
74
- expect(webhook_trigger_service).to receive(:trigger_webhooks_for_new_pact).with(new_pact, outgoing_webhook_options)
81
+ expect(webhook_trigger_service).to receive(:trigger_webhooks_for_new_pact).with(new_pact, webhook_options)
75
82
  subject
76
83
  end
77
84
  end
@@ -97,7 +104,7 @@ module PactBroker
97
104
  end
98
105
 
99
106
  it "triggers webhooks" do
100
- expect(webhook_trigger_service).to receive(:trigger_webhooks_for_updated_pact).with(existing_pact, new_pact, outgoing_webhook_options)
107
+ expect(webhook_trigger_service).to receive(:trigger_webhooks_for_updated_pact).with(existing_pact, new_pact, webhook_options)
101
108
  subject
102
109
  end
103
110
  end
@@ -23,14 +23,12 @@ module PactBroker
23
23
  let(:provider_y) { double('provider y', id: 8, name: 'provider y') }
24
24
  let(:provider_z) { double('provider z', id: 9, name: 'provider z') }
25
25
 
26
-
27
26
  let(:relationship_1) { Domain::IndexItem.new(consumer_a, provider_x) }
28
27
  let(:relationship_4) { Domain::IndexItem.new(consumer_a, provider_y) }
29
28
  let(:relationship_2) { Domain::IndexItem.new(consumer_b, provider_y) }
30
29
 
31
30
  let(:relationship_3) { Domain::IndexItem.new(consumer_c, provider_z) }
32
31
 
33
-
34
32
  let(:relationship_5) { Domain::IndexItem.new(consumer_l, provider_p) }
35
33
  let(:relationship_6) { Domain::IndexItem.new(consumer_m, provider_p) }
36
34
 
@@ -117,7 +117,6 @@ module PactBroker
117
117
  end
118
118
  end
119
119
 
120
-
121
120
  describe "find_all_tag_names_for_pacticipant" do
122
121
  before do
123
122
  td.create_consumer("Foo")
@@ -1,5 +1,6 @@
1
1
  require 'pact_broker/verifications/service'
2
2
  require 'pact_broker/verifications/repository'
3
+ require 'pact_broker/webhooks/execution_configuration'
3
4
 
4
5
  module PactBroker
5
6
 
@@ -16,10 +17,11 @@ module PactBroker
16
17
  describe "#create" do
17
18
  before do
18
19
  allow(PactBroker::Webhooks::Service).to receive(:trigger_webhooks)
20
+ allow(webhook_execution_configuration).to receive(:with_webhook_context).and_return(webhook_execution_configuration)
19
21
  end
20
22
 
21
- let(:options) { { webhook_context: {} } }
22
- let(:expected_options) { { webhook_context: { provider_version_tags: %w[dev] } } }
23
+ let(:options) { { webhook_execution_configuration: webhook_execution_configuration } }
24
+ let(:webhook_execution_configuration) { instance_double(PactBroker::Webhooks::ExecutionConfiguration) }
23
25
  let(:params) { {'success' => true, 'providerApplicationVersion' => '4.5.6'} }
24
26
  let(:pact) do
25
27
  td.create_pact_with_hierarchy
@@ -52,13 +54,18 @@ module PactBroker
52
54
  expect(verification.provider_version_number).to eq '4.5.6'
53
55
  end
54
56
 
57
+ it "sets the provider version tags on the webhook execution configuration" do
58
+ expect(webhook_execution_configuration).to receive(:with_webhook_context).with(provider_version_tags: %w[dev])
59
+ create_verification
60
+ end
61
+
55
62
  it "invokes the webhooks for the verification" do
56
63
  verification = create_verification
57
64
  expect(PactBroker::Webhooks::Service).to have_received(:trigger_webhooks).with(
58
65
  pact,
59
66
  verification,
60
67
  PactBroker::Webhooks::WebhookEvent::VERIFICATION_PUBLISHED,
61
- expected_options
68
+ options
62
69
  )
63
70
  end
64
71
  end
@@ -9,7 +9,6 @@ module PactBroker
9
9
  let(:pacticipant_name) { "test_pacticipant" }
10
10
  let(:version_number) { "1.2.3" }
11
11
 
12
-
13
12
  describe "#find_by_pacticipant_name_and_latest_tag" do
14
13
  before do
15
14
  td.create_consumer("Bar")
@@ -0,0 +1,18 @@
1
+ require 'pact_broker/webhooks/execution_configuration'
2
+
3
+ module PactBroker
4
+ module Webhooks
5
+ describe ExecutionConfiguration do
6
+ subject { ExecutionConfiguration.new }
7
+
8
+ it "returns a new object with the updated value" do
9
+ expect(subject.with_show_response(true)[:logging_options][:show_response]).to eq true
10
+ expect(subject.with_show_response(false)[:logging_options][:show_response]).to eq false
11
+ end
12
+
13
+ it "deep merges webhook context" do
14
+ expect(subject.with_webhook_context(a: 1, b: 1).with_webhook_context(b: 2)[:webhook_context]).to eq a: 1, b: 2
15
+ end
16
+ end
17
+ end
18
+ end