defra_ruby_mocks 2.3.2 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +32 -75
  3. data/app/controllers/defra_ruby_mocks/govpay_controller.rb +28 -3
  4. data/app/jobs/defra_ruby_mocks/application_job.rb +6 -0
  5. data/app/jobs/defra_ruby_mocks/govpay_payment_callback_job.rb +17 -0
  6. data/app/services/defra_ruby_mocks/govpay_create_payment_service.rb +41 -13
  7. data/app/services/defra_ruby_mocks/govpay_get_payment_service.rb +74 -16
  8. data/app/services/defra_ruby_mocks/govpay_refund_details_service.rb +43 -0
  9. data/app/services/defra_ruby_mocks/govpay_request_refund_service.rb +27 -0
  10. data/config/routes.rb +10 -10
  11. data/lib/defra_ruby_mocks/configuration.rb +1 -1
  12. data/lib/defra_ruby_mocks/engine.rb +0 -1
  13. data/lib/defra_ruby_mocks/version.rb +1 -1
  14. data/spec/dummy/log/test.log +1279 -972
  15. data/spec/examples.txt +68 -121
  16. data/spec/fixtures/files/govpay/create_payment_created_response.json +24 -0
  17. data/spec/fixtures/files/govpay/create_payment_error_response.json +5 -0
  18. data/spec/fixtures/files/govpay/get_payment_response_cancelled.json +61 -0
  19. data/spec/fixtures/files/govpay/get_payment_response_created.json +73 -0
  20. data/spec/fixtures/files/govpay/get_payment_response_error.json +5 -0
  21. data/spec/fixtures/files/govpay/get_payment_response_failure.json +9 -0
  22. data/spec/fixtures/files/govpay/get_payment_response_not_found.json +4 -0
  23. data/spec/fixtures/files/govpay/get_payment_response_submitted.json +75 -0
  24. data/spec/fixtures/files/govpay/get_payment_response_success.json +62 -0
  25. data/spec/requests/govpay_spec.rb +64 -1
  26. data/spec/services/govpay_create_payment_service_spec.rb +44 -0
  27. data/spec/services/govpay_get_payment_service_spec.rb +30 -0
  28. data/spec/services/govpay_refund_details_service_spec.rb +58 -0
  29. data/spec/services/govpay_request_refund_service_spec.rb +31 -0
  30. metadata +32 -48
  31. data/app/controllers/defra_ruby_mocks/worldpay_controller.rb +0 -57
  32. data/app/services/defra_ruby_mocks/worldpay_payment_service.rb +0 -47
  33. data/app/services/defra_ruby_mocks/worldpay_refund_service.rb +0 -37
  34. data/app/services/defra_ruby_mocks/worldpay_request_handler_service.rb +0 -40
  35. data/app/services/defra_ruby_mocks/worldpay_resource_service.rb +0 -55
  36. data/app/services/defra_ruby_mocks/worldpay_response_service.rb +0 -119
  37. data/app/views/defra_ruby_mocks/worldpay/payment_request.xml.erb +0 -4
  38. data/app/views/defra_ruby_mocks/worldpay/refund_request.xml.erb +0 -4
  39. data/app/views/defra_ruby_mocks/worldpay/stuck.html.erb +0 -37
  40. data/lib/defra_ruby_mocks/unrecognised_worldpay_request_error.rb +0 -5
  41. data/spec/fixtures/payment_request_invalid.xml +0 -6
  42. data/spec/fixtures/payment_request_valid.xml +0 -30
  43. data/spec/fixtures/refund_request_invalid.xml +0 -6
  44. data/spec/fixtures/refund_request_valid.xml +0 -11
  45. data/spec/fixtures/unrecognised_request.xml +0 -6
  46. data/spec/requests/worldpay_spec.rb +0 -163
  47. data/spec/services/worldpay_payment_service_spec.rb +0 -95
  48. data/spec/services/worldpay_refund_service_spec.rb +0 -68
  49. data/spec/services/worldpay_request_handler_service_spec.rb +0 -79
  50. data/spec/services/worldpay_resource_service_spec.rb +0 -120
  51. data/spec/services/worldpay_response_service_spec.rb +0 -280
