defra_ruby_mocks 1.1.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +52 -2
  3. data/Rakefile +0 -2
  4. data/app/controllers/defra_ruby_mocks/company_controller.rb +1 -1
  5. data/app/controllers/defra_ruby_mocks/worldpay_controller.rb +33 -12
  6. data/app/services/defra_ruby_mocks/{worldpay_request_service.rb → worldpay_payment_service.rb} +3 -9
  7. data/app/services/defra_ruby_mocks/worldpay_refund_service.rb +37 -0
  8. data/app/services/defra_ruby_mocks/worldpay_request_handler_service.rb +40 -0
  9. data/app/services/defra_ruby_mocks/worldpay_resource_service.rb +55 -0
  10. data/app/services/defra_ruby_mocks/worldpay_response_service.rb +71 -52
  11. data/app/views/defra_ruby_mocks/worldpay/payment_request.xml.erb +4 -0
  12. data/app/views/defra_ruby_mocks/worldpay/refund_request.xml.erb +4 -0
  13. data/app/views/defra_ruby_mocks/worldpay/stuck.html.erb +37 -0
  14. data/lib/defra_ruby_mocks/engine.rb +2 -1
  15. data/lib/defra_ruby_mocks/missing_resource_error.rb +9 -0
  16. data/lib/defra_ruby_mocks/unrecognised_worldpay_request_error.rb +5 -0
  17. data/lib/defra_ruby_mocks/version.rb +1 -1
  18. data/spec/dummy/log/development.log +180 -0
  19. data/spec/dummy/log/test.log +1287 -323
  20. data/spec/examples.txt +99 -56
  21. data/spec/fixtures/{worldpay_request_invalid.xml → payment_request_invalid.xml} +0 -0
  22. data/spec/fixtures/{worldpay_request_valid.xml → payment_request_valid.xml} +0 -0
  23. data/spec/fixtures/refund_request_invalid.xml +6 -0
  24. data/spec/fixtures/refund_request_valid.xml +11 -0
  25. data/spec/fixtures/unrecognised_request.xml +6 -0
  26. data/spec/requests/worldpay_spec.rb +87 -26
  27. data/spec/services/{worldpay_request_service_spec.rb → worldpay_payment_service_spec.rb} +25 -22
  28. data/spec/services/worldpay_refund_service_spec.rb +68 -0
  29. data/spec/services/worldpay_request_handler_service_spec.rb +79 -0
  30. data/spec/services/worldpay_resource_service_spec.rb +112 -0
  31. data/spec/services/worldpay_response_service_spec.rb +185 -58
  32. data/spec/support/helpers/xml_matchers.rb +19 -0
  33. metadata +50 -17
  34. data/app/views/defra_ruby_mocks/worldpay/payments_service.xml.erb +0 -4
  35. data/lib/defra_ruby_mocks/missing_registration_error.rb +0 -9
