defra_ruby_mocks 1.0.0 → 1.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +90 -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 +51 -0
- data/app/services/defra_ruby_mocks/worldpay_payment_service.rb +47 -0
- 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 +92 -0
- 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/config/routes.rb +11 -0
- data/lib/defra_ruby_mocks/configuration.rb +2 -0
- data/lib/defra_ruby_mocks/engine.rb +3 -0
- data/lib/defra_ruby_mocks/invalid_config_error.rb +9 -0
- 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 +679 -99
- data/spec/examples.txt +83 -30
- data/spec/fixtures/payment_request_invalid.xml +6 -0
- data/spec/fixtures/payment_request_valid.xml +30 -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/company_spec.rb +3 -3
- data/spec/requests/worldpay_spec.rb +142 -0
- data/spec/services/worldpay_payment_service_spec.rb +95 -0
- 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 +156 -0
- data/spec/spec_helper.rb +3 -2
- data/spec/support/helpers/configuration.rb +1 -0
- data/spec/support/helpers/helpers.rb +13 -0
- data/spec/support/helpers/waste_carriers_engine.rb +10 -0
- data/spec/support/helpers/xml_matchers.rb +19 -0
- metadata +75 -8
data/spec/examples.txt
CHANGED
@@ -1,30 +1,83 @@
|
|
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/
|
20
|
-
./spec/
|
21
|
-
./spec/
|
22
|
-
./spec/
|
23
|
-
./spec/
|
24
|
-
./spec/
|
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:
|
30
|
-
./spec/services/companies_house_service_spec.rb[1:1:3:
|
1
|
+
example_id | status | run_time |
|
2
|
+
------------------------------------------------------------------- | ------ | --------------- |
|
3
|
+
./spec/defra_ruby_mocks_spec.rb[1:1:1] | passed | 0.02254 seconds |
|
4
|
+
./spec/defra_ruby_mocks_spec.rb[1:2:1:1] | passed | 0.00022 seconds |
|
5
|
+
./spec/defra_ruby_mocks_spec.rb[1:2:2:1] | passed | 0.00565 seconds |
|
6
|
+
./spec/lib/configuration_spec.rb[1:1:1:1] | passed | 0.00008 seconds |
|
7
|
+
./spec/lib/configuration_spec.rb[1:1:2:1] | passed | 0.00008 seconds |
|
8
|
+
./spec/lib/configuration_spec.rb[1:1:3:1] | passed | 0.00008 seconds |
|
9
|
+
./spec/lib/configuration_spec.rb[1:1:4:1] | passed | 0.00009 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.00009 seconds |
|
12
|
+
./spec/lib/configuration_spec.rb[1:2:3:1] | passed | 0.00011 seconds |
|
13
|
+
./spec/lib/configuration_spec.rb[1:2:4:1] | passed | 0.00236 seconds |
|
14
|
+
./spec/requests/company_spec.rb[1:1:1:1] | passed | 0.01096 seconds |
|
15
|
+
./spec/requests/company_spec.rb[1:1:2:1] | passed | 0.04303 seconds |
|
16
|
+
./spec/requests/company_spec.rb[1:1:3:1:1] | passed | 0.00435 seconds |
|
17
|
+
./spec/requests/company_spec.rb[1:1:3:2:1] | passed | 0.00458 seconds |
|
18
|
+
./spec/requests/company_spec.rb[1:2:1] | passed | 0.00311 seconds |
|
19
|
+
./spec/requests/worldpay_spec.rb[1:1:1:1:1:1] | passed | 0.02388 seconds |
|
20
|
+
./spec/requests/worldpay_spec.rb[1:1:1:1:2:1] | passed | 0.00636 seconds |
|
21
|
+
./spec/requests/worldpay_spec.rb[1:1:1:2:1:1] | passed | 0.01838 seconds |
|
22
|
+
./spec/requests/worldpay_spec.rb[1:1:2:1:1:1] | passed | 0.03425 seconds |
|
23
|
+
./spec/requests/worldpay_spec.rb[1:1:2:1:2:1] | passed | 0.04753 seconds |
|
24
|
+
./spec/requests/worldpay_spec.rb[1:1:2:2:1:1] | passed | 0.00465 seconds |
|
25
|
+
./spec/requests/worldpay_spec.rb[1:2:1:1] | passed | 0.0037 seconds |
|
26
|
+
./spec/requests/worldpay_spec.rb[1:2:2:1] | passed | 0.01137 seconds |
|
27
|
+
./spec/services/companies_house_service_spec.rb[1:1:1:1] | passed | 0.00017 seconds |
|
28
|
+
./spec/services/companies_house_service_spec.rb[1:1:2:1:1] | passed | 0.00011 seconds |
|
29
|
+
./spec/services/companies_house_service_spec.rb[1:1:2:2:1] | passed | 0.0001 seconds |
|
30
|
+
./spec/services/companies_house_service_spec.rb[1:1:2:3:1] | passed | 0.00012 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.00009 seconds |
|
33
|
+
./spec/services/companies_house_service_spec.rb[1:1:2:6:1] | passed | 0.0001 seconds |
|
34
|
+
./spec/services/companies_house_service_spec.rb[1:1:2:7:1] | passed | 0.0001 seconds |
|
35
|
+
./spec/services/companies_house_service_spec.rb[1:1:2:8:1] | passed | 0.00009 seconds |
|
36
|
+
./spec/services/companies_house_service_spec.rb[1:1:2:9:1] | passed | 0.0001 seconds |
|
37
|
+
./spec/services/companies_house_service_spec.rb[1:1:3:1:1] | passed | 0.00009 seconds |
|
38
|
+
./spec/services/companies_house_service_spec.rb[1:1:3:2:1] | passed | 0.00012 seconds |
|
39
|
+
./spec/services/worldpay_payment_service_spec.rb[1:1:1:1] | passed | 0.00019 seconds |
|
40
|
+
./spec/services/worldpay_payment_service_spec.rb[1:1:2:1:1] | passed | 0.002 seconds |
|
41
|
+
./spec/services/worldpay_payment_service_spec.rb[1:1:2:1:2] | passed | 0.00135 seconds |
|
42
|
+
./spec/services/worldpay_payment_service_spec.rb[1:1:2:1:3] | passed | 0.00059 seconds |
|
43
|
+
./spec/services/worldpay_payment_service_spec.rb[1:1:2:1:4] | passed | 0.00101 seconds |
|
44
|
+
./spec/services/worldpay_payment_service_spec.rb[1:1:2:1:5:1] | passed | 0.00086 seconds |
|
45
|
+
./spec/services/worldpay_payment_service_spec.rb[1:1:2:1:5:2] | passed | 0.01732 seconds |
|
46
|
+
./spec/services/worldpay_payment_service_spec.rb[1:1:2:1:5:3] | passed | 0.00079 seconds |
|
47
|
+
./spec/services/worldpay_payment_service_spec.rb[1:1:2:1:6:1] | passed | 0.00094 seconds |
|
48
|
+
./spec/services/worldpay_payment_service_spec.rb[1:1:3:1] | passed | 0.00208 seconds |
|
49
|
+
./spec/services/worldpay_refund_service_spec.rb[1:1:1:1:1] | passed | 0.00063 seconds |
|
50
|
+
./spec/services/worldpay_refund_service_spec.rb[1:1:1:1:2] | passed | 0.00065 seconds |
|
51
|
+
./spec/services/worldpay_refund_service_spec.rb[1:1:1:1:3] | passed | 0.0006 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.00218 seconds |
|
54
|
+
./spec/services/worldpay_refund_service_spec.rb[1:1:1:1:6] | passed | 0.00064 seconds |
|
55
|
+
./spec/services/worldpay_refund_service_spec.rb[1:1:1:1:7] | passed | 0.00061 seconds |
|
56
|
+
./spec/services/worldpay_refund_service_spec.rb[1:1:2:1] | passed | 0.01948 seconds |
|
57
|
+
./spec/services/worldpay_request_handler_service_spec.rb[1:1:1:1:1] | passed | 0.00125 seconds |
|
58
|
+
./spec/services/worldpay_request_handler_service_spec.rb[1:1:1:1:2] | passed | 0.00146 seconds |
|
59
|
+
./spec/services/worldpay_request_handler_service_spec.rb[1:1:1:2:1] | passed | 0.00086 seconds |
|
60
|
+
./spec/services/worldpay_request_handler_service_spec.rb[1:1:1:2:2] | passed | 0.00077 seconds |
|
61
|
+
./spec/services/worldpay_request_handler_service_spec.rb[1:1:1:3:1] | passed | 0.00141 seconds |
|
62
|
+
./spec/services/worldpay_resource_service_spec.rb[1:1:1:1] | passed | 0.00068 seconds |
|
63
|
+
./spec/services/worldpay_resource_service_spec.rb[1:1:1:2] | passed | 0.00062 seconds |
|
64
|
+
./spec/services/worldpay_resource_service_spec.rb[1:1:1:3] | passed | 0.00065 seconds |
|
65
|
+
./spec/services/worldpay_resource_service_spec.rb[1:1:1:4] | passed | 0.00056 seconds |
|
66
|
+
./spec/services/worldpay_resource_service_spec.rb[1:1:2:1] | passed | 0.00075 seconds |
|
67
|
+
./spec/services/worldpay_resource_service_spec.rb[1:1:2:2] | passed | 0.00067 seconds |
|
68
|
+
./spec/services/worldpay_resource_service_spec.rb[1:1:2:3] | passed | 0.00067 seconds |
|
69
|
+
./spec/services/worldpay_resource_service_spec.rb[1:1:2:4] | passed | 0.00064 seconds |
|
70
|
+
./spec/services/worldpay_resource_service_spec.rb[1:1:3:1] | passed | 0.05549 seconds |
|
71
|
+
./spec/services/worldpay_resource_service_spec.rb[1:1:4:1] | passed | 0.00428 seconds |
|
72
|
+
./spec/services/worldpay_response_service_spec.rb[1:1:1:1:1] | passed | 0.00066 seconds |
|
73
|
+
./spec/services/worldpay_response_service_spec.rb[1:1:1:1:2] | passed | 0.00055 seconds |
|
74
|
+
./spec/services/worldpay_response_service_spec.rb[1:1:1:1:3] | passed | 0.00058 seconds |
|
75
|
+
./spec/services/worldpay_response_service_spec.rb[1:1:1:1:4:1] | passed | 0.00059 seconds |
|
76
|
+
./spec/services/worldpay_response_service_spec.rb[1:1:1:1:5:1] | passed | 0.0006 seconds |
|
77
|
+
./spec/services/worldpay_response_service_spec.rb[1:1:1:1:6:1] | passed | 0.00057 seconds |
|
78
|
+
./spec/services/worldpay_response_service_spec.rb[1:1:2:1:1] | passed | 0.00061 seconds |
|
79
|
+
./spec/services/worldpay_response_service_spec.rb[1:1:2:1:2] | passed | 0.00059 seconds |
|
80
|
+
./spec/services/worldpay_response_service_spec.rb[1:1:2:1:3] | passed | 0.00059 seconds |
|
81
|
+
./spec/services/worldpay_response_service_spec.rb[1:1:2:1:4:1] | passed | 0.00072 seconds |
|
82
|
+
./spec/services/worldpay_response_service_spec.rb[1:1:2:1:5:1] | passed | 0.00291 seconds |
|
83
|
+
./spec/services/worldpay_response_service_spec.rb[1:1:2:1:6:1] | passed | 0.00091 seconds |
|
@@ -0,0 +1,30 @@
|
|
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
|
+
<submit>
|
5
|
+
<order orderCode="1577726052">
|
6
|
+
<description>Your Waste Carrier Registration CBDU2</description>
|
7
|
+
<amount currencyCode="GBP" value="10500" exponent="2"/>
|
8
|
+
<orderContent>Waste Carrier Registration renewal: CBDU2 for Booth Mcdaniel Associates</orderContent>
|
9
|
+
<paymentMethodMask>
|
10
|
+
<include code="VISA-SSL"/>
|
11
|
+
<include code="MAESTRO-SSL"/>
|
12
|
+
<include code="ECMC-SSL"/>
|
13
|
+
</paymentMethodMask>
|
14
|
+
<shopper>
|
15
|
+
<shopperEmailAddress>vucij@example.com</shopperEmailAddress>
|
16
|
+
</shopper>
|
17
|
+
<billingAddress>
|
18
|
+
<address>
|
19
|
+
<firstName>Bell</firstName>
|
20
|
+
<lastName>Cruz</lastName>
|
21
|
+
<address1>HARMSEN GROUP DEANERY ROAD</address1>
|
22
|
+
<address2/>
|
23
|
+
<postalCode>BS1 5AH</postalCode>
|
24
|
+
<city>BRISTOL</city>
|
25
|
+
<countryCode>GB</countryCode>
|
26
|
+
</address>
|
27
|
+
</billingAddress>
|
28
|
+
</order>
|
29
|
+
</submit>
|
30
|
+
</paymentService>
|
@@ -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>
|
@@ -2,14 +2,14 @@
|
|
2
2
|
|
3
3
|
require "rails_helper"
|
4
4
|
|
5
|
-
module
|
5
|
+
module DefraRubyMocks
|
6
6
|
RSpec.describe "Company", type: :request do
|
7
|
+
after(:all) { Helpers::Configuration.reset_for_tests }
|
7
8
|
|
8
9
|
let(:path) { "/defra_ruby_mocks/company" }
|
9
10
|
|
10
11
|
context "when mocks are enabled" do
|
11
|
-
before(:
|
12
|
-
after(:all) { Helpers::Configuration.reset_for_tests }
|
12
|
+
before(:each) { Helpers::Configuration.prep_for_tests }
|
13
13
|
|
14
14
|
context "when the company number is 99999999 for not found" do
|
15
15
|
let(:company_number) { "99999999" }
|
@@ -0,0 +1,142 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rails_helper"
|
4
|
+
|
5
|
+
module DefraRubyMocks
|
6
|
+
RSpec.describe "Worldpay", type: :request do
|
7
|
+
after(:all) { Helpers::Configuration.reset_for_tests }
|
8
|
+
|
9
|
+
context "when mocks are enabled" do
|
10
|
+
before(:each) do
|
11
|
+
Helpers::Configuration.prep_for_tests
|
12
|
+
DefraRubyMocks.configure do |config|
|
13
|
+
config.worldpay_admin_code = "admincode1"
|
14
|
+
config.worldpay_mac_secret = "macsecret1"
|
15
|
+
config.worldpay_domain = "http://localhost:3000/defra_ruby_mocks"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "#payments_service" do
|
20
|
+
let(:path) { "/defra_ruby_mocks/worldpay/payments-service" }
|
21
|
+
|
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") }
|
37
|
+
|
38
|
+
it "returns a response with a 500 code" do
|
39
|
+
get path, {}, "RAW_POST_DATA" => data
|
40
|
+
|
41
|
+
expect(response.code).to eq("500")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
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") }
|
49
|
+
|
50
|
+
it "returns an XML response with a 200 code" do
|
51
|
+
get path, {}, "RAW_POST_DATA" => data
|
52
|
+
|
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
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context "#dispatcher" do
|
62
|
+
let(:response_url) { "#{success_url}?orderKey=admincode1^^987654&paymentStatus=#{status}&paymentAmount=10500&paymentCurrency=GBP&mac=0ba5271e1ed1b26f9bb428ef7fb536a4&source=WP" }
|
63
|
+
let(:path) { "/defra_ruby_mocks/worldpay/dispatcher?successURL=#{CGI.escape(success_url)}" }
|
64
|
+
let(:service_response) do
|
65
|
+
double(
|
66
|
+
:response,
|
67
|
+
supplied_url: success_url,
|
68
|
+
url: response_url,
|
69
|
+
status: status,
|
70
|
+
separator: "?",
|
71
|
+
order_key: "admincode1",
|
72
|
+
mac: "e5bc7ce5dfe44d2000771ac2b157f0e9",
|
73
|
+
value: 154_00,
|
74
|
+
reference: "12345"
|
75
|
+
)
|
76
|
+
end
|
77
|
+
|
78
|
+
context "and the request is valid" do
|
79
|
+
before(:each) { allow(WorldpayResponseService).to receive(:run) { service_response } }
|
80
|
+
|
81
|
+
let(:success_url) { "http://example.com/fo/12345/worldpay/success" }
|
82
|
+
|
83
|
+
context "and a response is expected" do
|
84
|
+
let(:status) { "AUTHORISED" }
|
85
|
+
|
86
|
+
it "redirects the user with a 300 code" do
|
87
|
+
get path
|
88
|
+
|
89
|
+
expect(response).to redirect_to(response_url)
|
90
|
+
expect(response.code).to eq("302")
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
context "and a response is not expected" do
|
95
|
+
let(:status) { :STUCK }
|
96
|
+
|
97
|
+
it "renders the Worldpay stuck page" do
|
98
|
+
get path
|
99
|
+
|
100
|
+
expect(response).to render_template(:stuck)
|
101
|
+
expect(response.code).to eq("200")
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
context "and the request is invalid" do
|
107
|
+
before(:each) { allow(WorldpayResponseService).to receive(:run).and_raise(MissingResourceError.new("foo")) }
|
108
|
+
|
109
|
+
context "because the success url is not in a recognised format" do
|
110
|
+
let(:success_url) { "http://example.com/forthewin" }
|
111
|
+
|
112
|
+
it "returns a response with a 500 code" do
|
113
|
+
get path
|
114
|
+
|
115
|
+
expect(response.code).to eq("500")
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
context "when mocks are disabled" do
|
123
|
+
before(:each) { DefraRubyMocks.configuration.enable = false }
|
124
|
+
|
125
|
+
context "#payments_service" do
|
126
|
+
let(:path) { "/defra_ruby_mocks/worldpay/payments-service" }
|
127
|
+
|
128
|
+
it "cannot load the page" do
|
129
|
+
expect { get path }.to raise_error(ActionController::RoutingError)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
context "#dispatcher" do
|
134
|
+
let(:path) { "/defra_ruby_mocks/worldpay/dispatcher" }
|
135
|
+
|
136
|
+
it "cannot load the page" do
|
137
|
+
expect { get path }.to raise_error(ActionController::RoutingError)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rails_helper"
|
4
|
+
|
5
|
+
module DefraRubyMocks
|
6
|
+
RSpec.describe WorldpayPaymentService do
|
7
|
+
describe ".run" do
|
8
|
+
after(:each) { Helpers::Configuration.reset_for_tests }
|
9
|
+
|
10
|
+
let(:merchant_code) { "MERCHME" }
|
11
|
+
let(:args) { { merchant_code: merchant_code, xml: xml } }
|
12
|
+
|
13
|
+
context "when the mocks config is missing a worldpay domain" do
|
14
|
+
let(:xml) { nil }
|
15
|
+
|
16
|
+
it "raises a 'InvalidConfigError'" do
|
17
|
+
expect { described_class.run(args) }.to raise_error InvalidConfigError
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context "when the XML is valid" do
|
22
|
+
before(:each) do
|
23
|
+
DefraRubyMocks.configure do |config|
|
24
|
+
config.worldpay_domain = "http://localhost:3000/defra_ruby_mocks"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
let(:xml) { Nokogiri::XML(File.read("spec/fixtures/payment_request_valid.xml")) }
|
29
|
+
|
30
|
+
context "the result it returns" do
|
31
|
+
it "is a hash" do
|
32
|
+
expect(described_class.run(args)).to be_an_instance_of(Hash)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "contains 4 values" do
|
36
|
+
result = described_class.run(args).length
|
37
|
+
expect(result).to eq(4)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "has the merchant code passed in" do
|
41
|
+
result = described_class.run(args)[:merchant_code]
|
42
|
+
|
43
|
+
expect(result).to eq(merchant_code)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "has an order code extracted from the XML" do
|
47
|
+
result = described_class.run(args)[:order_code]
|
48
|
+
|
49
|
+
expect(result).to eq("1577726052")
|
50
|
+
end
|
51
|
+
|
52
|
+
context "has a generated ID which is" do
|
53
|
+
it "10 characters long" do
|
54
|
+
result = described_class.run(args)[:id]
|
55
|
+
|
56
|
+
expect(result.length).to eq(10)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "only made up of the digits 0 to 9" do
|
60
|
+
result = described_class.run(args)[:id]
|
61
|
+
|
62
|
+
expect(result.scan(/\D/).empty?).to be_truthy
|
63
|
+
end
|
64
|
+
|
65
|
+
it "different each time" do
|
66
|
+
results = []
|
67
|
+
3.times do
|
68
|
+
results << described_class.run(args)[:id]
|
69
|
+
end
|
70
|
+
|
71
|
+
expect(results.uniq.length).to eq(results.length)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context "has a url" do
|
76
|
+
it "based on the configured domain, and extracted merchant and order codes" do
|
77
|
+
result = described_class.run(args)[:url]
|
78
|
+
|
79
|
+
expect(result).to eq("http://localhost:3000/defra_ruby_mocks/worldpay/dispatcher?OrderKey=MERCHME%5E1577726052")
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
context "when the XML is invalid" do
|
87
|
+
let(:xml) { Nokogiri::XML(File.read("spec/fixtures/payment_request_invalid.xml")) }
|
88
|
+
|
89
|
+
it "raises an error" do
|
90
|
+
expect { described_class.run(args) }.to raise_error StandardError
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
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
|