@@ -1,280 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "rails_helper"
4
-
5
- module DefraRubyMocks
6
-
7
- RSpec.describe WorldpayResponseService do
8
- before(:each) do
9
- Helpers::Configuration.prep_for_tests
10
- DefraRubyMocks.configure do |config|
11
- config.worldpay_admin_code = admin_code
12
- config.worldpay_merchant_code = merchant_code
13
- config.worldpay_mac_secret = mac_secret
14
- end
15
-
16
- allow(WorldpayResourceService).to receive(:run) { resource }
17
- end
18
-
19
- let(:resource) { double(:resource, order: order, company_name: company_name&.downcase) }
20
-
21
- let(:admin_code) { "admincode1" }
22
- let(:merchant_code) { "merchantcode1" }
23
- let(:mac_secret) { "mac1" }
24
- let(:reference) { "12345" }
25
- let(:order_code) { "54321" }
26
- let(:order_key) { "#{admin_code}^#{merchant_code}^#{order_code}" }
27
- let(:order_value) { 105_00 }
28
- let(:payment_status) { :AUTHORISED }
29
- let(:company_name) { "Pay for the thing" }
30
-
31
- let(:order) { double(:order, order_code: order_code, total_amount: order_value) }
32
-
33
- let(:mac) { Digest::MD5.hexdigest(mac_data.join).to_s }
34
-
35
- let(:query_string) do
36
- [
37
- "orderKey=#{order_key}",
38
- "paymentStatus=#{payment_status}",
39
- "paymentAmount=#{order_value}",
40
- "paymentCurrency=GBP",
41
- "mac=#{mac}",
42
- "source=WP"
43
- ].join("&")
44
- end
45
-
46
- let(:args) do
47
- {
48
- success_url: success_url,
49
- failure_url: failure_url,
50
- pending_url: pending_url,
51
- cancel_url: cancel_url,
52
- error_url: error_url
53
- }
54
- end
55
-
56
- describe ".run" do
57
- context "when the request comes from the waste-carriers-front-office" do
58
- let(:success_url) { "http://example.com/fo/#{reference}/worldpay/success" }
59
- let(:failure_url) { "http://example.com/fo/#{reference}/worldpay/failure" }
60
- let(:pending_url) { "http://example.com/fo/#{reference}/worldpay/pending" }
61
- let(:cancel_url) { "http://example.com/fo/#{reference}/worldpay/cancel" }
62
- let(:error_url) { "http://example.com/fo/#{reference}/worldpay/error" }
63
-
64
- context "and is valid" do
65
- let(:relation) { double(:relation, first: registration) }
66
- let(:mac_data) { [order_key, order_value, "GBP", payment_status, mac_secret] }
67
-
68
- it "can extract the reference from the `success_url`" do
69
- expect(described_class.run(args).reference).to eq(reference)
70
- end
71
-
72
- it "can generate a valid order key" do
73
- expect(described_class.run(args).order_key).to eq(order_key)
74
- end
75
-
76
- context "and is for a successful payment" do
77
- it "can generate a valid mac" do
78
- expect(described_class.run(args).mac).to eq(mac)
79
- end
80
-
81
- it "returns a url in the expected format" do
82
- expected_response_url = "#{success_url}?#{query_string}"
83
-
84
- expect(described_class.run(args).url).to eq(expected_response_url)
85
- end
86
-
87
- context "and the company name is blank" do
88
- let(:company_name) { nil }
89
-
90
- it "can extract the reference from the `success_url`" do
91
- expect(described_class.run(args).reference).to eq(reference)
92
- end
93
- end
94
- end
95
-
96
- context "and is for a rejected payment" do
97
- let(:payment_status) { :REFUSED }
98
- let(:company_name) { "Reject for the thing" }
99
-
100
- it "can generate a valid mac" do
101
- expect(described_class.run(args).mac).to eq(mac)
102
- end
103
-
104
- it "returns a url in the expected format" do
105
- expected_response_url = "#{failure_url}?#{query_string}"
106
-
107
- expect(described_class.run(args).url).to eq(expected_response_url)
108
- end
109
- end
110
-
111
- context "and is for a stuck payment" do
112
- let(:payment_status) { :STUCK }
113
- let(:company_name) { "Give me a stuck thing" }
114
-
115
- it "can generate a valid mac" do
116
- expect(described_class.run(args).mac).to eq(mac)
117
- end
118
-
119
- it "returns a status of :STUCK" do
120
- expect(described_class.run(args).status).to eq(:STUCK)
121
- end
122
- end
123
-
124
- context "and is for a pending payment" do
125
- let(:payment_status) { :SENT_FOR_AUTHORISATION }
126
- let(:company_name) { "Pending for the thing" }
127
-
128
- it "can generate a valid mac" do
129
- expect(described_class.run(args).mac).to eq(mac)
130
- end
131
-
132
- it "returns a url in the expected format" do
133
- expected_response_url = "#{pending_url}?#{query_string}"
134
-
135
- expect(described_class.run(args).url).to eq(expected_response_url)
136
- end
137
- end
138
-
139
- context "and is for a cancelled payment" do
140
- let(:payment_status) { :CANCELLED }
141
- let(:company_name) { "Cancel the thing" }
142
- let(:mac_data) { [order_key, order_value, "GBP", mac_secret] }
143
-
144
- it "can generate a valid mac" do
145
- expect(described_class.run(args).mac).to eq(mac)
146
- end
147
-
148
- it "returns a url in the expected format" do
149
- expected_response_url = "#{cancel_url}?#{query_string}"
150
-
151
- expect(described_class.run(args).url).to eq(expected_response_url)
152
- end
153
- end
154
-
155
- context "and is for an errored payment" do
156
- let(:payment_status) { :ERROR }
157
- let(:company_name) { "Error the thing" }
158
-
159
- it "can generate a valid mac" do
160
- expect(described_class.run(args).mac).to eq(mac)
161
- end
162
-
163
- it "returns a url in the expected format" do
164
- expected_response_url = "#{error_url}?#{query_string}"
165
-
166
- expect(described_class.run(args).url).to eq(expected_response_url)
167
- end
168
- end
169
- end
170
- end
171
-
172
- context "when the request comes from the waste-carriers-frontend" do
173
- let(:success_url) { "http://example.com/your-registration/#{reference}/worldpay/success/54321/NEWREG?locale=en" }
174
- let(:failure_url) { "http://example.com/your-registration/#{reference}/worldpay/failure/54321/NEWREG?locale=en" }
175
- let(:pending_url) { "http://example.com/your-registration/#{reference}/worldpay/pending/54321/NEWREG?locale=en" }
176
- let(:cancel_url) { "http://example.com/your-registration/#{reference}/worldpay/cancel/54321/NEWREG?locale=en" }
177
- let(:error_url) { "http://example.com/your-registration/#{reference}/worldpay/error/54321/NEWREG?locale=en" }
178
-
179
- context "and is valid" do
180
- let(:relation) { double(:relation, first: registration) }
181
- let(:mac_data) { [order_key, order_value, "GBP", payment_status, mac_secret] }
182
-
183
- it "can extract the reference from the `success_url`" do
184
- expect(described_class.run(args).reference).to eq(reference)
185
- end
186
-
187
- it "can generate a valid order key" do
188
- expect(described_class.run(args).order_key).to eq(order_key)
189
- end
190
-
191
- context "and is for a successful payment" do
192
- it "can generate a valid mac" do
193
- expect(described_class.run(args).mac).to eq(mac)
194
- end
195
-
196
- it "returns a url in the expected format" do
197
- expected_response_url = "#{success_url}&#{query_string}"
198
-
199
- expect(described_class.run(args).url).to eq(expected_response_url)
200
- end
201
- end
202
-
203
- context "and is for a rejected payment" do
204
- let(:payment_status) { :REFUSED }
205
- let(:company_name) { "Reject for the thing" }
206
-
207
- it "can generate a valid mac" do
208
- expect(described_class.run(args).mac).to eq(mac)
209
- end
210
-
211
- it "returns a url in the expected format" do
212
- expected_response_url = "#{failure_url}&#{query_string}"
213
-
214
- expect(described_class.run(args).url).to eq(expected_response_url)
215
- end
216
- end
217
-
218
- context "and is for a stuck payment" do
219
- let(:payment_status) { :STUCK }
220
- let(:company_name) { "Give me a stuck thing" }
221
-
222
- it "can generate a valid mac" do
223
- expect(described_class.run(args).mac).to eq(mac)
224
- end
225
-
226
- it "returns a status of :STUCK" do
227
- expect(described_class.run(args).status).to eq(:STUCK)
228
- end
229
- end
230
-
231
- context "and is for a pending payment" do
232
- let(:payment_status) { :SENT_FOR_AUTHORISATION }
233
- let(:company_name) { "Pending for the thing" }
234
-
235
- it "can generate a valid mac" do
236
- expect(described_class.run(args).mac).to eq(mac)
237
- end
238
-
239
- it "returns a url in the expected format" do
240
- expected_response_url = "#{pending_url}&#{query_string}"
241
-
242
- expect(described_class.run(args).url).to eq(expected_response_url)
243
- end
244
- end
245
-
246
- context "and is for a cancelled payment" do
247
- let(:payment_status) { :CANCELLED }
248
- let(:company_name) { "Cancel the thing" }
249
- let(:mac_data) { [order_key, order_value, "GBP", mac_secret] }
250
-
251
- it "can generate a valid mac" do
252
- expect(described_class.run(args).mac).to eq(mac)
253
- end
254
-
255
- it "returns a url in the expected format" do
256
- expected_response_url = "#{cancel_url}&#{query_string}"
257
-
258
- expect(described_class.run(args).url).to eq(expected_response_url)
259
- end
260
- end
261
-
262
- context "and is for an errored payment" do
263
- let(:payment_status) { :ERROR }
264
- let(:company_name) { "Error the thing" }
265
-
266
- it "can generate a valid mac" do
267
- expect(described_class.run(args).mac).to eq(mac)
268
- end
269
-
270
- it "returns a url in the expected format" do
271
- expected_response_url = "#{error_url}&#{query_string}"
272
-
273
- expect(described_class.run(args).url).to eq(expected_response_url)
274
- end
275
- end
276
- end
277
- end
278
- end
279
- end
280
- end