@@ -1,56 +1,99 @@
1
- example_id | status | run_time |
2
- ------------------------------------------------------------- | ------ | --------------- |
3
- ./spec/defra_ruby_mocks_spec.rb[1:1:1] | passed | 0.00552 seconds |
4
- ./spec/defra_ruby_mocks_spec.rb[1:2:1:1] | passed | 0.00013 seconds |
5
- ./spec/defra_ruby_mocks_spec.rb[1:2:2:1] | passed | 0.00016 seconds |
6
- ./spec/lib/configuration_spec.rb[1:1:1:1] | passed | 0.00009 seconds |
7
- ./spec/lib/configuration_spec.rb[1:1:2:1] | passed | 0.00009 seconds |
8
- ./spec/lib/configuration_spec.rb[1:1:3:1] | passed | 0.0001 seconds |
9
- ./spec/lib/configuration_spec.rb[1:1:4:1] | passed | 0.00008 seconds |
10
- ./spec/lib/configuration_spec.rb[1:2:1:1] | passed | 0.00238 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.0001 seconds |
13
- ./spec/lib/configuration_spec.rb[1:2:4:1] | passed | 0.00011 seconds |
14
- ./spec/requests/company_spec.rb[1:1:1:1] | passed | 0.00478 seconds |
15
- ./spec/requests/company_spec.rb[1:1:2:1] | passed | 0.065 seconds |
16
- ./spec/requests/company_spec.rb[1:1:3:1:1] | passed | 0.00475 seconds |
17
- ./spec/requests/company_spec.rb[1:1:3:2:1] | passed | 0.01227 seconds |
18
- ./spec/requests/company_spec.rb[1:2:1] | passed | 0.0137 seconds |
19
- ./spec/requests/worldpay_spec.rb[1:1:1:1:1] | passed | 0.02505 seconds |
20
- ./spec/requests/worldpay_spec.rb[1:1:1:2:1] | passed | 0.00472 seconds |
21
- ./spec/requests/worldpay_spec.rb[1:1:2:1:1] | passed | 0.00564 seconds |
22
- ./spec/requests/worldpay_spec.rb[1:1:2:2:1:1] | passed | 0.00433 seconds |
23
- ./spec/requests/worldpay_spec.rb[1:2:1:1] | passed | 0.00355 seconds |
24
- ./spec/requests/worldpay_spec.rb[1:2:2:1] | passed | 0.00297 seconds |
25
- ./spec/services/companies_house_service_spec.rb[1:1:1:1] | passed | 0.00013 seconds |
26
- ./spec/services/companies_house_service_spec.rb[1:1:2:1:1] | passed | 0.00009 seconds |
27
- ./spec/services/companies_house_service_spec.rb[1:1:2:2:1] | passed | 0.00009 seconds |
28
- ./spec/services/companies_house_service_spec.rb[1:1:2:3:1] | passed | 0.00011 seconds |
29
- ./spec/services/companies_house_service_spec.rb[1:1:2:4:1] | passed | 0.00009 seconds |
30
- ./spec/services/companies_house_service_spec.rb[1:1:2:5:1] | passed | 0.00009 seconds |
31
- ./spec/services/companies_house_service_spec.rb[1:1:2:6:1] | passed | 0.00009 seconds |
32
- ./spec/services/companies_house_service_spec.rb[1:1:2:7:1] | passed | 0.0001 seconds |
33
- ./spec/services/companies_house_service_spec.rb[1:1:2:8:1] | passed | 0.00009 seconds |
34
- ./spec/services/companies_house_service_spec.rb[1:1:2:9:1] | passed | 0.00009 seconds |
35
- ./spec/services/companies_house_service_spec.rb[1:1:3:1:1] | passed | 0.0001 seconds |
36
- ./spec/services/companies_house_service_spec.rb[1:1:3:2:1] | passed | 0.00012 seconds |
37
- ./spec/services/worldpay_request_service_spec.rb[1:1:1:1] | passed | 0.00014 seconds |
38
- ./spec/services/worldpay_request_service_spec.rb[1:1:2:1:1] | passed | 0.00233 seconds |
39
- ./spec/services/worldpay_request_service_spec.rb[1:1:2:1:2] | passed | 0.00076 seconds |
40
- ./spec/services/worldpay_request_service_spec.rb[1:1:2:1:3:1] | passed | 0.0005 seconds |
41
- ./spec/services/worldpay_request_service_spec.rb[1:1:2:1:3:2] | passed | 0.00047 seconds |
42
- ./spec/services/worldpay_request_service_spec.rb[1:1:2:1:4:1] | passed | 0.0005 seconds |
43
- ./spec/services/worldpay_request_service_spec.rb[1:1:2:1:4:2] | passed | 0.0005 seconds |
44
- ./spec/services/worldpay_request_service_spec.rb[1:1:2:1:4:3] | passed | 0.00084 seconds |
45
- ./spec/services/worldpay_request_service_spec.rb[1:1:2:1:5:1] | passed | 0.00056 seconds |
46
- ./spec/services/worldpay_request_service_spec.rb[1:1:3:1] | passed | 0.00032 seconds |
47
- ./spec/services/worldpay_response_service_spec.rb[1:1:1:1:1] | passed | 0.00076 seconds |
48
- ./spec/services/worldpay_response_service_spec.rb[1:1:1:1:2] | passed | 0.00083 seconds |
49
- ./spec/services/worldpay_response_service_spec.rb[1:1:1:1:3] | passed | 0.0009 seconds |
50
- ./spec/services/worldpay_response_service_spec.rb[1:1:1:1:4] | passed | 0.00081 seconds |
51
- ./spec/services/worldpay_response_service_spec.rb[1:1:1:2:1] | passed | 0.00063 seconds |
52
- ./spec/services/worldpay_response_service_spec.rb[1:1:2:1:1] | passed | 0.02869 seconds |
53
- ./spec/services/worldpay_response_service_spec.rb[1:1:2:1:2] | passed | 0.0011 seconds |
54
- ./spec/services/worldpay_response_service_spec.rb[1:1:2:1:3] | passed | 0.00111 seconds |
55
- ./spec/services/worldpay_response_service_spec.rb[1:1:2:1:4] | passed | 0.00138 seconds |
56
- ./spec/services/worldpay_response_service_spec.rb[1:1:2:2:1] | passed | 0.00091 seconds |
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 |
@@ -0,0 +1,6 @@
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">
4
+ <modify>
5
+ </modify>
6
+ </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>
@@ -0,0 +1,6 @@
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
+ <boom>
5
+ </boom>
6
+ </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 "and the request is valid" do
23
- let(:data) { File.read("spec/fixtures/worldpay_request_valid.xml") }
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
- it "returns an XML response with a 200 code" do
26
- get path, {}, "RAW_POST_DATA" => data
38
+ it "returns a response with a 500 code" do
39
+ get path, {}, "RAW_POST_DATA" => data
27
40
 
