pact_broker-client 1.75.3 → 1.75.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +7 -0
  3. data/lib/pact_broker/client/version.rb +1 -1
  4. metadata +5 -216
  5. data/.github/workflows/test.yml +0 -59
  6. data/.rspec +0 -3
  7. data/lib/pact_broker/client/pacts/list_latest_versions.rb +0 -66
  8. data/lib/pact_broker/client/webhooks/test.rb +0 -16
  9. data/pact-broker-client.gemspec +0 -31
  10. data/spec/fixtures/MyConsumer-MyProvider (1).json +0 -37
  11. data/spec/fixtures/MyConsumer-MyProvider.json +0 -37
  12. data/spec/fixtures/approvals/can_i_deploy_failure_dry_run.approved.txt +0 -7
  13. data/spec/fixtures/approvals/can_i_deploy_ignore.approved.txt +0 -13
  14. data/spec/fixtures/approvals/can_i_deploy_success_dry_run.approved.txt +0 -7
  15. data/spec/fixtures/approvals/describe_environment.approved.txt +0 -7
  16. data/spec/fixtures/approvals/describe_pacticipant.approved.txt +0 -2
  17. data/spec/fixtures/approvals/list_environments.approved.txt +0 -3
  18. data/spec/fixtures/approvals/publish_provider_contract.approved.txt +0 -2
  19. data/spec/fixtures/certificates/ca_cert.pem +0 -19
  20. data/spec/fixtures/certificates/ca_cert.srl +0 -1
  21. data/spec/fixtures/certificates/ca_key.pem +0 -28
  22. data/spec/fixtures/certificates/client_cert.pem +0 -17
  23. data/spec/fixtures/certificates/key.pem +0 -28
  24. data/spec/fixtures/certificates/server.csr +0 -15
  25. data/spec/fixtures/certificates/unsigned_cert.pem +0 -19
  26. data/spec/fixtures/certificates/unsigned_key.pem +0 -28
  27. data/spec/fixtures/foo-bar.json +0 -31
  28. data/spec/integration/can_i_deploy_spec.rb +0 -24
  29. data/spec/integration/can_i_merge_spec.rb +0 -44
  30. data/spec/integration/create_version_tag_spec.rb +0 -20
  31. data/spec/integration/describe_environment_spec.rb +0 -31
  32. data/spec/integration/publish_provider_contract_spec.rb +0 -53
  33. data/spec/integration/unknown_options_spec.rb +0 -39
  34. data/spec/lib/pact_broker/client/base_client_spec.rb +0 -182
  35. data/spec/lib/pact_broker/client/branches/delete_branch_spec.rb +0 -103
  36. data/spec/lib/pact_broker/client/can_i_deploy_spec.rb +0 -250
  37. data/spec/lib/pact_broker/client/cli/broker_can_i_deploy_spec.rb +0 -196
  38. data/spec/lib/pact_broker/client/cli/broker_create_or_update_webhook_spec.rb +0 -23
  39. data/spec/lib/pact_broker/client/cli/broker_create_webhook_spec.rb +0 -23
  40. data/spec/lib/pact_broker/client/cli/broker_publish_spec.rb +0 -327
  41. data/spec/lib/pact_broker/client/cli/broker_run_webhook_commands_spec.rb +0 -287
  42. data/spec/lib/pact_broker/client/cli/custom_thor_spec.rb +0 -174
  43. data/spec/lib/pact_broker/client/cli/version_selector_options_parser_spec.rb +0 -97
  44. data/spec/lib/pact_broker/client/deployments/record_deployment_spec.rb +0 -224
  45. data/spec/lib/pact_broker/client/deployments/record_support_ended_spec.rb +0 -208
  46. data/spec/lib/pact_broker/client/deployments/record_undeployment_spec.rb +0 -227
  47. data/spec/lib/pact_broker/client/environments/delete_environment_spec.rb +0 -120
  48. data/spec/lib/pact_broker/client/environments/describe_environment_spec.rb +0 -89
  49. data/spec/lib/pact_broker/client/environments/update_environment_spec.rb +0 -167
  50. data/spec/lib/pact_broker/client/generate_display_name_spec.rb +0 -39
  51. data/spec/lib/pact_broker/client/git_spec.rb +0 -159
  52. data/spec/lib/pact_broker/client/hal/authorization_header_redactor_spec.rb +0 -17
  53. data/spec/lib/pact_broker/client/hal/entity_spec.rb +0 -149
  54. data/spec/lib/pact_broker/client/hal/http_client_spec.rb +0 -238
  55. data/spec/lib/pact_broker/client/hal/link_spec.rb +0 -127
  56. data/spec/lib/pact_broker/client/matrix/abbreviate_version_number_spec.rb +0 -42
  57. data/spec/lib/pact_broker/client/matrix/resource_spec.rb +0 -70
  58. data/spec/lib/pact_broker/client/matrix/text_formatter_spec.rb +0 -63
  59. data/spec/lib/pact_broker/client/matrix_spec.rb +0 -17
  60. data/spec/lib/pact_broker/client/merge_pacts_spec.rb +0 -198
  61. data/spec/lib/pact_broker/client/pact_broker_client_spec.rb +0 -47
  62. data/spec/lib/pact_broker/client/pacticipants/create_spec.rb +0 -31
  63. data/spec/lib/pact_broker/client/pacticipants_spec.rb +0 -18
  64. data/spec/lib/pact_broker/client/publish_pacts_the_old_way_spec.rb +0 -272
  65. data/spec/lib/pact_broker/client/retry_spec.rb +0 -119
  66. data/spec/lib/pact_broker/client/tasks/publication_task_spec.rb +0 -231
  67. data/spec/lib/pact_broker/client/versions/create_spec.rb +0 -174
  68. data/spec/lib/pact_broker/client/versions/describe_spec.rb +0 -64
  69. data/spec/lib/pact_broker/client/versions_spec.rb +0 -34
  70. data/spec/lib/pact_broker/client/webhooks/create_spec.rb +0 -99
  71. data/spec/lib/pactflow/client/provider_contracts/publish_spec.rb +0 -179
  72. data/spec/pacts/pact_broker_client-pact_broker.json +0 -2969
  73. data/spec/pacts/pact_broker_client-pactflow.json +0 -288
  74. data/spec/readme_spec.rb +0 -16
  75. data/spec/service_providers/create_environment_spec.rb +0 -78
  76. data/spec/service_providers/delete_branch_spec.rb +0 -68
  77. data/spec/service_providers/extra_goodies_spec.rb +0 -108
  78. data/spec/service_providers/list_environments_spec.rb +0 -77
  79. data/spec/service_providers/list_latest_pact_versions_spec.rb.bak +0 -44
  80. data/spec/service_providers/pact_broker_client_matrix_ignore_spec.rb +0 -98
  81. data/spec/service_providers/pact_broker_client_matrix_spec.rb +0 -292
  82. data/spec/service_providers/pact_broker_client_pacticipant_version_spec.rb +0 -56
  83. data/spec/service_providers/pact_broker_client_publish_spec.rb +0 -135
  84. data/spec/service_providers/pact_broker_client_register_repository_spec.rb +0 -49
  85. data/spec/service_providers/pact_broker_client_retrieve_all_pacts_for_provider_spec.rb +0 -53
  86. data/spec/service_providers/pact_broker_client_retrieve_pact_spec.rb +0 -109
  87. data/spec/service_providers/pact_broker_client_tags_spec.rb +0 -101
  88. data/spec/service_providers/pact_broker_client_versions_spec.rb +0 -113
  89. data/spec/service_providers/pact_helper.rb +0 -136
  90. data/spec/service_providers/pactflow_publish_provider_contract_spec.rb +0 -137
  91. data/spec/service_providers/pactflow_publish_provider_contract_the_old_way_spec.rb +0 -129
  92. data/spec/service_providers/pactflow_webhooks_create_spec.rb +0 -86
  93. data/spec/service_providers/pacticipants_create_spec.rb +0 -119
  94. data/spec/service_providers/publish_pacts_spec.rb +0 -114
  95. data/spec/service_providers/record_deployment_spec.rb +0 -199
  96. data/spec/service_providers/record_release_spec.rb +0 -130
  97. data/spec/service_providers/record_undeployment_spec.rb +0 -164
  98. data/spec/service_providers/webhooks_create_spec.rb +0 -391
  99. data/spec/spec_helper.rb +0 -68
  100. data/spec/support/approvals.rb +0 -26
  101. data/spec/support/cli_test_pacts/bar.json +0 -0
  102. data/spec/support/cli_test_pacts/foo.json +0 -0
  103. data/spec/support/latest_pacts_for_provider.json +0 -15
  104. data/spec/support/matrix.json +0 -35
  105. data/spec/support/matrix.txt +0 -3
  106. data/spec/support/matrix_error.txt +0 -3
  107. data/spec/support/matrix_with_results.txt +0 -10
  108. data/spec/support/pacticipant_get.json +0 -18
  109. data/spec/support/pacticipants_list.json +0 -26
  110. data/spec/support/pacts_latest_list.json +0 -41
  111. data/spec/support/shared_context.rb +0 -25
  112. data/spec/support/ssl_server.rb +0 -42
