brot 0.1.1
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 +7 -0
- data/.github/workflows/ci.yml +25 -0
- data/.github/workflows/release.yml +43 -0
- data/.rubocop.yml +9 -0
- data/Gemfile +13 -0
- data/LICENSE.txt +22 -0
- data/README.md +424 -0
- data/Rakefile +10 -0
- data/brot.gemspec +44 -0
- data/lib/brot/pain00100112/account.rb +48 -0
- data/lib/brot/pain00100112/document.rb +162 -0
- data/lib/brot/pain00100112/schema.rb +58 -0
- data/lib/brot/pain00100112/serializer.rb +25 -0
- data/lib/brot/pain00100112/serializer_base.rb +174 -0
- data/lib/brot/pain00100112/transfer.rb +96 -0
- data/lib/brot/pain00100112/utils.rb +92 -0
- data/lib/brot/pain00100112.rb +25 -0
- data/lib/brot/version.rb +5 -0
- data/lib/brot.rb +13 -0
- data/test/brot_test.rb +9 -0
- data/test/pain00100112_document_test.rb +87 -0
- data/test/test_helper.rb +5 -0
- data/xsd/pain.001.001.12.xsd +1208 -0
- metadata +82 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'test_helper'
|
|
4
|
+
|
|
5
|
+
class Pain00100112DocumentTest < Minitest::Test
|
|
6
|
+
NS = { 'ns' => Brot::Pain00100112::NAMESPACE }.freeze
|
|
7
|
+
DOCUMENT_ATTRIBUTES = {
|
|
8
|
+
message_id: 'MSG-20260313-01',
|
|
9
|
+
payment_information_id: 'PMT-20260313-01',
|
|
10
|
+
initiating_party_name: 'Example Debtor GmbH',
|
|
11
|
+
debtor_name: 'Example Debtor GmbH',
|
|
12
|
+
debtor_iban: 'DE12500105170648489890',
|
|
13
|
+
debtor_bic: 'INGDDEFFXXX',
|
|
14
|
+
requested_execution_date: Date.new(2026, 3, 13),
|
|
15
|
+
created_at: Time.utc(2026, 3, 13, 12, 0, 0)
|
|
16
|
+
}.freeze
|
|
17
|
+
TRANSFER_ATTRIBUTES = {
|
|
18
|
+
amount: '1250.50',
|
|
19
|
+
creditor_name: 'Example Supplier GmbH',
|
|
20
|
+
creditor_iban: 'DE89370400440532013000',
|
|
21
|
+
creditor_bic: 'COBADEFFXXX',
|
|
22
|
+
end_to_end_id: 'INV-2026-0001',
|
|
23
|
+
remittance_information: 'Invoice 2026-0001',
|
|
24
|
+
instruction_id: 'INSTR-2026-0001'
|
|
25
|
+
}.freeze
|
|
26
|
+
|
|
27
|
+
def test_uses_the_pain_001_001_12_namespace
|
|
28
|
+
assert_equal Brot::Pain00100112::NAMESPACE, parsed_document.root.namespace.href
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def test_serializes_the_group_header
|
|
32
|
+
assert_xpath('//ns:GrpHdr/ns:MsgId', 'MSG-20260313-01')
|
|
33
|
+
assert_xpath('//ns:GrpHdr/ns:NbOfTxs', '1')
|
|
34
|
+
assert_xpath('//ns:GrpHdr/ns:CtrlSum', '1250.50')
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def test_serializes_payment_metadata
|
|
38
|
+
assert_xpath('//ns:PmtTpInf/ns:SvcLvl/ns:Cd', 'SEPA')
|
|
39
|
+
assert_xpath('//ns:ReqdExctnDt/ns:Dt', '2026-03-13')
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def test_serializes_creditor_transfer_details
|
|
43
|
+
assert_xpath('//ns:Amt/ns:InstdAmt', '1250.50')
|
|
44
|
+
assert_equal 'EUR', parsed_document.at_xpath('//ns:Amt/ns:InstdAmt', NS).attribute('Ccy').value
|
|
45
|
+
assert_xpath('//ns:RmtInf/ns:Ustrd', 'Invoice 2026-0001')
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def test_validates_generated_xml_against_the_bundled_xsd
|
|
49
|
+
assert_path_exists Brot::Pain00100112::Schema.bundled_xsd_path
|
|
50
|
+
|
|
51
|
+
result = document.validate
|
|
52
|
+
|
|
53
|
+
assert_predicate result, :valid?, result.errors.join("\n")
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def test_rejects_an_invalid_iban
|
|
57
|
+
error = assert_raises(Brot::Pain00100112::ValidationError) { invalid_document }
|
|
58
|
+
|
|
59
|
+
assert_equal 'iban is invalid', error.message
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
private
|
|
63
|
+
|
|
64
|
+
def assert_xpath(xpath, expected)
|
|
65
|
+
assert_equal expected, parsed_document.at_xpath(xpath, NS).content
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def document
|
|
69
|
+
Brot::Pain00100112::Document.new(**document_attributes)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def document_attributes(**overrides)
|
|
73
|
+
DOCUMENT_ATTRIBUTES.merge(transfers: [transfer], **overrides)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def invalid_document
|
|
77
|
+
Brot::Pain00100112::Document.new(**document_attributes(debtor_iban: 'INVALID'))
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def parsed_document
|
|
81
|
+
@parsed_document ||= Nokogiri::XML(document.to_xml)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def transfer
|
|
85
|
+
Brot::Pain00100112::Transfer.new(**TRANSFER_ATTRIBUTES)
|
|
86
|
+
end
|
|
87
|
+
end
|