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,174 +0,0 @@
1
- require 'pact_broker/client/cli/custom_thor'
2
-
3
- module PactBroker::Client::CLI
4
-
5
- class Delegate
6
- def self.call options; end
7
- end
8
-
9
- class TestThor < CustomThor
10
- def self.exit_on_failure?
11
- false
12
- end
13
-
14
- desc 'ARGUMENT', 'This is the description'
15
- def test_default(argument)
16
- Delegate.call(argument: argument)
17
- end
18
-
19
- desc '', ''
20
- method_option :multi, type: :array
21
- def test_multiple_options
22
- Delegate.call(options)
23
- end
24
-
25
- desc '', ''
26
- method_option :broker_base_url, required: true, aliases: "-b"
27
- method_option :broker_username, aliases: "-u"
28
- method_option :broker_password, aliases: "-p"
29
- method_option :broker_token, aliases: "-k"
30
- def test_using_env_vars
31
- Delegate.call(options)
32
- end
33
-
34
- desc '', ''
35
- method_option :broker_base_url, required: true, aliases: "-b"
36
- method_option :broker_username, aliases: "-u"
37
- method_option :broker_password, aliases: "-p"
38
- method_option :broker_token, aliases: "-k"
39
- def test_pact_broker_client_options
40
- Delegate.call(pact_broker_client_options)
41
- end
42
-
43
- desc '', ''
44
- ignored_and_hidden_potential_options_from_environment_variables
45
- def test_without_parameters
46
- Delegate.call(options)
47
- end
48
-
49
- default_command :test_default
50
- end
51
-
52
- describe CustomThor do
53
- subject { TestThor.new }
54
-
55
- it "converts options that are specified multiple times into a single array" do
56
- expect(Delegate).to receive(:call).with({'multi' => ['one', 'two']})
57
- TestThor.start(%w{test_multiple_options --multi one --multi two})
58
- end
59
-
60
- context "with broker configuration in the environment variables" do
61
- before do
62
- ENV['PACT_BROKER_BASE_URL'] = 'http://foo'
63
- ENV['PACT_BROKER_USERNAME'] = 'username'
64
- ENV['PACT_BROKER_PASSWORD'] = 'password'
65
- ENV['PACT_BROKER_TOKEN'] = 'token'
66
- end
67
-
68
- it "populates the base URL from the environment variables" do
69
- expect(Delegate).to receive(:call) do | options |
70
- expect(options.broker_base_url).to eq 'http://foo'
71
- end
72
- TestThor.start(%w{test_using_env_vars})
73
- end
74
-
75
- it "does not override a value specifed on the command line" do
76
- expect(Delegate).to receive(:call) do | options |
77
- expect(options.broker_base_url).to eq 'http://bar'
78
- end
79
- TestThor.start(%w{test_using_env_vars --broker-base-url http://bar})
80
- end
81
-
82
- it "allows commands to be called that don't use the environment variables" do
83
- expect(Delegate).to receive(:call)
84
- TestThor.start(%w{test_without_parameters})
85
- end
86
- end
87
-
88
- it "removes trailing slashes from the broker base url when passed as an arg" do
89
- expect(Delegate).to receive(:call) do | options |
90
- expect(options[:pact_broker_base_url]).to eq 'http://bar'
91
- end
92
- TestThor.start(%w{test_pact_broker_client_options --broker-base-url http://bar/})
93
- end
94
-
95
- it "removes trailing slashes from the broker base url when passed as an env var" do
96
- ENV['PACT_BROKER_BASE_URL'] = 'http://bar/'
97
- expect(Delegate).to receive(:call) do | options |
98
- expect(options[:pact_broker_base_url]).to eq 'http://bar'
99
- end
100
- TestThor.start(%w{test_pact_broker_client_options})
101
- end
102
-
103
- describe "when someone copy pastes from Word and uses an em dash instead of a normal dash" do
104
- before do
105
- allow(TestThor).to receive(:exit_with_error_code)
106
- end
107
-
108
- it "exits with an error message" do
109
- expect($stdout).to receive(:puts).with(/contains an em dash/)
110
- expect(TestThor).to receive(:exit_with_error_code)
111
- TestThor.start(["test_default", "\u2014\u2014bar"])
112
- end
113
- end
114
-
115
- describe ".handle_help" do
116
- context "when the last argument is --help or -h" do
117
- it "turns it into the form that Thor expects, which is a really odd one" do
118
- expect(TestThor.handle_help(["foo", "--help"])).to eq ["help", "foo"]
119
- expect(TestThor.handle_help(["foo", "-h"])).to eq ["help", "foo"]
120
- expect(TestThor.handle_help(["-h"])).to eq ["help"]
121
- expect(TestThor.handle_help(["--help"])).to eq ["help"]
122
- end
123
- end
124
- end
125
-
126
- describe ".turn_muliple_tag_options_into_array" do
127
- it "turns '--tag foo --tag bar' into '--tag foo bar'" do
128
- input = %w{--ignore this --tag foo --tag bar --wiffle --that}
129
- output = %w{--ignore this --tag foo bar --wiffle --that }
130
- expect(TestThor.turn_muliple_tag_options_into_array(input)).to eq output
131
- end
132
-
133
- it "turns '--tag foo bar --tag meep' into '--tag foo meep bar'" do
134
- input = %w{--ignore this --tag foo bar --tag meep --wiffle --that}
135
- output = %w{--ignore this --tag foo meep bar --wiffle --that}
136
- expect(TestThor.turn_muliple_tag_options_into_array(input)).to eq output
137
- end
138
-
139
- it "turns '--tag foo --tag bar wiffle' into '--tag foo bar wiffle' which is silly" do
140
- input = %w{--ignore this --tag foo --tag bar wiffle}
141
- output = %w{--ignore this --tag foo bar wiffle}
142
- expect(TestThor.turn_muliple_tag_options_into_array(input)).to eq output
143
- end
144
-
145
- it "maintains '--tag foo bar wiffle'" do
146
- input = %w{--ignore this --tag foo bar wiffle --meep}
147
- output = %w{--ignore this --tag foo bar wiffle --meep}
148
- expect(TestThor.turn_muliple_tag_options_into_array(input)).to eq output
149
- end
150
-
151
- it "turns '-t foo -t bar' into '-t foo bar'" do
152
- input = %w{--ignore this -t foo -t bar --meep --that 1 2 3}
153
- output = %w{--ignore this -t foo bar --meep --that 1 2 3}
154
- expect(TestThor.turn_muliple_tag_options_into_array(input)).to eq output
155
- end
156
-
157
- it "turns '--tag=foo --tag=bar' into '--tag foo bar'" do
158
- input = %w{--ignore this --tag=foo --tag=bar --wiffle --that}
159
- output = %w{--ignore this --tag foo bar --wiffle --that }
160
- expect(TestThor.turn_muliple_tag_options_into_array(input)).to eq output
161
- end
162
-
163
- it "doesn't change anything when there are no duplicate options" do
164
- input = %w{--ignore this --taggy foo --blah bar --wiffle --that}
165
- expect(TestThor.turn_muliple_tag_options_into_array(input)).to eq input
166
- end
167
-
168
- it "return an empty array when given an empty array" do
169
- input = []
170
- expect(TestThor.turn_muliple_tag_options_into_array(input)).to eq input
171
- end
172
- end
173
- end
174
- end
@@ -1,97 +0,0 @@
1
- require 'pact_broker/client/cli/version_selector_options_parser'
2
-
3
- module PactBroker
4
- module Client
5
- module CLI
6
- describe VersionSelectorOptionsParser do
7
-
8
- TEST_CASES = [
9
- [
10
- ["--pacticipant", "Foo", "--version", "1.2.3"],
11
- [{ pacticipant: "Foo", version: "1.2.3" } ]
12
- ],[
13
- ["-a", "Foo", "-e", "1.2.3"],
14
- [{ pacticipant: "Foo", version: "1.2.3" } ]
15
- ],[
16
- ["--pacticipant", "Foo"],
17
- [{ pacticipant: "Foo" } ]
18
- ],[
19
- ["--pacticipant", "Foo", "Bar"],
20
- [{ pacticipant: "Bar" } ]
21
- ],[
22
- ["--pacticipant", "Foo", "--pacticipant", "Bar", "--version", "1.2.3"],
23
- [{ pacticipant: "Foo" }, { pacticipant: "Bar", version: "1.2.3" } ]
24
- ],[
25
- ["--pacticipant", "Foo", "--wrong", "Bar", "--version", "1.2.3"],
26
- [{ pacticipant: "Foo", version: "1.2.3" } ]
27
- ],[
28
- ["--pacticipant", "the-thing", "--version", "1.2.3"],
29
- [{ pacticipant: "the-thing", version: "1.2.3" } ]
30
- ],[
31
- ["--version", "1.2.3"],
32
- [{ pacticipant: nil, version: "1.2.3" } ]
33
- ],[
34
- ["--pacticipant", "Foo", "--latest", "--pacticipant", "Bar"],
35
- [{ pacticipant: "Foo", latest: true }, { pacticipant: "Bar" } ]
36
- ],[
37
- ["--pacticipant", "Foo", "--latest", "prod", "--pacticipant", "Bar"],
38
- [{ pacticipant: "Foo", latest: true, tag: "prod"}, { pacticipant: "Bar" } ]
39
- ],[
40
- ["--pacticipant", "Foo", "--all", "prod", "--pacticipant", "Bar"],
41
- [{ pacticipant: "Foo", tag: "prod"}, { pacticipant: "Bar" } ]
42
- ],[
43
- ["--pacticipant=Foo", "--version=1.2.3"],
44
- [{ pacticipant: "Foo", version: "1.2.3" } ]
45
- ],[
46
- ["--pacticipant=Foo=Bar", "--version", "1.2.3"],
47
- [{ pacticipant: "Foo=Bar", version: "1.2.3" } ]
48
- ],[
49
- ["--pacticipant", "Foo=Bar", "--version", "1.2.3"],
50
- [{ pacticipant: "Foo=Bar", version: "1.2.3" } ]
51
- ],[
52
- ["--ignore", "Foo", "--version", "1.2.3"],
53
- [{ pacticipant: "Foo", version: "1.2.3", ignore: true }]
54
- ],[
55
- ["--ignore", "Foo", "--ignore", "Bar", "--version", "1.2.3"],
56
- [{ pacticipant: "Foo", ignore: true }, { pacticipant: "Bar", version: "1.2.3", ignore: true }]
57
- ],[
58
- ["--ignore", "Foo", "--pacticipant", "Bar", "--version", "1.2.3"],
59
- [{ pacticipant: "Foo", ignore: true }, { pacticipant: "Bar", version: "1.2.3" }]
60
- ],[
61
- ["--pacticipant", "Foo", "--version", "1", "--version", "2"],
62
- [{ pacticipant: "Foo", version: "2" }]
63
- ],[
64
- ["--pacticipant", "Foo", "--version", "2", "--latest"],
65
- [{ pacticipant: "Foo", version: "2", latest: true }]
66
- ],[
67
- ["--pacticipant", "Foo", "--version", "2", "--latest", "--latest"],
68
- [{ pacticipant: "Foo", version: "2", latest: true }]
69
- ],[
70
- ["--version", "2"],
71
- [{ pacticipant: nil, version: "2" }]
72
- ],[
73
- ["--pacticipant", "Foo", "--branch", "main"],
74
- [{ pacticipant: "Foo", branch: "main", latest: true }]
75
- ],[
76
- ["--branch", "main"],
77
- [{ pacticipant: nil, branch: "main", latest: true }]
78
- ],[
79
- ["--pacticipant", "Foo", "--main-branch", "--pacticipant", "Bar", "--version", "1"],
80
- [{ pacticipant: "Foo", main_branch: true, latest: true }, { pacticipant: "Bar", version: "1" }]
81
- ],[
82
- ["--main-branch"],
83
- [{ pacticipant: nil, main_branch: true, latest: true }]
84
- ]
85
- ]
86
-
87
- TEST_CASES.each do | input, output |
88
-
89
- it "parses #{input.join(' ')}" do
90
- expect(VersionSelectorOptionsParser.call(input)).to eq output
91
- end
92
-
93
- end
94
- end
95
- end
96
- end
97
- end
@@ -1,224 +0,0 @@
1
- require 'pact_broker/client/deployments/record_deployment'
2
-
3
- module PactBroker
4
- module Client
5
- module Deployments
6
- describe RecordDeployment do
7
- describe ".call" do
8
- let(:broker_base_url) { "http://broker" }
9
- let(:index_body_hash) do
10
- {
11
- _links: {
12
- "pb:environments" => { href: "#{broker_base_url}/environments" },
13
- "pb:pacticipant-version" => {
14
- href: "#{broker_base_url}/pacticipants/{pacticipant}/versions/{version}"
15
- }
16
- }
17
- }
18
- end
19
- let(:version_body_hash) do
20
- {
21
- "_links" => {
22
- "pb:record-deployment" => [
23
- {
24
- name: "test",
25
- href: "#{broker_base_url}/record-deployment"
26
- }
27
- ]
28
- }
29
- }
30
- end
31
- let(:environments_body_hash) do
32
- {
33
- "_links" => {
34
- "pb:environments" => [
35
- {
36
- "name" => "test",
37
- "href" => ""
38
- }
39
- ]
40
- }
41
-
42
- }
43
- end
44
- let(:record_deployment_body_hash) do
45
- { "some" => "response" }
46
- end
47
- let(:index_headers) { { "Content-Type" => "application/hal+json" } }
48
- let!(:index_request) do
49
- stub_request(:get, broker_base_url).to_return(status: 200, body: index_body_hash.to_json, headers: index_headers )
50
- end
51
- let!(:version_request) do
52
- stub_request(:get, broker_base_url + "/pacticipants/Foo/versions/1").to_return(status: 200, body: version_body_hash.to_json, headers: { "Content-Type" => "application/hal+json" } )
53
- end
54
-
55
- let!(:environments_request) do
56
- stub_request(:get, "http://broker/environments").
57
- with(headers: { 'Accept'=>'application/hal+json' }).
58
- to_return(status: 200, body: environments_body_hash.to_json, headers: { "Content-Type" => "application/hal+json" })
59
- end
60
- let!(:record_deployment_request) do
61
- stub_request(:post, "http://broker/record-deployment").
62
- to_return(status: 200, body: record_deployment_body_hash.to_json , headers: {})
63
- end
64
-
65
- let(:application_instance) { "blue" }
66
-
67
- let(:params) do
68
- {
69
- pacticipant_name: "Foo",
70
- version_number: "1",
71
- environment_name: "test",
72
- application_instance: application_instance
73
- }
74
- end
75
-
76
- let(:options) do
77
- {
78
- output: output,
79
- verbose: true
80
- }
81
- end
82
- let(:output) { "text" }
83
- let(:pact_broker_client_options) { { pact_broker_base_url: broker_base_url} }
84
-
85
- subject { RecordDeployment.call(params, options, pact_broker_client_options) }
86
-
87
- context "when the pb:environments relation does not exist" do
88
- let(:index_body_hash) do
89
- {
90
- "_links" => {}
91
- }
92
- end
93
-
94
- it "returns an error response" do
95
- expect(subject.success).to be false
96
- expect(subject.message).to include "does not support"
97
- end
98
-
99
- context "when the server is PactFlow" do
100
- let(:index_headers) { { "Content-Type" => "application/hal+json", "Pactflow-Something" => "foo" } }
101
-
102
- it "returns an error response" do
103
- expect(subject.message).to include "permission"
104
- expect(subject.message).to include "does not support"
105
- end
106
- end
107
- end
108
-
109
- context "when the specified version does not exist" do
110
- let!(:version_request) do
111
- stub_request(:get, broker_base_url + "/pacticipants/Foo/versions/1").to_return(status: 404)
112
- end
113
-
114
- it "returns an error response" do
115
- expect(subject.success).to be false
116
- expect(subject.message).to include "Foo version 1 not found"
117
- end
118
- end
119
-
120
- context "when the pacticipant version does not support recording deployments" do
121
- let(:version_body_hash) do
122
- {
123
- "_links" => {}
124
- }
125
- end
126
- it "returns an error response" do
127
- expect(subject.success).to be false
128
- expect(subject.message).to include "does not support"
129
- end
130
- end
131
-
132
- context "when the specified environment is not available for recording a deployment" do
133
- let(:version_body_hash) do
134
- {
135
- "_links" => {
136
- "pb:record-deployment" => [
137
- {
138
- "name" => "prod",
139
- "href" => ""
140
- }
141
- ]
142
- }
143
- }
144
- end
145
-
146
- context "when the environment does not exist" do
147
- let(:environments_body_hash) do
148
- {
149
- "_links" => {
150
- "pb:environments" => [
151
- {
152
- "name" => "prod",
153
- "href" => ""
154
- },{
155
- "name" => "uat",
156
- "href" => ""
157
- }
158
- ]
159
- }
160
- }
161
- end
162
-
163
- it "returns an error response" do
164
- expect(subject.success).to be false
165
- expect(subject.message).to include "No environment found with name 'test'. Available options: prod"
166
- end
167
-
168
- context "when the server is PactFlow" do
169
- let(:index_headers) { { "Content-Type" => "application/hal+json", "X-Pactflow-Sha" => "123" } }
170
-
171
- it "returns a customised message" do
172
- expect(subject.message).to include "Environment 'test' is not an available option for recording a deployment of Foo"
173
- expect(subject.message).to include "permissions"
174
- end
175
- end
176
- end
177
-
178
- context "when the environment does exist" do
179
- it "returns an error response" do
180
- expect(subject.success).to be false
181
- expect(subject.message).to include "Environment 'test' is not an available option for recording a deployment of Foo. Available options: prod"
182
- end
183
- end
184
- end
185
-
186
- context "when the output is json" do
187
- let(:output) { "json" }
188
-
189
- it "returns the JSON payload" do
190
- expect(JSON.parse(subject.message)).to eq record_deployment_body_hash
191
- end
192
- end
193
-
194
- context "when the response headers contain PactFlow" do
195
- before do
196
- allow_any_instance_of(RecordDeployment).to receive(:check_if_command_supported)
197
- allow_any_instance_of(RecordDeployment).to receive(:check_environment_exists)
198
- allow_any_instance_of(RecordDeployment).to receive(:record_action)
199
- allow_any_instance_of(RecordDeployment).to receive(:index_resource).and_return(index_resource)
200
- end
201
-
202
- let(:response_headers) { { "X-Pactflow-Sha" => "abc" } }
203
-
204
- let(:index_resource) do
205
- double('PactBroker::Client::Hal::Entity', response: double('response', headers: response_headers) )
206
- end
207
-
208
- it "indicates the API was PactFlow" do
209
- expect(subject.message).to include "Recorded deployment of Foo version 1 to test environment (application instance blue) in PactFlow"
210
- end
211
-
212
- context "when application_instance is nil" do
213
- let(:application_instance) { nil }
214
-
215
- it "does not include the application_instance in the result message" do
216
- expect(subject.message).to include "Recorded deployment of Foo version 1 to test environment in"
217
- end
218
- end
219
- end
220
- end
221
- end
222
- end
223
- end
224
- end