@@ -1,130 +0,0 @@
1
- require 'service_providers/pact_helper'
2
- require 'pact_broker/client/deployments/record_deployment'
3
-
4
- RSpec.describe "recording a release", pact: true do
5
- include_context "pact broker"
6
- include PactBrokerPactHelperMethods
7
-
8
- let(:pacticipant_name) { "Foo" }
9
- let(:version_number) { "5556b8149bf8bac76bc30f50a8a2dd4c22c85f30" }
10
- let(:environment_name) { "test" }
11
- let(:output) { "text" }
12
- let(:target) { "blue" }
13
- let(:params) do
14
- {
15
- pacticipant_name: pacticipant_name,
16
- version_number: version_number,
17
- environment_name: environment_name
18
- }
19
- end
20
- let(:options) do
21
- {
22
- output: output
23
- }
24
- end
25
- let(:pact_broker_client_options) { { pact_broker_base_url: broker_base_url } }
26
-
27
- subject { PactBroker::Client::Deployments::RecordRelease.call(params, options, pact_broker_client_options) }
28
-
29
- def mock_index
30
- pact_broker
31
- .given("the pb:pacticipant-version and pb:environments relations exist in the index resource")
32
- .upon_receiving("a request for the index resource")
33
- .with(
34
- method: "GET",
35
- path: '/',
36
- headers: get_request_headers).
37
- will_respond_with(
38
- status: 200,
39
- headers: pact_broker_response_headers,
40
- body: {
41
- _links: {
42
- :'pb:pacticipant-version' => {
43
- href: placeholder_url_term("pb:pacticipant-version", ["pacticipant", "version"])
44
- },
45
- :'pb:environments' => {
46
- href: placeholder_url_term("pb:environments")
47
- }
48
- }
49
- }
50
- )
51
- end
52
-
53
- def mock_pacticipant_version_with_test_environment_available_for_release
54
- pact_broker
55
- .given("version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 of pacticipant Foo exists with a test environment available for release")
56
- .upon_receiving("a request for a pacticipant version")
57
- .with(
58
- method: "GET",
59
- path: "/HAL-REL-PLACEHOLDER-PB-PACTICIPANT-VERSION-Foo-5556b8149bf8bac76bc30f50a8a2dd4c22c85f30",
60
- headers: get_request_headers
61
- )
62
- .will_respond_with(
63
- status: 200,
64
- headers: pact_broker_response_headers,
65
- body: {
66
- _links: {
67
- "pb:record-release" => [
68
- {
69
- name: "test",
70
- href: placeholder_url_term("pb:record-release-#{pacticipant_name}-#{version_number}-#{environment_name}")
71
- }
72
- ]
73
- }
74
- }
75
- )
76
- end
77
-
78
- def mock_environments
79
- pact_broker
80
- .given("an environment with name test exists")
81
- .upon_receiving("a request for the environments")
82
- .with(
83
- method: "GET",
84
- path: "/HAL-REL-PLACEHOLDER-PB-ENVIRONMENTS",
85
- headers: get_request_headers
86
- )
87
- .will_respond_with(
88
- status: 200,
89
- headers: pact_broker_response_headers,
90
- body: {
91
- _links: {
92
- "pb:environments" => [
93
- {
94
- name: "test",
95
- href: Pact.like("href")
96
- }
97
- ]
98
- }
99
- }
100
- )
101
- end
102
-
103
- def mock_record_release
104
- pact_broker
105
- .given("version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 of pacticipant Foo exists with a test environment available for deployment")
106
- .upon_receiving("a request to record a release")
107
- .with(
108
- method: "POST",
109
- path: "/HAL-REL-PLACEHOLDER-PB-RECORD-RELEASE-FOO-5556B8149BF8BAC76BC30F50A8A2DD4C22C85F30-TEST",
110
- headers: post_request_headers
111
- )
112
- .will_respond_with(
113
- status: 201,
114
- headers: pact_broker_response_headers
115
- )
116
- end
117
-
118
- context "when the deployment is recorded successfully" do
119
- before do
120
- mock_index
121
- mock_pacticipant_version_with_test_environment_available_for_release
122
- mock_record_release
123
- end
124
-
125
- it "returns a success message" do
126
- expect(subject.success).to be true
127
- expect(subject.message).to include "Recorded release of Foo version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 to test environment in the Pact Broker."
128
- end
129
- end
130
- end
@@ -1,164 +0,0 @@
1
- require 'service_providers/pact_helper'
2
- require 'pact_broker/client/deployments/record_undeployment'
3
-
4
- RSpec.describe "recording an undeployment", pact: true do
5
- include_context "pact broker"
6
- include PactBrokerPactHelperMethods
7
-
8
- let(:pacticipant_name) { "Foo" }
9
- let(:environment_name) { "test" }
10
- let(:output) { "text" }
11
- let(:application_instance) { "customer-1" }
12
- let(:params) do
13
- {
14
- pacticipant_name: pacticipant_name,
15
- environment_name: environment_name,
16
- application_instance: application_instance
17
- }
18
- end
19
- let(:options) do
20
- {
21
- output: output,
22
- verbose: true
23
- }
24
- end
25
- let(:webmock_base_url) { "http://broker" }
26
- let(:pact_broker_client_options) { { pact_broker_base_url: webmock_base_url } }
27
- let(:test_environment_placeholder_path) { "/HAL-REL-PLACEHOLDER-PB-ENVIRONMENT-16926ef3-590f-4e3f-838e-719717aa88c9" }
28
- let(:currently_deployed_versions_placeholder_path) { "/PLACEHOLDER-ENVIRONMENT-CURRENTLY-DEPLOYED-16926ef3-590f-4e3f-838e-719717aa88c9" }
29
- let(:deployed_version_placeholder_path) { "/PLACEHOLDER-DEPLOYED-VERSION-ff3adecf-cfc5-4653-a4e3-f1861092f8e0"}
30
-
31
- subject { PactBroker::Client::Deployments::RecordUndeployment.call(params, options, pact_broker_client_options) }
32
-
33
- let(:index_body_hash) do
34
- {
35
- _links: {
36
- :'pb:environments' => {
37
- href: "#{webmock_base_url}/environments"
38
- }
39
- }
40
- }
41
- end
42
-
43
- let(:environments_hash) do
44
- {
45
- _links: {
46
- :'pb:environments' => [
47
- {
48
- name: "test",
49
- href: pact_broker.mock_service_base_url + test_environment_placeholder_path
50
- }
51
- ]
52
- }
53
- }
54
- end
55
-
56
- let!(:index_request) do
57
- stub_request(:get, "http://broker").to_return(status: 200, body: index_body_hash.to_json, headers: { "Content-Type" => "application/hal+json" } )
58
- end
59
-
60
- let!(:environments_request) do
61
- stub_request(:get, "http://broker/environments").to_return(status: 200, body: environments_hash.to_json, headers: { "Content-Type" => "application/hal+json" } )
62
- end
63
-
64
- def mock_test_environment
65
- pact_broker
66
- .given("an environment with name test and UUID 16926ef3-590f-4e3f-838e-719717aa88c9 exists")
67
- .upon_receiving("a request for an environment")
68
- .with(
69
- method: "GET",
70
- path: test_environment_placeholder_path,
71
- headers: get_request_headers
72
- )
73
- .will_respond_with(
74
- status: 200,
75
- headers: pact_broker_response_headers,
76
- body: {
77
- _links: {
78
- :'pb:currently-deployed-deployed-versions' => {
79
- href: Pact.term( pact_broker.mock_service_base_url + currently_deployed_versions_placeholder_path, /^http.*/)
80
- }
81
- }
82
- }
83
- )
84
- end
85
-
86
- def mock_deployed_versions_search_results
87
- pact_broker
88
- .given("an version is deployed to environment with UUID 16926ef3-590f-4e3f-838e-719717aa88c9 with target customer-1")
89
- .upon_receiving("a request to list the versions deployed to an environment for a pacticipant name and application instance")
90
- .with(
91
- method: "GET",
92
- path: currently_deployed_versions_placeholder_path,
93
- query: { pacticipant: pacticipant_name },
94
- headers: get_request_headers
95
- )
96
- .will_respond_with(
97
- status: 200,
98
- headers: pact_broker_response_headers,
99
- body: {
100
- _embedded: {
101
- deployedVersions: [
102
- {
103
- applicationInstance: application_instance,
104
- _links: {
105
- self: {
106
- href: Pact.term(pact_broker.mock_service_base_url + deployed_version_placeholder_path, /^http/)
107
- }
108
- }
109
- }
110
- ]
111
- }
112
- }
113
- )
114
- end
115
-
116
- def mock_mark_deployed_version_as_undeployed
117
- pact_broker
118
- .given("a currently deployed version exists")
119
- .upon_receiving("a request to mark a deployed version as not currently deploye")
120
- .with(
121
- method: "PATCH",
122
- path: deployed_version_placeholder_path,
123
- body: { currentlyDeployed: false },
124
- headers: patch_request_headers
125
- )
126
- .will_respond_with(
127
- status: 200,
128
- headers: pact_broker_response_headers,
129
- body: deployed_version_hash
130
- )
131
- end
132
-
133
- let(:deployed_version_hash) do
134
- {
135
- "currentlyDeployed" => false,
136
- "_embedded" => {
137
- "version" => {
138
- "number" => Pact.like("2")
139
- }
140
- }
141
- }
142
- end
143
-
144
- context "when the deployment is recorded successfully" do
145
- before do
146
- mock_test_environment
147
- mock_deployed_versions_search_results
148
- mock_mark_deployed_version_as_undeployed
149
- end
150
-
151
- it "returns a success message" do
152
- expect(subject.success).to be true
153
- expect(subject.message).to include "Recorded undeployment of Foo version 2 from test environment (application instance customer-1) in the Pact Broker"
154
- end
155
-
156
- context "when the output is json" do
157
- let(:output) { "json" }
158
-
159
- it "returns the JSON payload" do
160
- expect(JSON.parse(subject.message)).to eq [Pact::Reification.from_term(deployed_version_hash)]
161
- end
162
- end
163
- end
164
- end
@@ -1,391 +0,0 @@
1
- require_relative 'pact_helper'
2
- require 'pact_broker/client/webhooks/create'
3
-
4
- RSpec.describe "creating a webhook", pact: true do
5
-
6
- include_context "pact broker"
7
- include PactBrokerPactHelperMethods
8
-
9
- let(:event_names) { %w{contract_content_changed contract_published provider_verification_published provider_verification_succeeded provider_verification_failed} }
10
-
11
- let(:params) do
12
- {
13
- description: "a webhook",
14
- events: %w{contract_content_changed},
15
- http_method: "POST",
16
- url: "https://webhook",
17
- headers: { "Foo" => "bar", "Bar" => "foo"},
18
- username: "username",
19
- password: "password",
20
- body: body,
21
- consumer: "Condor",
22
- provider: "Pricing Service"
23
- }.tap { |it| Pact::Fixture.add_fixture(:create_webhook_params, it) }
24
- end
25
-
26
- let(:body) { { some: "body" }.to_json }
27
-
28
- let(:request_body) do
29
- {
30
- "description" => "a webhook",
31
- "events" => [
32
- "name" => "contract_content_changed"
33
- ],
34
- "request" => {
35
- "url" => "https://webhook",
36
- "method" => "POST",
37
- "headers" => {
38
- "Foo" => "bar",
39
- "Bar" => "foo"
40
- },
41
- "body" => {
42
- "some" => "body"
43
- },
44
- "username" => "username",
45
- "password" => "password"
46
- }
47
- }
48
- end
49
-
50
- let(:response_status) { 201 }
51
- let(:success_response) do
52
- {
53
- status: response_status,
54
- headers: pact_broker_response_headers,
55
- body: {
56
- description: Pact.like("a webhook"),
57
- request: {
58
- body: {
59
- some: "body"
60
- }
61
- },
62
- events: [
63
- name: "contract_content_changed"
64
- ],
65
- _links: {
66
- self: {
67
- href: Pact.term('http://localhost:1234/some-url', %r{http://.*}),
68
- title: Pact.like("A title")
69
- }
70
- }
71
- }
72
- }
73
- end
74
-
75
- let(:pact_broker_client_options) { {} }
76
-
77
- subject { PactBroker::Client::Webhooks::Create.call(params, broker_base_url, pact_broker_client_options) }
78
-
79
- context "when a valid webhook with a JSON body is submitted" do
80
- before do
81
- pact_broker
82
- .given("the 'Pricing Service' and 'Condor' already exist in the pact-broker")
83
- .upon_receiving("a request to create a webhook with a JSON body for a consumer and provider")
84
- .with(
85
- method: :post,
86
- path: '/webhooks/provider/Pricing%20Service/consumer/Condor',
87
- headers: post_request_headers,
88
- body: request_body)
89
- .will_respond_with(success_response)
90
- end
91
-
92
- it "returns a CommandResult with success = true" do
93
- expect(subject).to be_a PactBroker::Client::CommandResult
94
- expect(subject.success).to be true
95
- expect(subject.message).to eq "Webhook \"a webhook\" created"
96
- end
97
- end
98
-
99
- context "when a valid webhook with every possible event type is sumbitted" do
100
- before do
101
- params.merge!(events: event_names)
102
- request_body.merge!("events" => event_names.map{ |event_name| { "name" => event_name } })
103
- success_response[:body].merge!(events: event_names.map{ |event_name| { "name" => event_name } })
104
-
105
- pact_broker
106
- .given("the 'Pricing Service' and 'Condor' already exist in the pact-broker")
107
- .upon_receiving("a request to create a webhook with every possible event type")
108
- .with(
109
- method: :post,
110
- path: '/webhooks/provider/Pricing%20Service/consumer/Condor',
111
- headers: post_request_headers,
112
- body: request_body)
113
- .will_respond_with(success_response)
114
- end
115
-
116
- it "returns a CommandResult with success = true" do
117
- expect(subject.success).to be true
118
- end
119
- end
120
-
121
- context "when a valid webhook with an XML body is submitted" do
122
- before do
123
- request_body["request"]["body"] = body
124
- success_response[:body][:request][:body] = body
125
-
126
- pact_broker
127
- .given("the 'Pricing Service' and 'Condor' already exist in the pact-broker")
128
- .upon_receiving("a request to create a webhook with a non-JSON body for a consumer and provider")
129
- .with(
130
- method: :post,
131
- path: '/webhooks/provider/Pricing%20Service/consumer/Condor',
132
- headers: post_request_headers,
133
- body: request_body)
134
- .will_respond_with(success_response)
135
- end
136
-
137
- let(:body) { "<xml></xml>" }
138
-
139
- it "returns a CommandResult with success = true" do
140
- expect(subject.success).to be true
141
- end
142
- end
143
-
144
- context "when an invalid webhook is submitted" do
145
- before do
146
- params[:url] = nil
147
- request_body["request"].delete("url")
148
-
149
- pact_broker
150
- .given("the 'Pricing Service' and 'Condor' already exist in the pact-broker")
151
- .upon_receiving("an invalid request to create a webhook for a consumer and provider")
152
- .with(
153
- method: :post,
154
- path: '/webhooks/provider/Pricing%20Service/consumer/Condor',
155
- headers: post_request_headers,
156
- body: request_body).
157
- will_respond_with(
158
- status: 400,
159
- headers: pact_broker_response_headers,
160
- body: {
161
- errors: {
162
- "request.url" => Pact.each_like("Some error")
163
- }
164
- }
165
- )
166
- end
167
-
168
- it "returns a CommandResult with success = false" do
169
- expect(subject.success).to be false
170
- expect(subject.message).to match /400/
171
- expect(subject.message).to match /Some error/
172
- end
173
- end
174
-
175
- context "when one of the pacticipants does not exist" do
176
- before do
177
- pact_broker
178
- .given("'Condor' does not exist in the pact-broker")
179
- .upon_receiving("a request to create a webhook for a consumer and provider")
180
- .with(
181
- method: :post,
182
- path: '/webhooks/provider/Pricing%20Service/consumer/Condor',
183
- headers: post_request_headers,
184
- body: request_body).
185
- will_respond_with(
186
- status: 404,
187
- headers: pact_broker_response_headers
188
- )
189
- end
190
-
191
- it "returns a CommandResult with success = false" do
192
- expect(subject.success).to be false
193
- expect(subject.message).to match /404/
194
- end
195
- end
196
-
197
- context "when only a consumer is specified" do
198
- before do
199
- params.delete(:provider)
200
- request_body["consumer"] = { "name" => "Condor" }
201
- mock_pact_broker_index(self)
202
-
203
- pact_broker
204
- .given("the 'Pricing Service' and 'Condor' already exist in the pact-broker")
205
- .upon_receiving("a request to create a webhook with a JSON body for a consumer")
206
- .with(
207
- method: :post,
208
- path: placeholder_path('pb:webhooks'),
209
- headers: post_request_headers,
210
- body: request_body)
211
- .will_respond_with(success_response)
212
- end
213
-
214
- it "returns a CommandResult with success = true" do
215
- expect(subject.success).to be true
216
- expect(subject.message).to eq "Webhook \"a webhook\" created"
217
- end
218
- end
219
-
220
- context "when consumer is specified using a label" do
221
- before do
222
- params.delete(:consumer)
223
- params.delete(:provider)
224
- params.merge!(consumer_label: "consumer_label")
225
- request_body["consumer"] = { "label" => "consumer_label" }
226
- mock_pact_broker_index(self)
227
-
228
- pact_broker
229
- .upon_receiving("a request to create a webhook with a JSON body for a consumer specified by a label")
230
- .with(
231
- method: :post,
232
- path: placeholder_path('pb:webhooks'),
233
- headers: post_request_headers,
234
- body: request_body)
235
- .will_respond_with(success_response)
236
- end
237
-
238
- it "returns a CommandResult with success = true" do
239
- expect(subject.success).to be true
240
- expect(subject.message).to eq "Webhook \"a webhook\" created"
241
- end
242
- end
243
-
244
- context "when only a consumer is specified and it does not exist" do
245
- before do
246
- params.delete(:provider)
247
- request_body["consumer"] = { "name" => "Condor" }
248
- mock_pact_broker_index(self)
249
-
250
- pact_broker
251
- .upon_receiving("a request to create a webhook with a JSON body for a consumer that does not exist")
252
- .with(
253
- method: :post,
254
- path: placeholder_path('pb:webhooks'),
255
- headers: post_request_headers,
256
- body: request_body)
257
- .will_respond_with(
258
- status: 400,
259
- headers: pact_broker_response_headers,
260
- body: {
261
- errors: {
262
- "consumer.name" => Pact.each_like("Some error")
263
- }
264
- })
265
- end
266
-
267
- it "returns a CommandResult with success = true" do
268
- expect(subject.success).to be false
269
- end
270
- end
271
-
272
- context "when only a provider is specified" do
273
- before do
274
- params.delete(:consumer)
275
- request_body["provider"] = { "name" => "Pricing Service" }
276
- mock_pact_broker_index(self)
277
-
278
- pact_broker
279
- .given("the 'Pricing Service' and 'Condor' already exist in the pact-broker")
280
- .upon_receiving("a request to create a webhook with a JSON body for a provider")
281
- .with(
282
- method: :post,
283
- path: placeholder_path('pb:webhooks'),
284
- headers: post_request_headers,
285
- body: request_body)
286
- .will_respond_with(success_response)
287
- end
288
-
289
- it "returns a CommandResult with success = true" do
290
- expect(subject.success).to be true
291
- end
292
- end
293
-
294
- context "when provider is specified using a label" do
295
- before do
296
- params.delete(:consumer)
297
- params.delete(:provider)
298
- params.merge!(provider_label: "provider_label")
299
- request_body["provider"] = { "label" => "provider_label" }
300
- mock_pact_broker_index(self)
301
-
302
- pact_broker
303
- .upon_receiving("a request to create a webhook with a JSON body for a provider specified by a label")
304
- .with(
305
- method: :post,
306
- path: placeholder_path('pb:webhooks'),
307
- headers: post_request_headers,
308
- body: request_body)
309
- .will_respond_with(success_response)
310
- end
311
-
312
- it "returns a CommandResult with success = true" do
313
- expect(subject.success).to be true
314
- expect(subject.message).to eq "Webhook \"a webhook\" created"
315
- end
316
- end
317
-
318
- context "when neither consumer nor provider are specified" do
319
- before do
320
- params.delete(:consumer)
321
- params.delete(:provider)
322
- mock_pact_broker_index(self)
323
-
324
- pact_broker
325
- .upon_receiving("a request to create a global webhook with a JSON body")
326
- .with(
327
- method: :post,
328
- path: placeholder_path('pb:webhooks'),
329
- headers: post_request_headers,
330
- body: request_body)
331
- .will_respond_with(success_response)
332
- end
333
-
334
- it "returns a CommandResult with success = true" do
335
- expect(subject.success).to be true
336
- end
337
- end
338
-
339
- context "when a uuid is specified" do
340
- before do
341
- params.merge!(uuid: uuid)
342
- request_body["provider"] = { "name" => "Pricing Service" }
343
- request_body["consumer"] = { "name" => "Condor" }
344
- mock_pact_broker_index_with_webhook_relation(self)
345
- end
346
-
347
- let(:uuid) { '696c5f93-1b7f-44bc-8d03-59440fcaa9a0' }
348
-
349
- context "when the webhook does not already exist" do
350
- before do
351
- pact_broker
352
- .upon_receiving("a request to create a webhook with a JSON body and a uuid")
353
- .given("the 'Pricing Service' and 'Condor' already exist in the pact-broker")
354
- .with(
355
- method: :put,
356
- path: "/webhooks/#{uuid}",
357
- headers: put_request_headers,
358
- body: request_body)
359
- .will_respond_with(success_response)
360
- end
361
-
362
- it "returns a CommandResult with success = true" do
363
- expect(subject).to be_a PactBroker::Client::CommandResult
364
- expect(subject.success).to be true
365
- expect(subject.message).to eq "Webhook \"a webhook\" created"
366
- end
367
- end
368
-
369
- context "when the webhook does exist" do
370
- before do
371
- pact_broker
372
- .upon_receiving("a request to update a webhook")
373
- .given("a webhook with the uuid #{uuid} exists")
374
- .with(
375
- method: :put,
376
- path: "/webhooks/#{uuid}",
377
- headers: put_request_headers,
378
- body: request_body)
379
- .will_respond_with(success_response)
380
- end
381
-
382
- let(:response_status) { 200 }
383
-
384
- it "returns a CommandResult with success = true" do
385
- expect(subject).to be_a PactBroker::Client::CommandResult
386
- expect(subject.success).to be true
387
- expect(subject.message).to eq "Webhook \"a webhook\" updated"
388
- end
389
- end
390
- end
391
- end