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.
@@ -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
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/setup'
4
+ require 'brot'
5
+ require 'minitest/autorun'