28
- expect(response.content_type).to eq("application/xml")
29
- expect(response.code).to eq("200")
41
+ expect(response.code).to eq("500")
42
+ end
30
43
  end
31
44
  end
32
45
 
33
- context "and the request is invalid" do
34
- let(:data) { File.read("spec/fixtures/worldpay_request_invalid.xml") }
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
- it "returns a response with a 500 code" do
37
- get path, {}, "RAW_POST_DATA" => data
50
+ it "returns an XML response with a 200 code" do
51
+ get path, {}, "RAW_POST_DATA" => data
38
52
 
39
- expect(response.code).to eq("500")
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(:relation) { double(:relation, first: registration) }
46
- let(:registration) { double(:registration, finance_details: finance_details) }
47
- let(:finance_details) { double(:finance_details, orders: orders) }
48
- let(:orders) { double(:orders, order_by: sorted_orders) }
49
- let(:sorted_orders) { double(:sorted_orders, first: order) }
50
- let(:order) { double(:order, order_code: "987654", total_amount: 105_00) }
51
-
52
- let(:path) { "/defra_ruby_mocks/worldpay/dispatcher?successURL=#{CGI.escape(success_url)}" }
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
- let(:response_params) { "orderKey=admincode1^^987654&paymentStatus=AUTHORISED&paymentAmount=10500&paymentCurrency=GBP&mac=0ba5271e1ed1b26f9bb428ef7fb536a4&source=WP" }
56
- let(:success_url) { "http://example.com/fo/12345/worldpay/success" }
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
- it "redirects the user with a 300 code" do
59
- expect(::WasteCarriersEngine::TransientRegistration).to receive(:where) { relation }
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
- get path
118
+ it "renders the Worldpay stuck page" do
119
+ get path
62
120
 
63
- expect(response).to redirect_to("#{success_url}?#{response_params}")
64
- expect(response.code).to eq("302")
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 WorldpayRequestService do
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(nil) }.to raise_error InvalidConfigError
17
+ expect { described_class.run(args) }.to raise_error InvalidConfigError
13
18
  end
14
19
  end
15
20
 
16
- context "when the XML data is valid" do
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(:data) { File.read("spec/fixtures/worldpay_request_valid.xml") }
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(data)).to be_an_instance_of(Hash)
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(data).length
36
+ result = described_class.run(args).length
32
37
  expect(result).to eq(4)
33
38
  end
34
39
 
35
- context "has values extracted from the XML data" do
36
- it "a merchant code" do
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
- expect(result).to eq("MERCHME")
40
- end
43
+ expect(result).to eq(merchant_code)
44
+ end
41
45
 
42
- it "an order code" do
43
- result = described_class.run(data)[:order_code]
46
+ it "has an order code extracted from the XML" do
47
+ result = described_class.run(args)[:order_code]
44
48
 
45
- expect(result).to eq("1577726052")
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(data)[:id]
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(data)[:id]
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(data)[:id]
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(data)[:url]
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 data is invalid" do
84
- let(:data) { File.read("spec/fixtures/worldpay_request_invalid.xml") }
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(data) }.to raise_error StandardError
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