defra_ruby_mocks 1.1.0 → 1.5.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.
- checksums.yaml +5 -5
- data/README.md +52 -2
- data/Rakefile +0 -2
- data/app/controllers/defra_ruby_mocks/company_controller.rb +1 -1
- data/app/controllers/defra_ruby_mocks/worldpay_controller.rb +33 -12
- data/app/services/defra_ruby_mocks/{worldpay_request_service.rb → worldpay_payment_service.rb} +3 -9
- data/app/services/defra_ruby_mocks/worldpay_refund_service.rb +37 -0
- data/app/services/defra_ruby_mocks/worldpay_request_handler_service.rb +40 -0
- data/app/services/defra_ruby_mocks/worldpay_resource_service.rb +55 -0
- data/app/services/defra_ruby_mocks/worldpay_response_service.rb +71 -52
- data/app/views/defra_ruby_mocks/worldpay/payment_request.xml.erb +4 -0
- data/app/views/defra_ruby_mocks/worldpay/refund_request.xml.erb +4 -0
- data/app/views/defra_ruby_mocks/worldpay/stuck.html.erb +37 -0
- data/lib/defra_ruby_mocks/engine.rb +2 -1
- data/lib/defra_ruby_mocks/missing_resource_error.rb +9 -0
- data/lib/defra_ruby_mocks/unrecognised_worldpay_request_error.rb +5 -0
- data/lib/defra_ruby_mocks/version.rb +1 -1
- data/spec/dummy/log/development.log +180 -0
- data/spec/dummy/log/test.log +1287 -323
- data/spec/examples.txt +99 -56
- data/spec/fixtures/{worldpay_request_invalid.xml → payment_request_invalid.xml} +0 -0
- data/spec/fixtures/{worldpay_request_valid.xml → payment_request_valid.xml} +0 -0
- data/spec/fixtures/refund_request_invalid.xml +6 -0
- data/spec/fixtures/refund_request_valid.xml +11 -0
- data/spec/fixtures/unrecognised_request.xml +6 -0
- data/spec/requests/worldpay_spec.rb +87 -26
- data/spec/services/{worldpay_request_service_spec.rb → worldpay_payment_service_spec.rb} +25 -22
- data/spec/services/worldpay_refund_service_spec.rb +68 -0
- data/spec/services/worldpay_request_handler_service_spec.rb +79 -0
- data/spec/services/worldpay_resource_service_spec.rb +112 -0
- data/spec/services/worldpay_response_service_spec.rb +185 -58
- data/spec/support/helpers/xml_matchers.rb +19 -0
- metadata +50 -17
- data/app/views/defra_ruby_mocks/worldpay/payments_service.xml.erb +0 -4
- data/lib/defra_ruby_mocks/missing_registration_error.rb +0 -9
data/spec/examples.txt
CHANGED
@@ -1,56 +1,99 @@
|
|
1
|
-
example_id
|
2
|
-
|
3
|
-
./spec/defra_ruby_mocks_spec.rb[1:1:1]
|
4
|
-
./spec/defra_ruby_mocks_spec.rb[1:2:1:1]
|
5
|
-
./spec/defra_ruby_mocks_spec.rb[1:2:2:1]
|
6
|
-
./spec/lib/configuration_spec.rb[1:1:1:1]
|
7
|
-
./spec/lib/configuration_spec.rb[1:1:2:1]
|
8
|
-
./spec/lib/configuration_spec.rb[1:1:3:1]
|
9
|
-
./spec/lib/configuration_spec.rb[1:1:4:1]
|
10
|
-
./spec/lib/configuration_spec.rb[1:2:1:1]
|
11
|
-
./spec/lib/configuration_spec.rb[1:2:2:1]
|
12
|
-
./spec/lib/configuration_spec.rb[1:2:3:1]
|
13
|
-
./spec/lib/configuration_spec.rb[1:2:4:1]
|
14
|
-
./spec/requests/company_spec.rb[1:1:1:1]
|
15
|
-
./spec/requests/company_spec.rb[1:1:2:1]
|
16
|
-
./spec/requests/company_spec.rb[1:1:3:1:1]
|
17
|
-
./spec/requests/company_spec.rb[1:1:3:2:1]
|
18
|
-
./spec/requests/company_spec.rb[1:2:1]
|
19
|
-
./spec/requests/worldpay_spec.rb[1:1:1:1:1]
|
20
|
-
./spec/requests/worldpay_spec.rb[1:1:1:2:1]
|
21
|
-
./spec/requests/worldpay_spec.rb[1:1:2:1:1]
|
22
|
-
./spec/requests/worldpay_spec.rb[1:1:2:
|
23
|
-
./spec/requests/worldpay_spec.rb[1:2:1:1]
|
24
|
-
./spec/requests/worldpay_spec.rb[1:2:2:1]
|
25
|
-
./spec/
|
26
|
-
./spec/
|
27
|
-
./spec/services/companies_house_service_spec.rb[1:1:
|
28
|
-
./spec/services/companies_house_service_spec.rb[1:1:2:
|
29
|
-
./spec/services/companies_house_service_spec.rb[1:1:2:
|
30
|
-
./spec/services/companies_house_service_spec.rb[1:1:2:
|
31
|
-
./spec/services/companies_house_service_spec.rb[1:1:2:
|
32
|
-
./spec/services/companies_house_service_spec.rb[1:1:2:
|
33
|
-
./spec/services/companies_house_service_spec.rb[1:1:2:
|
34
|
-
./spec/services/companies_house_service_spec.rb[1:1:2:
|
35
|
-
./spec/services/companies_house_service_spec.rb[1:1:
|
36
|
-
./spec/services/companies_house_service_spec.rb[1:1:
|
37
|
-
./spec/services/
|
38
|
-
./spec/services/
|
39
|
-
./spec/services/
|
40
|
-
./spec/services/
|
41
|
-
./spec/services/
|
42
|
-
./spec/services/
|
43
|
-
./spec/services/
|
44
|
-
./spec/services/
|
45
|
-
./spec/services/
|
46
|
-
./spec/services/
|
47
|
-
./spec/services/
|
48
|
-
./spec/services/
|
49
|
-
./spec/services/
|
50
|
-
./spec/services/
|
51
|
-
./spec/services/
|
52
|
-
./spec/services/
|
53
|
-
./spec/services/
|
54
|
-
./spec/services/
|
55
|
-
./spec/services/
|
56
|
-
./spec/services/
|
1
|
+
example_id | status | run_time |
|
2
|
+
------------------------------------------------------------------- | ------ | --------------- |
|
3
|
+
./spec/defra_ruby_mocks_spec.rb[1:1:1] | passed | 0.00949 seconds |
|
4
|
+
./spec/defra_ruby_mocks_spec.rb[1:2:1:1] | passed | 0.00016 seconds |
|
5
|
+
./spec/defra_ruby_mocks_spec.rb[1:2:2:1] | passed | 0.00015 seconds |
|
6
|
+
./spec/lib/configuration_spec.rb[1:1:1:1] | passed | 0.0001 seconds |
|
7
|
+
./spec/lib/configuration_spec.rb[1:1:2:1] | passed | 0.0001 seconds |
|
8
|
+
./spec/lib/configuration_spec.rb[1:1:3:1] | passed | 0.00009 seconds |
|
9
|
+
./spec/lib/configuration_spec.rb[1:1:4:1] | passed | 0.0001 seconds |
|
10
|
+
./spec/lib/configuration_spec.rb[1:2:1:1] | passed | 0.00009 seconds |
|
11
|
+
./spec/lib/configuration_spec.rb[1:2:2:1] | passed | 0.00115 seconds |
|
12
|
+
./spec/lib/configuration_spec.rb[1:2:3:1] | passed | 0.00009 seconds |
|
13
|
+
./spec/lib/configuration_spec.rb[1:2:4:1] | passed | 0.0001 seconds |
|
14
|
+
./spec/requests/company_spec.rb[1:1:1:1] | passed | 0.04773 seconds |
|
15
|
+
./spec/requests/company_spec.rb[1:1:2:1] | passed | 0.00765 seconds |
|
16
|
+
./spec/requests/company_spec.rb[1:1:3:1:1] | passed | 0.00364 seconds |
|
17
|
+
./spec/requests/company_spec.rb[1:1:3:2:1] | passed | 0.00421 seconds |
|
18
|
+
./spec/requests/company_spec.rb[1:2:1] | passed | 0.00804 seconds |
|
19
|
+
./spec/requests/worldpay_spec.rb[1:1:1:1:1:1] | passed | 0.01734 seconds |
|
20
|
+
./spec/requests/worldpay_spec.rb[1:1:1:1:2:1] | passed | 0.00482 seconds |
|
21
|
+
./spec/requests/worldpay_spec.rb[1:1:1:2:1:1] | passed | 0.0217 seconds |
|
22
|
+
./spec/requests/worldpay_spec.rb[1:1:2:1:1:1] | passed | 0.00433 seconds |
|
23
|
+
./spec/requests/worldpay_spec.rb[1:1:2:1:2:1] | passed | 0.00844 seconds |
|
24
|
+
./spec/requests/worldpay_spec.rb[1:1:2:2:1:1] | passed | 0.00496 seconds |
|
25
|
+
./spec/requests/worldpay_spec.rb[1:2:1:1] | passed | 0.00303 seconds |
|
26
|
+
./spec/requests/worldpay_spec.rb[1:2:2:1] | passed | 0.00199 seconds |
|
27
|
+
./spec/services/companies_house_service_spec.rb[1:1:1:1] | passed | 0.00011 seconds |
|
28
|
+
./spec/services/companies_house_service_spec.rb[1:1:2:1:1] | passed | 0.00009 seconds |
|
29
|
+
./spec/services/companies_house_service_spec.rb[1:1:2:2:1] | passed | 0.00011 seconds |
|
30
|
+
./spec/services/companies_house_service_spec.rb[1:1:2:3:1] | passed | 0.00013 seconds |
|
31
|
+
./spec/services/companies_house_service_spec.rb[1:1:2:4:1] | passed | 0.00009 seconds |
|
32
|
+
./spec/services/companies_house_service_spec.rb[1:1:2:5:1] | passed | 0.00008 seconds |
|
33
|
+
./spec/services/companies_house_service_spec.rb[1:1:2:6:1] | passed | 0.00008 seconds |
|
34
|
+
./spec/services/companies_house_service_spec.rb[1:1:2:7:1] | passed | 0.00011 seconds |
|
35
|
+
./spec/services/companies_house_service_spec.rb[1:1:2:8:1] | passed | 0.00012 seconds |
|
36
|
+
./spec/services/companies_house_service_spec.rb[1:1:2:9:1] | passed | 0.00009 seconds |
|
37
|
+
./spec/services/companies_house_service_spec.rb[1:1:3:1:1] | passed | 0.0001 seconds |
|
38
|
+
./spec/services/companies_house_service_spec.rb[1:1:3:2:1] | passed | 0.00015 seconds |
|
39
|
+
./spec/services/worldpay_payment_service_spec.rb[1:1:1:1] | passed | 0.00014 seconds |
|
40
|
+
./spec/services/worldpay_payment_service_spec.rb[1:1:2:1:1] | passed | 0.00123 seconds |
|
41
|
+
./spec/services/worldpay_payment_service_spec.rb[1:1:2:1:2] | passed | 0.00171 seconds |
|
42
|
+
./spec/services/worldpay_payment_service_spec.rb[1:1:2:1:3] | passed | 0.00041 seconds |
|
43
|
+
./spec/services/worldpay_payment_service_spec.rb[1:1:2:1:4] | passed | 0.00052 seconds |
|
44
|
+
./spec/services/worldpay_payment_service_spec.rb[1:1:2:1:5:1] | passed | 0.00039 seconds |
|
45
|
+
./spec/services/worldpay_payment_service_spec.rb[1:1:2:1:5:2] | passed | 0.00051 seconds |
|
46
|
+
./spec/services/worldpay_payment_service_spec.rb[1:1:2:1:5:3] | passed | 0.00046 seconds |
|
47
|
+
./spec/services/worldpay_payment_service_spec.rb[1:1:2:1:6:1] | passed | 0.0005 seconds |
|
48
|
+
./spec/services/worldpay_payment_service_spec.rb[1:1:3:1] | passed | 0.00192 seconds |
|
49
|
+
./spec/services/worldpay_refund_service_spec.rb[1:1:1:1:1] | passed | 0.00072 seconds |
|
50
|
+
./spec/services/worldpay_refund_service_spec.rb[1:1:1:1:2] | passed | 0.00049 seconds |
|
51
|
+
./spec/services/worldpay_refund_service_spec.rb[1:1:1:1:3] | passed | 0.00047 seconds |
|
52
|
+
./spec/services/worldpay_refund_service_spec.rb[1:1:1:1:4] | passed | 0.00066 seconds |
|
53
|
+
./spec/services/worldpay_refund_service_spec.rb[1:1:1:1:5] | passed | 0.00065 seconds |
|
54
|
+
./spec/services/worldpay_refund_service_spec.rb[1:1:1:1:6] | passed | 0.00056 seconds |
|
55
|
+
./spec/services/worldpay_refund_service_spec.rb[1:1:1:1:7] | passed | 0.00066 seconds |
|
56
|
+
./spec/services/worldpay_refund_service_spec.rb[1:1:2:1] | passed | 0.00215 seconds |
|
57
|
+
./spec/services/worldpay_request_handler_service_spec.rb[1:1:1:1:1] | passed | 0.00095 seconds |
|
58
|
+
./spec/services/worldpay_request_handler_service_spec.rb[1:1:1:1:2] | passed | 0.00093 seconds |
|
59
|
+
./spec/services/worldpay_request_handler_service_spec.rb[1:1:1:2:1] | passed | 0.02227 seconds |
|
60
|
+
./spec/services/worldpay_request_handler_service_spec.rb[1:1:1:2:2] | passed | 0.00086 seconds |
|
61
|
+
./spec/services/worldpay_request_handler_service_spec.rb[1:1:1:3:1] | passed | 0.00052 seconds |
|
62
|
+
./spec/services/worldpay_resource_service_spec.rb[1:1:1:1] | passed | 0.00064 seconds |
|
63
|
+
./spec/services/worldpay_resource_service_spec.rb[1:1:1:2] | passed | 0.00057 seconds |
|
64
|
+
./spec/services/worldpay_resource_service_spec.rb[1:1:1:3] | passed | 0.00061 seconds |
|
65
|
+
./spec/services/worldpay_resource_service_spec.rb[1:1:1:4] | passed | 0.00064 seconds |
|
66
|
+
./spec/services/worldpay_resource_service_spec.rb[1:1:2:1] | passed | 0.0007 seconds |
|
67
|
+
./spec/services/worldpay_resource_service_spec.rb[1:1:2:2] | passed | 0.00063 seconds |
|
68
|
+
./spec/services/worldpay_resource_service_spec.rb[1:1:2:3] | passed | 0.0007 seconds |
|
69
|
+
./spec/services/worldpay_resource_service_spec.rb[1:1:2:4] | passed | 0.00066 seconds |
|
70
|
+
./spec/services/worldpay_resource_service_spec.rb[1:1:3:1] | passed | 0.0028 seconds |
|
71
|
+
./spec/services/worldpay_resource_service_spec.rb[1:1:4:1] | passed | 0.00066 seconds |
|
72
|
+
./spec/services/worldpay_response_service_spec.rb[1:1:1:1:1] | passed | 0.0006 seconds |
|
73
|
+
./spec/services/worldpay_response_service_spec.rb[1:1:1:1:2] | passed | 0.00056 seconds |
|
74
|
+
./spec/services/worldpay_response_service_spec.rb[1:1:1:1:3:1] | passed | 0.00058 seconds |
|
75
|
+
./spec/services/worldpay_response_service_spec.rb[1:1:1:1:3:2] | passed | 0.00052 seconds |
|
76
|
+
./spec/services/worldpay_response_service_spec.rb[1:1:1:1:4:1] | passed | 0.00054 seconds |
|
77
|
+
./spec/services/worldpay_response_service_spec.rb[1:1:1:1:4:2] | passed | 0.00057 seconds |
|
78
|
+
./spec/services/worldpay_response_service_spec.rb[1:1:1:1:5:1] | passed | 0.00041 seconds |
|
79
|
+
./spec/services/worldpay_response_service_spec.rb[1:1:1:1:5:2] | passed | 0.00046 seconds |
|
80
|
+
./spec/services/worldpay_response_service_spec.rb[1:1:1:1:6:1] | passed | 0.0006 seconds |
|
81
|
+
./spec/services/worldpay_response_service_spec.rb[1:1:1:1:6:2] | passed | 0.00063 seconds |
|
82
|
+
./spec/services/worldpay_response_service_spec.rb[1:1:1:1:7:1] | passed | 0.00055 seconds |
|
83
|
+
./spec/services/worldpay_response_service_spec.rb[1:1:1:1:7:2] | passed | 0.00062 seconds |
|
84
|
+
./spec/services/worldpay_response_service_spec.rb[1:1:1:1:8:1] | passed | 0.00058 seconds |
|
85
|
+
./spec/services/worldpay_response_service_spec.rb[1:1:1:1:8:2] | passed | 0.00064 seconds |
|
86
|
+
./spec/services/worldpay_response_service_spec.rb[1:1:2:1:1] | passed | 0.00072 seconds |
|
87
|
+
./spec/services/worldpay_response_service_spec.rb[1:1:2:1:2] | passed | 0.00056 seconds |
|
88
|
+
./spec/services/worldpay_response_service_spec.rb[1:1:2:1:3:1] | passed | 0.00063 seconds |
|
89
|
+
./spec/services/worldpay_response_service_spec.rb[1:1:2:1:3:2] | passed | 0.00059 seconds |
|
90
|
+
./spec/services/worldpay_response_service_spec.rb[1:1:2:1:4:1] | passed | 0.00056 seconds |
|
91
|
+
./spec/services/worldpay_response_service_spec.rb[1:1:2:1:4:2] | passed | 0.00056 seconds |
|
92
|
+
./spec/services/worldpay_response_service_spec.rb[1:1:2:1:5:1] | passed | 0.00069 seconds |
|
93
|
+
./spec/services/worldpay_response_service_spec.rb[1:1:2:1:5:2] | passed | 0.00055 seconds |
|
94
|
+
./spec/services/worldpay_response_service_spec.rb[1:1:2:1:6:1] | passed | 0.00058 seconds |
|
95
|
+
./spec/services/worldpay_response_service_spec.rb[1:1:2:1:6:2] | passed | 0.00074 seconds |
|
96
|
+
./spec/services/worldpay_response_service_spec.rb[1:1:2:1:7:1] | passed | 0.00063 seconds |
|
97
|
+
./spec/services/worldpay_response_service_spec.rb[1:1:2:1:7:2] | passed | 0.00058 seconds |
|
98
|
+
./spec/services/worldpay_response_service_spec.rb[1:1:2:1:8:1] | passed | 0.00064 seconds |
|
99
|
+
./spec/services/worldpay_response_service_spec.rb[1:1:2:1:8:2] | passed | 0.00063 seconds |
|
File without changes
|
File without changes
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<?xml version="1.0"?>
|
2
|
+
<!DOCTYPE paymentService PUBLIC '-//WorldPay/DTD WorldPay PaymentService v1/EN' 'http://dtd.worldpay.com/paymentService_v1.dtd'>
|
3
|
+
<paymentService version="1.4" merchantCode="MERCHME">
|
4
|
+
<modify>
|
5
|
+
<orderModification orderCode="1579644835">
|
6
|
+
<refund>
|
7
|
+
<amount value="2500" currencyCode="GBP" exponent="2"/>
|
8
|
+
</refund>
|
9
|
+
</orderModification>
|
10
|
+
</modify>
|
11
|
+
</paymentService>
|
@@ -19,53 +19,114 @@ module DefraRubyMocks
|
|
19
19
|
context "#payments_service" do
|
20
20
|
let(:path) { "/defra_ruby_mocks/worldpay/payments-service" }
|
21
21
|
|
22
|
-
context "
|
23
|
-
|
22
|
+
context "when a payment request is received" do
|
23
|
+
context "and the request is valid" do
|
24
|
+
let(:data) { File.read("spec/fixtures/payment_request_valid.xml") }
|
25
|
+
|
26
|
+
it "returns an XML response with a 200 code" do
|
27
|
+
get path, {}, "RAW_POST_DATA" => data
|
28
|
+
|
29
|
+
expect(response.content_type).to eq("application/xml")
|
30
|
+
expect(response.code).to eq("200")
|
31
|
+
expect(response.body).to be_xml
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "and the request is invalid" do
|
36
|
+
let(:data) { File.read("spec/fixtures/payment_request_invalid.xml") }
|
24
37
|
|
25
|
-
|
26
|
-
|
38
|
+
it "returns a response with a 500 code" do
|
39
|
+
get path, {}, "RAW_POST_DATA" => data
|
27
40
|
|
28
|
-
|
29
|
-
|
41
|
+
expect(response.code).to eq("500")
|
42
|
+
end
|
30
43
|
end
|
31
44
|
end
|
32
45
|
|
33
|
-
context "
|
34
|
-
|
46
|
+
context "when a refund request is received" do
|
47
|
+
context "and the request is valid" do
|
48
|
+
let(:data) { File.read("spec/fixtures/refund_request_valid.xml") }
|
35
49
|
|
36
|
-
|
37
|
-
|
50
|
+
it "returns an XML response with a 200 code" do
|
51
|
+
get path, {}, "RAW_POST_DATA" => data
|
38
52
|
|
39
|
-
|
53
|
+
expect(response.content_type).to eq("application/xml")
|
54
|
+
expect(response.code).to eq("200")
|
55
|
+
expect(response.body).to be_xml
|
56
|
+
end
|
40
57
|
end
|
41
58
|
end
|
42
59
|
end
|
43
60
|
|
44
61
|
context "#dispatcher" do
|
45
|
-
let(:
|
46
|
-
let(:
|
47
|
-
let(:
|
48
|
-
let(:
|
49
|
-
let(:
|
50
|
-
let(:
|
51
|
-
|
52
|
-
|
62
|
+
let(:success_url) { "http://example.com/fo/12345/worldpay/success" }
|
63
|
+
let(:failure_url) { "http://example.com/fo/12345/worldpay/failure" }
|
64
|
+
let(:pending_url) { "http://example.com/fo/12345/worldpay/pending" }
|
65
|
+
let(:cancel_url) { "http://example.com/fo/12345/worldpay/cancel" }
|
66
|
+
let(:error_url) { "http://example.com/fo/12345/worldpay/error" }
|
67
|
+
let(:response_url) { "#{success_url}?orderKey=admincode1^^987654&paymentStatus=#{status}&paymentAmount=10500&paymentCurrency=GBP&mac=0ba5271e1ed1b26f9bb428ef7fb536a4&source=WP" }
|
68
|
+
let(:path) do
|
69
|
+
root = "/defra_ruby_mocks/worldpay/dispatcher"
|
70
|
+
escaped_success = CGI.escape(success_url)
|
71
|
+
escaped_failure = CGI.escape(failure_url)
|
72
|
+
escaped_pending = CGI.escape(pending_url)
|
73
|
+
escaped_cancel = CGI.escape(cancel_url)
|
74
|
+
escaped_error = CGI.escape(error_url)
|
75
|
+
|
76
|
+
"#{root}?successURL=#{escaped_success}&failureURL=#{escaped_failure}&pendingURL=#{escaped_pending}&cancelURL=#{escaped_cancel}&errorURL=#{escaped_error}"
|
77
|
+
end
|
78
|
+
let(:service_response) do
|
79
|
+
double(
|
80
|
+
:response,
|
81
|
+
supplied_url: success_url,
|
82
|
+
url: response_url,
|
83
|
+
status: status,
|
84
|
+
separator: "?",
|
85
|
+
order_key: "admincode1",
|
86
|
+
mac: "e5bc7ce5dfe44d2000771ac2b157f0e9",
|
87
|
+
value: 154_00,
|
88
|
+
reference: "12345"
|
89
|
+
)
|
90
|
+
end
|
53
91
|
|
54
92
|
context "and the request is valid" do
|
55
|
-
|
56
|
-
|
93
|
+
before(:each) do
|
94
|
+
allow(WorldpayResponseService).to receive(:run)
|
95
|
+
.with(
|
96
|
+
success_url: success_url,
|
97
|
+
failure_url: failure_url,
|
98
|
+
pending_url: pending_url,
|
99
|
+
cancel_url: cancel_url,
|
100
|
+
error_url: error_url
|
101
|
+
) { service_response }
|
102
|
+
end
|
103
|
+
|
104
|
+
context "and a response is expected" do
|
105
|
+
let(:status) { "AUTHORISED" }
|
106
|
+
|
107
|
+
it "redirects the user with a 300 code" do
|
108
|
+
get path
|
57
109
|
|
58
|
-
|
59
|
-
|
110
|
+
expect(response).to redirect_to(response_url)
|
111
|
+
expect(response.code).to eq("302")
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
context "and a response is not expected" do
|
116
|
+
let(:status) { :STUCK }
|
60
117
|
|
61
|
-
|
118
|
+
it "renders the Worldpay stuck page" do
|
119
|
+
get path
|
62
120
|
|
63
|
-
|
64
|
-
|
121
|
+
expect(response).to render_template(:stuck)
|
122
|
+
expect(response.code).to eq("200")
|
123
|
+
end
|
65
124
|
end
|
66
125
|
end
|
67
126
|
|
68
127
|
context "and the request is invalid" do
|
128
|
+
before(:each) { allow(WorldpayResponseService).to receive(:run).and_raise(MissingResourceError.new("foo")) }
|
129
|
+
|
69
130
|
context "because the success url is not in a recognised format" do
|
70
131
|
let(:success_url) { "http://example.com/forthewin" }
|
71
132
|
|
@@ -3,58 +3,61 @@
|
|
3
3
|
require "rails_helper"
|
4
4
|
|
5
5
|
module DefraRubyMocks
|
6
|
-
RSpec.describe
|
6
|
+
RSpec.describe WorldpayPaymentService do
|
7
7
|
describe ".run" do
|
8
8
|
after(:each) { Helpers::Configuration.reset_for_tests }
|
9
9
|
|
10
|
+
let(:merchant_code) { "MERCHME" }
|
11
|
+
let(:args) { { merchant_code: merchant_code, xml: xml } }
|
12
|
+
|
10
13
|
context "when the mocks config is missing a worldpay domain" do
|
14
|
+
let(:xml) { nil }
|
15
|
+
|
11
16
|
it "raises a 'InvalidConfigError'" do
|
12
|
-
expect { described_class.run(
|
17
|
+
expect { described_class.run(args) }.to raise_error InvalidConfigError
|
13
18
|
end
|
14
19
|
end
|
15
20
|
|
16
|
-
context "when the XML
|
21
|
+
context "when the XML is valid" do
|
17
22
|
before(:each) do
|
18
23
|
DefraRubyMocks.configure do |config|
|
19
24
|
config.worldpay_domain = "http://localhost:3000/defra_ruby_mocks"
|
20
25
|
end
|
21
26
|
end
|
22
27
|
|
23
|
-
let(:
|
28
|
+
let(:xml) { Nokogiri::XML(File.read("spec/fixtures/payment_request_valid.xml")) }
|
24
29
|
|
25
30
|
context "the result it returns" do
|
26
31
|
it "is a hash" do
|
27
|
-
expect(described_class.run(
|
32
|
+
expect(described_class.run(args)).to be_an_instance_of(Hash)
|
28
33
|
end
|
29
34
|
|
30
35
|
it "contains 4 values" do
|
31
|
-
result = described_class.run(
|
36
|
+
result = described_class.run(args).length
|
32
37
|
expect(result).to eq(4)
|
33
38
|
end
|
34
39
|
|
35
|
-
|
36
|
-
|
37
|
-
result = described_class.run(data)[:merchant_code]
|
40
|
+
it "has the merchant code passed in" do
|
41
|
+
result = described_class.run(args)[:merchant_code]
|
38
42
|
|
39
|
-
|
40
|
-
|
43
|
+
expect(result).to eq(merchant_code)
|
44
|
+
end
|
41
45
|
|
42
|
-
|
43
|
-
|
46
|
+
it "has an order code extracted from the XML" do
|
47
|
+
result = described_class.run(args)[:order_code]
|
44
48
|
|
45
|
-
|
46
|
-
end
|
49
|
+
expect(result).to eq("1577726052")
|
47
50
|
end
|
48
51
|
|
49
52
|
context "has a generated ID which is" do
|
50
53
|
it "10 characters long" do
|
51
|
-
result = described_class.run(
|
54
|
+
result = described_class.run(args)[:id]
|
52
55
|
|
53
56
|
expect(result.length).to eq(10)
|
54
57
|
end
|
55
58
|
|
56
59
|
it "only made up of the digits 0 to 9" do
|
57
|
-
result = described_class.run(
|
60
|
+
result = described_class.run(args)[:id]
|
58
61
|
|
59
62
|
expect(result.scan(/\D/).empty?).to be_truthy
|
60
63
|
end
|
@@ -62,7 +65,7 @@ module DefraRubyMocks
|
|
62
65
|
it "different each time" do
|
63
66
|
results = []
|
64
67
|
3.times do
|
65
|
-
results << described_class.run(
|
68
|
+
results << described_class.run(args)[:id]
|
66
69
|
end
|
67
70
|
|
68
71
|
expect(results.uniq.length).to eq(results.length)
|
@@ -71,7 +74,7 @@ module DefraRubyMocks
|
|
71
74
|
|
72
75
|
context "has a url" do
|
73
76
|
it "based on the configured domain, and extracted merchant and order codes" do
|
74
|
-
result = described_class.run(
|
77
|
+
result = described_class.run(args)[:url]
|
75
78
|
|
76
79
|
expect(result).to eq("http://localhost:3000/defra_ruby_mocks/worldpay/dispatcher?OrderKey=MERCHME%5E1577726052")
|
77
80
|
end
|
@@ -80,11 +83,11 @@ module DefraRubyMocks
|
|
80
83
|
|
81
84
|
end
|
82
85
|
|
83
|
-
context "when the
|
84
|
-
let(:
|
86
|
+
context "when the XML is invalid" do
|
87
|
+
let(:xml) { Nokogiri::XML(File.read("spec/fixtures/payment_request_invalid.xml")) }
|
85
88
|
|
86
89
|
it "raises an error" do
|
87
|
-
expect { described_class.run(
|
90
|
+
expect { described_class.run(args) }.to raise_error StandardError
|
88
91
|
end
|
89
92
|
end
|
90
93
|
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rails_helper"
|
4
|
+
|
5
|
+
module DefraRubyMocks
|
6
|
+
RSpec.describe WorldpayRefundService do
|
7
|
+
describe ".run" do
|
8
|
+
|
9
|
+
let(:merchant_code) { "MERCHME" }
|
10
|
+
let(:args) { { merchant_code: merchant_code, xml: xml } }
|
11
|
+
|
12
|
+
context "when the XML is valid" do
|
13
|
+
|
14
|
+
let(:xml) { Nokogiri::XML(File.read("spec/fixtures/refund_request_valid.xml")) }
|
15
|
+
|
16
|
+
context "the result it returns" do
|
17
|
+
it "is a hash" do
|
18
|
+
expect(described_class.run(args)).to be_an_instance_of(Hash)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "contains 5 values" do
|
22
|
+
result = described_class.run(args).length
|
23
|
+
expect(result).to eq(5)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "has the merchant code passed in" do
|
27
|
+
result = described_class.run(args)[:merchant_code]
|
28
|
+
|
29
|
+
expect(result).to eq(merchant_code)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "has an order code extracted from the XML" do
|
33
|
+
result = described_class.run(args)[:order_code]
|
34
|
+
|
35
|
+
expect(result).to eq("1579644835")
|
36
|
+
end
|
37
|
+
|
38
|
+
it "has the refund value extracted from the XML" do
|
39
|
+
result = described_class.run(args)[:refund_value]
|
40
|
+
|
41
|
+
expect(result).to eq("2500")
|
42
|
+
end
|
43
|
+
|
44
|
+
it "has a currency code extracted from the XML" do
|
45
|
+
result = described_class.run(args)[:currency_code]
|
46
|
+
|
47
|
+
expect(result).to eq("GBP")
|
48
|
+
end
|
49
|
+
|
50
|
+
it "has the exponent extracted from the XML" do
|
51
|
+
result = described_class.run(args)[:exponent]
|
52
|
+
|
53
|
+
expect(result).to eq("2")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
context "when the XML is invalid" do
|
60
|
+
let(:xml) { Nokogiri::XML(File.read("spec/fixtures/refund_request_invalid.xml")) }
|
61
|
+
|
62
|
+
it "raises an error" do
|
63
|
+
expect { described_class.run(args) }.to raise_error StandardError
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|