sepafm 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +14 -30
  3. data/.ruby-version +1 -1
  4. data/.travis.yml +15 -0
  5. data/Gemfile +1 -1
  6. data/LICENSE +16 -4
  7. data/README.md +180 -319
  8. data/Rakefile +7 -2
  9. data/lib/sepa/application_request.rb +100 -131
  10. data/lib/sepa/application_response.rb +28 -84
  11. data/lib/sepa/attribute_checks.rb +169 -0
  12. data/lib/sepa/banks/danske/danske_response.rb +19 -0
  13. data/lib/sepa/banks/danske/soap_danske.rb +132 -0
  14. data/lib/sepa/banks/nordea/nordea_response.rb +20 -0
  15. data/lib/sepa/banks/nordea/soap_nordea.rb +51 -0
  16. data/lib/sepa/client.rb +72 -60
  17. data/lib/sepa/error_messages.rb +15 -0
  18. data/lib/sepa/response.rb +88 -85
  19. data/lib/sepa/soap_builder.rb +51 -341
  20. data/lib/sepa/utilities.rb +132 -0
  21. data/lib/sepa/version.rb +1 -1
  22. data/lib/sepa/xml_schemas/PKIFactory.xsd +334 -0
  23. data/lib/sepa/xml_schemas/xml_id.xsd +9 -0
  24. data/lib/sepa/xml_templates/application_request/create_certificate.xml +15 -10
  25. data/lib/sepa/xml_templates/application_request/danske_get_bank_certificate.xml +13 -9
  26. data/lib/sepa/xml_templates/application_request/download_file.xml +32 -30
  27. data/lib/sepa/xml_templates/application_request/download_file_list.xml +29 -27
  28. data/lib/sepa/xml_templates/application_request/encrypted_request.xml +22 -0
  29. data/lib/sepa/xml_templates/application_request/get_certificate.xml +9 -8
  30. data/lib/sepa/xml_templates/application_request/get_user_info.xml +26 -24
  31. data/lib/sepa/xml_templates/application_request/upload_file.xml +29 -27
  32. data/lib/sepa/xml_templates/soap/create_certificate.xml +17 -15
  33. data/lib/sepa/xml_templates/soap/danske_get_bank_certificate.xml +15 -13
  34. data/lib/sepa/xml_templates/soap/download_file.xml +19 -15
  35. data/lib/sepa/xml_templates/soap/download_file_list.xml +19 -15
  36. data/lib/sepa/xml_templates/soap/get_certificate.xml +2 -1
  37. data/lib/sepa/xml_templates/soap/get_user_info.xml +19 -15
  38. data/lib/sepa/xml_templates/soap/header.xml +48 -37
  39. data/lib/sepa/xml_templates/soap/upload_file.xml +19 -15
  40. data/lib/sepafm.rb +20 -18
  41. data/{sepa.gemspec → sepafm.gemspec} +10 -9
  42. data/test/sepa/banks/danske/danske_cert_response_test.rb +52 -0
  43. data/test/sepa/banks/danske/danske_cert_soap_builder_test.rb +100 -0
  44. data/test/sepa/banks/danske/danske_generic_soap_builder_test.rb +278 -0
  45. data/test/sepa/banks/danske/danske_get_bank_cert_test.rb +111 -0
  46. data/{lib/sepa/danske_testing/keys/danske_encryption.crt → test/sepa/banks/danske/keys/bank_encryption_cert.pem} +0 -0
  47. data/test/sepa/{danske_test_keys/danskeroot.pem → banks/danske/keys/bank_root_cert.pem} +1 -1
  48. data/test/sepa/banks/danske/keys/bank_signing_cert.pem +24 -0
  49. data/test/sepa/banks/danske/keys/danske_encryption.crt +24 -0
  50. data/test/sepa/banks/danske/keys/enc_private_key.pem +27 -0
  51. data/test/sepa/{danske_test_keys → banks/danske/keys}/encryption_pkcs.csr +0 -0
  52. data/test/sepa/banks/danske/keys/own_enc_cert.pem +21 -0
  53. data/test/sepa/banks/danske/keys/own_signing_cert.pem +22 -0
  54. data/test/sepa/{danske_test_keys → banks/danske/keys}/signing_key.pem +0 -0
  55. data/test/sepa/{danske_test_keys → banks/danske/keys}/signing_pkcs.csr +0 -0
  56. data/test/sepa/banks/danske/keys/signing_private_key.pem +27 -0
  57. data/test/sepa/banks/danske/responses/create_cert.xml +38 -0
  58. data/test/sepa/banks/danske/responses/get_bank_cert.xml +37 -0
  59. data/{lib/sepa/nordea_testing → test/sepa/banks/nordea}/keys/nordea.crt +0 -4
  60. data/test/sepa/{nordea_test_keys → banks/nordea/keys}/nordea.key +0 -3
  61. data/test/sepa/{nordea_test_keys → banks/nordea/keys}/root_cert.cer +0 -0
  62. data/test/sepa/{nordea_test_keys → banks/nordea/keys}/testcert.csr +0 -0
  63. data/test/sepa/banks/nordea/nordea_application_request_test.rb +252 -0
  64. data/test/sepa/{application_response_test.rb → banks/nordea/nordea_application_response_test.rb} +40 -46
  65. data/test/sepa/banks/nordea/nordea_cert_application_request_test.rb +72 -0
  66. data/test/sepa/banks/nordea/nordea_cert_request_soap_builder_test.rb +65 -0
  67. data/test/sepa/banks/nordea/nordea_generic_soap_builder_test.rb +280 -0
  68. data/test/sepa/banks/nordea/nordea_response_test.rb +116 -0
  69. data/test/sepa/banks/nordea/responses/df_ktl.xml +45 -0
  70. data/test/sepa/{test_files/test_responses/df.xml → banks/nordea/responses/df_tito.xml} +1 -1
  71. data/test/sepa/{test_files/test_responses → banks/nordea/responses}/dfl.xml +0 -0
  72. data/test/sepa/banks/nordea/responses/gbc.xml +15 -0
  73. data/test/sepa/banks/nordea/responses/gc.xml +49 -0
  74. data/test/sepa/{test_files/test_responses → banks/nordea/responses}/gui.xml +0 -0
  75. data/test/sepa/{test_files/test_responses → banks/nordea/responses}/uf.xml +0 -0
  76. data/test/sepa/client_test.rb +156 -302
  77. data/test/sepa/fixtures.rb +214 -0
  78. data/test/sepa/sepa_test.rb +3 -13
  79. data/test/sepa/test_files/{invalid.wsdl → invalid_wsdl.wsdl} +0 -0
  80. data/test/test_helper.rb +29 -3
  81. metadata +140 -116
  82. data/lib/danske_get_bank_certificate_test.rb +0 -15
  83. data/lib/sepa/custom_exceptions.rb +0 -2
  84. data/lib/sepa/filedescriptor.rb +0 -7
  85. data/lib/sepa/filetypeservice.rb +0 -6
  86. data/lib/sepa/nordea_testing/keys/CSR.csr +0 -0
  87. data/lib/sepa/nordea_testing/keys/nordea.key +0 -19
  88. data/lib/sepa/nordea_testing/response/content_053.xml +0 -998
  89. data/lib/sepa/nordea_testing/response/content_054.xml +0 -1
  90. data/lib/sepa/nordea_testing/response/download_file_response.xml +0 -14
  91. data/lib/sepa/nordea_testing/response/download_filelist_response.xml +0 -14
  92. data/lib/sepa/nordea_testing/response/get_user_info_response.xml +0 -14
  93. data/lib/sepa/nordea_testing/response/upload_file_response.xml +0 -14
  94. data/lib/sepa/payload.rb +0 -109
  95. data/lib/sepa/payment.rb +0 -97
  96. data/lib/sepa/sender_verifier.rb +0 -15
  97. data/lib/sepa/signature.rb +0 -7
  98. data/lib/sepa/soap_danske.rb +0 -47
  99. data/lib/sepa/soap_nordea.rb +0 -68
  100. data/lib/sepa/transaction.rb +0 -178
  101. data/lib/sepa/userfiletype.rb +0 -16
  102. data/lib/sepa/xml_parser.rb +0 -291
  103. data/lib/sepa_client_testing_mika.rb +0 -32
  104. data/lib/sepa_client_testing_tiere.rb +0 -257
  105. data/test/sepa/application_request_test.rb +0 -423
  106. data/test/sepa/cert_application_request_test.rb +0 -99
  107. data/test/sepa/nordea_cert_request_soap_builder_test.rb +0 -112
  108. data/test/sepa/nordea_generic_soap_builder_test.rb +0 -427
  109. data/test/sepa/nordea_test_keys/nordea.crt +0 -27
  110. data/test/sepa/payload_test.rb +0 -297
  111. data/test/sepa/payment_test.rb +0 -198
  112. data/test/sepa/response_test.rb +0 -269
  113. data/test/sepa/transaction_test.rb +0 -362
  114. data/test/sepa/user_file_type_test.rb +0 -21
  115. data/test/sepa/xml_parser_test.rb +0 -73
@@ -1,269 +0,0 @@
1
- require File.expand_path('../../test_helper.rb', __FILE__)
2
-
3
- class ResponseTest < MiniTest::Test
4
- def setup
5
- keys_path = File.expand_path('../nordea_test_keys', __FILE__)
6
-
7
- @root_cert = OpenSSL::X509::Certificate.new File.read(
8
- "#{keys_path}/root_cert.cer"
9
- )
10
-
11
- @not_root_cert = OpenSSL::X509::Certificate.new File.read(
12
- "#{keys_path}/nordea.crt"
13
- )
14
-
15
- responses_path = File.expand_path('../test_files/test_responses', __FILE__)
16
-
17
- # Response that was requested with :download_file_list command
18
- @dfl = Nokogiri::XML(File.read("#{responses_path}/dfl.xml"))
19
-
20
- # Response that was requested with :upload_file command
21
- @uf = Nokogiri::XML(File.read("#{responses_path}/uf.xml"))
22
-
23
- # Response that was requested with :download_file command
24
- @df = Nokogiri::XML(File.read("#{responses_path}/df.xml"))
25
-
26
- # Response that was requested with :get_user_info command
27
- @gui = Nokogiri::XML(File.read("#{responses_path}/gui.xml"))
28
-
29
- # Actual response objects for testing.
30
- @dfl_response = Sepa::Response.new(@dfl)
31
- @uf_response = Sepa::Response.new(@uf)
32
- @df_response = Sepa::Response.new(@df)
33
- @gui_response = Sepa::Response.new(@gui)
34
- end
35
-
36
- def test_should_initialize_with_proper_response
37
- assert Sepa::Response.new(@dfl)
38
- end
39
-
40
- def test_should_complain_if_initialized_with_something_not_nokogiri_xml
41
- assert_raises(ArgumentError) { Sepa::Response.new("Sammakko") }
42
- end
43
-
44
- def test_should_complain_if_response_not_valid_against_schema
45
- assert_raises(ArgumentError) do
46
- Sepa::Response.new(Nokogiri::XML("<tomaatti>moikka</tomaatti>"))
47
- end
48
- end
49
-
50
- def test_proper_dfl_hash_check_should_verify
51
- assert Sepa::Response.new(@dfl).hashes_match?
52
- end
53
-
54
- def test_proper_uf_hash_check_should_verify
55
- assert Sepa::Response.new(@uf).hashes_match?
56
- end
57
-
58
- def test_proper_df_hash_check_should_verify
59
- assert Sepa::Response.new(@df).hashes_match?
60
- end
61
-
62
- def test_proper_gui_hash_check_should_verify
63
- assert Sepa::Response.new(@gui).hashes_match?
64
- end
65
-
66
- def test_corrupted_hash_in_dfl_should_fail_hash_check
67
- hash_node = @dfl.css(
68
- 'xmlns|DigestValue',
69
- 'xmlns' => 'http://www.w3.org/2000/09/xmldsig#'
70
- )[0]
71
-
72
- hash_node.content = Base64.encode64('alsdflsdhf'*6)
73
-
74
- refute Sepa::Response.new(@dfl).hashes_match?
75
- end
76
-
77
- def test_corrupted_hash_in_uf_should_fail_hash_check
78
- hash_node = @uf.css(
79
- 'xmlns|DigestValue',
80
- 'xmlns' => 'http://www.w3.org/2000/09/xmldsig#'
81
- )[1]
82
-
83
- wrong_value = Base64.encode64(OpenSSL::Digest::SHA1.new.digest('hemuli'))
84
-
85
- hash_node.content = wrong_value
86
-
87
- refute Sepa::Response.new(@uf).hashes_match?
88
- end
89
-
90
- def test_corrupted_hash_in_df_should_fail_hash_check
91
- hash_node = @df.css(
92
- 'xmlns|DigestValue',
93
- 'xmlns' => 'http://www.w3.org/2000/09/xmldsig#'
94
- )[0]
95
- wrong_value = Base64.encode64(
96
- OpenSSL::Digest::SHA1.new.digest('whatifitoldyouimnotavalidvalueforhash' \
97
- 'ing')
98
- )
99
-
100
- hash_node.content = wrong_value
101
-
102
- refute Sepa::Response.new(@df).hashes_match?
103
- end
104
-
105
- def test_corrupted_hash_in_gui_should_fail_hash_check
106
- hash_node = @gui.css(
107
- 'xmlns|DigestValue',
108
- 'xmlns' => 'http://www.w3.org/2000/09/xmldsig#'
109
- )[1]
110
-
111
- hash_node.content = hash_node.content[6..-1]
112
-
113
- refute Sepa::Response.new(@gui).hashes_match?
114
- end
115
-
116
- def test_proper_dfl_signature_should_verify
117
- assert Sepa::Response.new(@dfl).signature_is_valid?
118
- end
119
-
120
- def test_proper_uf_signature_should_verify
121
- assert Sepa::Response.new(@uf).signature_is_valid?
122
- end
123
-
124
- def test_proper_df_signature_should_verify
125
- assert Sepa::Response.new(@df).signature_is_valid?
126
- end
127
-
128
- def test_proper_gui_signature_should_verify
129
- assert Sepa::Response.new(@gui).signature_is_valid?
130
- end
131
-
132
- def test_corrupted_signature_in_dfl_should_fail_signature_verification
133
- signature_node = @dfl.at_css(
134
- 'xmlns|SignatureValue',
135
- 'xmlns' => 'http://www.w3.org/2000/09/xmldsig#'
136
- )
137
-
138
- signature_node.content = signature_node.content[1..-1]
139
-
140
- refute Sepa::Response.new(@dfl).signature_is_valid?
141
- end
142
-
143
- def test_corrupted_signature_in_uf_should_fail_signature_verification
144
- signature_node = @uf.at_css(
145
- 'xmlns|SignatureValue',
146
- 'xmlns' => 'http://www.w3.org/2000/09/xmldsig#'
147
- )
148
-
149
- signature_node.content = signature_node.content[6..-4]
150
-
151
- refute Sepa::Response.new(@uf).signature_is_valid?
152
- end
153
-
154
- def test_corrupted_signature_in_df_should_fail_signature_verification
155
- signature_node = @df.at_css(
156
- 'xmlns|SignatureValue',
157
- 'xmlns' => 'http://www.w3.org/2000/09/xmldsig#'
158
- )
159
-
160
- signature_node.content = signature_node.content[0..-2]
161
-
162
- refute Sepa::Response.new(@df).signature_is_valid?
163
- end
164
-
165
- def test_corrupted_signature_in_gui_should_fail_signature_verification
166
- signature_node = @gui.at_css(
167
- 'xmlns|SignatureValue',
168
- 'xmlns' => 'http://www.w3.org/2000/09/xmldsig#'
169
- )
170
-
171
- signature_node.content = 'i' + signature_node.content
172
-
173
- refute Sepa::Response.new(@gui).signature_is_valid?
174
- end
175
-
176
- def test_should_raise_error_if_certificate_corrupted_in_dfl
177
- cert_node = @dfl.at_css(
178
- 'wsse|BinarySecurityToken',
179
- 'wsse' => 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-ws' \
180
- 'security-secext-1.0.xsd'
181
- )
182
-
183
- cert_node.content = cert_node.content + 'a'
184
-
185
- assert_raises(OpenSSL::X509::CertificateError) do
186
- Sepa::Response.new(@dfl).signature_is_valid?
187
- end
188
- end
189
-
190
- def test_should_raise_error_if_certificate_corrupted_in_uf
191
- cert_node = @uf.at_css(
192
- 'wsse|BinarySecurityToken',
193
- 'wsse' => 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-ws' \
194
- 'security-secext-1.0.xsd'
195
- )
196
-
197
- cert_node.content = cert_node.content[1..-1]
198
-
199
- assert_raises(OpenSSL::X509::CertificateError) do
200
- Sepa::Response.new(@uf).signature_is_valid?
201
- end
202
- end
203
-
204
- def test_should_raise_error_if_certificate_corrupted_in_df
205
- cert_node = @df.at_css(
206
- 'wsse|BinarySecurityToken',
207
- 'wsse' => 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-ws' \
208
- 'security-secext-1.0.xsd'
209
- )
210
-
211
- cert_node.content = cert_node.content[0..-5]
212
-
213
- assert_raises(OpenSSL::X509::CertificateError) do
214
- Sepa::Response.new(@df).signature_is_valid?
215
- end
216
- end
217
-
218
- def test_should_raise_error_if_certificate_corrupted_in_gui
219
- cert_node = @gui.at_css(
220
- 'wsse|BinarySecurityToken',
221
- 'wsse' => 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-ws' \
222
- 'security-secext-1.0.xsd'
223
- )
224
-
225
- cert_node.content = cert_node.content[9..-1]
226
-
227
- assert_raises(OpenSSL::X509::CertificateError) do
228
- Sepa::Response.new(@gui).signature_is_valid?
229
- end
230
- end
231
-
232
- def test_should_return_certificate_with_certificate_method
233
- assert @dfl_response.certificate.respond_to?(:public_key)
234
- assert @uf_response.certificate.respond_to?(:public_key)
235
- assert @df_response.certificate.respond_to?(:public_key)
236
- assert @gui_response.certificate.respond_to?(:public_key)
237
- end
238
-
239
- def test_cert_should_be_trusted_with_correct_root_cert
240
- assert @dfl_response.cert_is_trusted?(@root_cert)
241
- assert @uf_response.cert_is_trusted?(@root_cert)
242
- assert @df_response.cert_is_trusted?(@root_cert)
243
- assert @gui_response.cert_is_trusted?(@root_cert)
244
- end
245
-
246
- def test_dfl_should_fail_if_wrong_root_cert
247
- assert_raises(SecurityError) do
248
- @dfl_response.cert_is_trusted?(@not_root_cert)
249
- end
250
- end
251
-
252
- def test_uf_should_fail_if_wrong_root_cert
253
- assert_raises(SecurityError) do
254
- @uf_response.cert_is_trusted?(@not_root_cert)
255
- end
256
- end
257
-
258
- def test_df_should_fail_if_wrong_root_cert
259
- assert_raises(SecurityError) do
260
- @df_response.cert_is_trusted?(@not_root_cert)
261
- end
262
- end
263
-
264
- def test_gui_should_fail_if_wrong_root_cert
265
- assert_raises(SecurityError) do
266
- @gui_response.cert_is_trusted?(@not_root_cert)
267
- end
268
- end
269
- end
@@ -1,362 +0,0 @@
1
- require File.expand_path('../../test_helper.rb', __FILE__)
2
-
3
- class TestTransaction < MiniTest::Test
4
- def setup
5
- @invoice_bundle = []
6
-
7
- invoice_1 = {
8
- type: 'CINV',
9
- amount: '700',
10
- currency: 'EUR',
11
- invoice_number: '123456'
12
- }
13
-
14
- invoice_2 = {
15
- type: 'CINV',
16
- amount: '300',
17
- currency: 'EUR',
18
- reference: '123456789',
19
- }
20
-
21
- invoice_3 = {
22
- type: 'CREN',
23
- amount: '-100',
24
- currency: 'EUR',
25
- invoice_number: '654321'
26
- }
27
-
28
- invoice_4 = {
29
- type: 'CREN',
30
- amount: '-500',
31
- currency: 'EUR',
32
- reference: '987654321'
33
- }
34
-
35
- @invoice_bundle.push(invoice_1)
36
- @invoice_bundle.push(invoice_2)
37
- @invoice_bundle.push(invoice_3)
38
- @invoice_bundle.push(invoice_4)
39
-
40
- @params = {
41
- instruction_id: '70CEF29BEBA8396A1F806005EDA51DEE4CE',
42
- end_to_end_id: '629CADFDAD5246AD915BA24A3C8E9FC3313',
43
- amount: '30.75',
44
- currency: 'EUR',
45
- bic: 'NDEAFIHH',
46
- name: 'Testi Saaja Oy',
47
- address: 'Kokeilukatu 66',
48
- country: 'FI',
49
- postcode: '00200',
50
- town: 'Helsinki',
51
- iban: 'FI7429501800000014',
52
- reference: '00000000000000001245',
53
- message: 'Maksu',
54
- social_security_number: '112233-0005'
55
- }
56
-
57
- @transaction = Sepa::Transaction.new(@params)
58
- @transaction_node = @transaction.to_node
59
- end
60
-
61
- def test_should_initialize_with_proper_params
62
- assert Sepa::Transaction.new(@params)
63
- end
64
-
65
- def test_instruction_id_is_set_correctly
66
- assert_equal @params[:instruction_id],
67
- @transaction_node.at('/CdtTrfTxInf/PmtId/InstrId').content
68
- end
69
-
70
- def test_end_to_end_id_is_set_correctly
71
- assert_equal @params[:end_to_end_id],
72
- @transaction_node.at('/CdtTrfTxInf/PmtId/EndToEndId').content
73
- end
74
-
75
- def test_amount_is_set_correctly
76
- assert_equal @params[:amount],
77
- @transaction_node.at('/CdtTrfTxInf/Amt/InstdAmt').content
78
- end
79
-
80
- def test_currency_is_set_correctly
81
- assert_equal @params[:currency],
82
- @transaction_node.at('/CdtTrfTxInf/Amt/InstdAmt/@Ccy').content
83
- end
84
-
85
- def test_bic_is_set_correctly
86
- assert_equal @params[:bic],
87
- @transaction_node.at('/CdtTrfTxInf/CdtrAgt/FinInstnId/BIC').content
88
- end
89
-
90
- def test_name_is_set_correctly
91
- assert_equal @params[:name],
92
- @transaction_node.at('/CdtTrfTxInf/Cdtr/Nm').content
93
- end
94
-
95
- def test_first_address_line_is_set_correctly
96
- assert_equal @params[:address],
97
- @transaction_node.at('/CdtTrfTxInf/Cdtr/PstlAdr/AdrLine[1]').content
98
- end
99
-
100
- def test_second_address_line_is_set_correctly
101
- assert_equal "#{@params[:country]}-#{@params[:postcode]} #{@params[:town]}",
102
- @transaction_node.at('/CdtTrfTxInf/Cdtr/PstlAdr/AdrLine[2]').content
103
- end
104
-
105
- def test_street_name_is_set_correctly
106
- assert_equal @params[:address],
107
- @transaction_node.at('/CdtTrfTxInf/Cdtr/PstlAdr/StrtNm').content
108
- end
109
-
110
- def test_postcode_is_set_correctly
111
- assert_equal "#{@params[:country]}-#{@params[:postcode]}",
112
- @transaction_node.at('/CdtTrfTxInf/Cdtr/PstlAdr/PstCd').content
113
- end
114
-
115
- def test_town_is_set_correctly
116
- assert_equal @params[:town],
117
- @transaction_node.at('/CdtTrfTxInf/Cdtr/PstlAdr/TwnNm').content
118
- end
119
-
120
- def test_country_is_set_correctly
121
- assert_equal @params[:country],
122
- @transaction_node.at('/CdtTrfTxInf/Cdtr/PstlAdr/Ctry').content
123
- end
124
-
125
- def test_iban_is_set_correctly
126
- assert_equal @params[:iban],
127
- @transaction_node.at('/CdtTrfTxInf/CdtrAcct/Id/IBAN').content
128
- end
129
-
130
- def test_reference_is_set_if_present
131
- assert_equal @params[:reference],
132
- @transaction_node.at(
133
- '/CdtTrfTxInf/RmtInf/Strd/CdtrRefInf/CdtrRef'
134
- ).content
135
- end
136
-
137
- def test_message_is_not_set_when_reference_is_present
138
- refute @transaction_node.at('/CdtTrfTxInf/RmtInf/Ustrd')
139
- end
140
-
141
- def test_message_is_set_when_reference_not_present
142
- @params.delete(:reference)
143
-
144
- transaction = Sepa::Transaction.new(@params)
145
- transaction_node = transaction.to_node
146
-
147
- assert_equal @params[:message],
148
- transaction_node.at('/CdtTrfTxInf/RmtInf/Ustrd').content
149
- end
150
-
151
- def test_social_security_number_is_set_correctly_when_salary
152
- @params[:salary] = true
153
- transaction = Sepa::Transaction.new(@params)
154
- transaction_node = transaction.to_node
155
-
156
- assert_equal @params[:social_security_number],
157
- transaction_node.at('/CdtTrfTxInf/Cdtr/Id/PrvtId/SclSctyNb').content
158
- end
159
-
160
- def test_purpose_is_set_correctly_when_pension
161
- @params[:pension] = true
162
- transaction = Sepa::Transaction.new(@params)
163
- transaction_node = transaction.to_node
164
-
165
- assert_equal transaction_node.at('/CdtTrfTxInf/Purp/Cd').content,
166
- 'PENS'
167
- end
168
-
169
- def test_invoice_bundle_is_added_correctly
170
- @params[:invoice_bundle] = @invoice_bundle
171
- transaction = Sepa::Transaction.new(@params)
172
- transaction_node = transaction.to_node
173
-
174
- assert_equal @invoice_bundle.count,
175
- transaction_node.xpath('/CdtTrfTxInf/RmtInf/Strd').count
176
- end
177
-
178
- def test_raises_key_error_if_end_to_end_id_missing
179
- @params.delete(:end_to_end_id)
180
- assert_raises(KeyError) { transaction = Sepa::Transaction.new(@params) }
181
- end
182
-
183
- def test_raises_key_error_if_invoice_amount_missing
184
- @invoice_bundle[0].delete(:amount)
185
- @params[:invoice_bundle] = @invoice_bundle
186
-
187
- assert_raises(KeyError) { transaction = Sepa::Transaction.new(@params) }
188
- end
189
-
190
- def test_raises_key_error_if_invoice_type_missing
191
- @invoice_bundle[1].delete(:type)
192
- @params[:invoice_bundle] = @invoice_bundle
193
- transaction = Sepa::Transaction.new(@params)
194
-
195
- assert_raises(KeyError) { transaction.to_node }
196
- end
197
-
198
- def test_raises_key_error_if_amount_missing_when_not_invoice_bundle
199
- @params.delete(:amount)
200
- assert_raises(KeyError) { transaction = Sepa::Transaction.new(@params) }
201
- end
202
-
203
- def test_raises_key_error_if_currency_missing
204
- @params.delete(:currency)
205
- assert_raises(KeyError) { transaction = Sepa::Transaction.new(@params) }
206
- end
207
-
208
- def test_raises_key_error_if_bic_missing
209
- @params.delete(:bic)
210
- assert_raises(KeyError) { transaction = Sepa::Transaction.new(@params) }
211
- end
212
-
213
- def test_raises_key_error_if_name_missing
214
- @params.delete(:name)
215
- assert_raises(KeyError) { transaction = Sepa::Transaction.new(@params) }
216
- end
217
-
218
- def test_raises_key_error_if_address_missing
219
- @params.delete(:address)
220
- assert_raises(KeyError) { transaction = Sepa::Transaction.new(@params) }
221
- end
222
-
223
- def test_raises_key_error_if_country_missing
224
- @params.delete(:country)
225
- assert_raises(KeyError) { transaction = Sepa::Transaction.new(@params) }
226
- end
227
-
228
- def test_raises_key_error_if_postcode_missing
229
- @params.delete(:postcode)
230
- assert_raises(KeyError) { transaction = Sepa::Transaction.new(@params) }
231
- end
232
-
233
- def test_raises_key_error_if_town_missing
234
- @params.delete(:town)
235
- assert_raises(KeyError) { transaction = Sepa::Transaction.new(@params) }
236
- end
237
-
238
- def test_raises_key_error_if_iban_missing
239
- @params.delete(:iban)
240
- assert_raises(KeyError) { transaction = Sepa::Transaction.new(@params) }
241
- end
242
-
243
- def test_amount_is_set_correctly_when_invoice_bundle
244
- @params[:invoice_bundle] = @invoice_bundle
245
- transaction = Sepa::Transaction.new(@params)
246
- transaction_node = transaction.to_node
247
-
248
- amount = 0
249
- @invoice_bundle.each { |i| amount += i[:amount].to_f }
250
-
251
- assert_equal amount.to_s,
252
- transaction_node.at('/CdtTrfTxInf/Amt/InstdAmt').content
253
- end
254
-
255
- def test_invoice_type_is_set_correctly_when_invoice_bundle
256
- @params[:invoice_bundle] = @invoice_bundle
257
- transaction = Sepa::Transaction.new(@params)
258
- transaction_node = transaction.to_node
259
-
260
- type_nodes = transaction_node.xpath('//Strd/RfrdDocInf/RfrdDocTp/Cd')
261
-
262
- types_in_doc = []
263
-
264
- type_nodes.each { |t| types_in_doc.push(t.content) }
265
-
266
- types_in_params = []
267
-
268
- @invoice_bundle.each { |i| types_in_params.push(i[:type]) }
269
-
270
- type_hash = types_in_doc.zip(types_in_params)
271
-
272
- type_hash.each { |key, value| assert_equal key, value }
273
- end
274
-
275
- def test_invoice_number_is_set_correctly_when_invoice_bundle
276
- @params[:invoice_bundle] = @invoice_bundle
277
- transaction = Sepa::Transaction.new(@params)
278
- transaction_node = transaction.to_node
279
-
280
- number_nodes = transaction_node.xpath('//Strd/RfrdDocInf/RfrdDocNb')
281
-
282
- numbers_in_doc = []
283
-
284
- number_nodes.each { |t| numbers_in_doc.push(t.content) }
285
-
286
- numbers_in_params = []
287
-
288
- @invoice_bundle.each do |i|
289
- numbers_in_params.push(i[:invoice_number]) unless i[:invoice_number].nil?
290
- end
291
-
292
- number_hash = numbers_in_doc.zip(numbers_in_params)
293
-
294
- number_hash.each { |key, value| assert_equal key, value }
295
- end
296
-
297
- def test_invoice_reference_is_set_correctly_when_invoice_bundle
298
- @params[:invoice_bundle] = @invoice_bundle
299
- transaction = Sepa::Transaction.new(@params)
300
- transaction_node = transaction.to_node
301
-
302
- reference_nodes = transaction_node.xpath('//Strd/CdtrRefInf/CdtrRef')
303
-
304
- references_in_doc = []
305
-
306
- reference_nodes.each { |t| references_in_doc.push(t.content) }
307
-
308
- references_in_params = []
309
-
310
- @invoice_bundle.each do |i|
311
- references_in_params.push(i[:reference]) unless i[:reference].nil?
312
- end
313
-
314
- reference_hash = references_in_doc.zip(references_in_params)
315
-
316
- reference_hash.each { |key, value| assert_equal key, value }
317
- end
318
-
319
- def test_invoice_amount_is_set_correctly_when_invoice_bundle_and_not_credit
320
- @params[:invoice_bundle] = @invoice_bundle
321
- transaction = Sepa::Transaction.new(@params)
322
- transaction_node = transaction.to_node
323
-
324
- amount_nodes = transaction_node.xpath('//Strd/RfrdDocAmt/RmtdAmt')
325
-
326
- amounts_in_doc = []
327
-
328
- amount_nodes.each { |a| amounts_in_doc.push(a.content) }
329
-
330
- amounts_in_params = []
331
-
332
- @invoice_bundle.each do |i|
333
- amounts_in_params.push(i[:amount]) unless i[:amount].to_f < 0
334
- end
335
-
336
- amount_hash = amounts_in_doc.zip(amounts_in_params)
337
-
338
- amount_hash.each { |key, value| assert_equal key, value }
339
- end
340
-
341
- def test_invoice_amount_is_set_correctly_when_invoice_bundle_and_credit
342
- @params[:invoice_bundle] = @invoice_bundle
343
- transaction = Sepa::Transaction.new(@params)
344
- transaction_node = transaction.to_node
345
-
346
- amount_nodes = transaction_node.xpath('//Strd/RfrdDocAmt/CdtNoteAmt')
347
-
348
- amounts_in_doc = []
349
-
350
- amount_nodes.each { |a| amounts_in_doc.push(a.content) }
351
-
352
- amounts_in_params = []
353
-
354
- @invoice_bundle.each do |i|
355
- amounts_in_params.push(i[:amount].to_f.abs.to_s) unless i[:amount].to_f > 0
356
- end
357
-
358
- amount_hash = amounts_in_doc.zip(amounts_in_params)
359
-
360
- amount_hash.each { |key, value| assert_equal key, value }
361
- end
362
- end
@@ -1,21 +0,0 @@
1
- require File.expand_path('../../test_helper.rb', __FILE__)
2
-
3
- class UserFileTypeTest < MiniTest::Test
4
- def setup
5
- @single = Sepa::Filetypeservice.new
6
- @fts = []
7
- 10.times { @fts<<Sepa::Filetypeservice.new }
8
-
9
- @container = Sepa::Userfiletype.new
10
- @container.filetypeServices = []
11
- end
12
-
13
- def test_should_add_incoming_parameter_into_array
14
- assert @container.add_filetypeservice(@single)
15
- end
16
-
17
- def test_get_filetypeservices_should_return_array
18
- @container.filetypeServices = @fts
19
- assert @container.get_filetypeservices.kind_of?(Array), "Does not return an array"
20
- end
21
- end