cfonb 0.0.0 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cfonb'
4
+
5
+ describe CFONB::LineParser::NewBalance do
6
+ describe '.initialize' do
7
+ subject(:line) { described_class.new(input) }
8
+
9
+ let(:input) do
10
+ '0115589 01020EUR2 98765432100 150519 0000000001904L150519160519 '
11
+ end
12
+
13
+ it 'correctly parses a line' do
14
+ expect(line).to have_attributes(
15
+ 'code' => '01',
16
+ 'bank' => '15589',
17
+ 'branch' => '01020',
18
+ 'currency' => 'EUR',
19
+ 'scale' => 2,
20
+ 'account' => '98765432100',
21
+ 'date' => Date.new(2019, 5, 15),
22
+ 'amount' => -190.43
23
+ )
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cfonb'
4
+
5
+ describe CFONB::LineParser::OperationDetail do
6
+ describe '.initialize' do
7
+ subject(:line) { described_class.new(input) }
8
+
9
+ let(:input) do
10
+ '0515589916201020EUR2 98765432100B1150519 LIBMENSUEAUHTR13133 '
11
+ end
12
+
13
+ it 'correctly parses a line' do
14
+ expect(line).to have_attributes(
15
+ 'code' => '05',
16
+ 'bank' => '15589',
17
+ 'branch' => '01020',
18
+ 'currency' => 'EUR',
19
+ 'scale' => 2,
20
+ 'account' => '98765432100',
21
+ 'date' => Date.new(2019, 5, 15),
22
+ 'internal_operation_code' => '9162',
23
+ 'interbank_operation_code' => 'B1',
24
+ 'detail_code' => 'LIB',
25
+ 'detail' => 'MENSUEAUHTR13133'
26
+ )
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cfonb'
4
+
5
+ describe CFONB::LineParser::Operation do
6
+ describe '.initialize' do
7
+ subject(:line) { described_class.new(input) }
8
+
9
+ let(:input) do
10
+ '0415589916201020EUR2 98765432100B115051964160519PRLV SEPA TEST CABINET 7654321UP0000000000322JXYZ123 '
11
+ end
12
+
13
+ it 'correctly parses a line' do
14
+ expect(line).to have_attributes(
15
+ 'code' => '04',
16
+ 'bank' => '15589',
17
+ 'branch' => '01020',
18
+ 'currency' => 'EUR',
19
+ 'scale' => 2,
20
+ 'account' => '98765432100',
21
+ 'date' => Date.new(2019, 5, 15),
22
+ 'amount' => -32.21,
23
+ 'internal_operation_code' => '9162',
24
+ 'interbank_operation_code' => 'B1',
25
+ 'rejection_code' => '64',
26
+ 'value_date' => Date.new(2019, 5, 16),
27
+ 'label' => 'PRLV SEPA TEST CABINET',
28
+ 'number' => 7_654_321,
29
+ 'exoneration_code' => 'U',
30
+ 'unavailability_code' => 'P',
31
+ 'reference' => 'XYZ123'
32
+ )
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cfonb'
4
+
5
+ describe CFONB::LineParser::PreviousBalance do
6
+ describe '.initialize' do
7
+ subject(:line) { described_class.new(input) }
8
+
9
+ let(:input) do
10
+ '0115589 01020EUR2 98765432100 150519 0000000001904L150519160519 '
11
+ end
12
+
13
+ it 'correctly parses a line' do
14
+ expect(line).to have_attributes(
15
+ 'code' => '01',
16
+ 'bank' => '15589',
17
+ 'branch' => '01020',
18
+ 'currency' => 'EUR',
19
+ 'scale' => 2,
20
+ 'account' => '98765432100',
21
+ 'date' => Date.new(2019, 5, 15),
22
+ 'amount' => -190.43
23
+ )
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,184 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cfonb'
4
+ require 'ostruct'
5
+
6
+ describe CFONB::Operation do
7
+ subject(:operation) { described_class.new(line) }
8
+
9
+ let(:line) do
10
+ OpenStruct.new(
11
+ body: 'xxxxxxxxxxxxxx',
12
+ label: 'A random operation label',
13
+ date: Date.new(2021, 3, 5),
14
+ currency: 'EUR',
15
+ amount: -15,
16
+ reference: '42'
17
+ )
18
+ end
19
+
20
+ describe '#merge_detail' do
21
+ it 'merges the lines body' do
22
+ detail = OpenStruct.new(body: 'yyyyyyyyyyyyyy')
23
+ operation.merge_detail(detail)
24
+
25
+ expect(operation.raw).to eq(<<~TXT.strip)
26
+ xxxxxxxxxxxxxx
27
+ yyyyyyyyyyyyyy
28
+ TXT
29
+ end
30
+
31
+ context 'with a LIB detail' do
32
+ let(:detail) { OpenStruct.new(body: '', detail_code: 'LIB', detail: ' Extra label ') }
33
+
34
+ it 'Adds the new label line' do
35
+ operation.merge_detail(detail)
36
+
37
+ expect(operation.label).to eq(<<~TXT.strip)
38
+ A random operation label
39
+ Extra label
40
+ TXT
41
+ end
42
+ end
43
+
44
+ context 'with a LCC detail' do
45
+ let(:detail) { OpenStruct.new(body: '', detail_code: 'LCC', detail: ' Extra label ') }
46
+
47
+ it 'Adds the new label line' do
48
+ operation.merge_detail(detail)
49
+
50
+ expect(operation.label).to eq(<<~TXT.strip)
51
+ A random operation label
52
+ Extra label
53
+ TXT
54
+ end
55
+ end
56
+
57
+ context 'with a LC2 detail' do
58
+ let(:detail) { OpenStruct.new(body: '', detail_code: 'LC2', detail: ' Extra label ') }
59
+
60
+ it 'Adds the new label line' do
61
+ operation.merge_detail(detail)
62
+
63
+ expect(operation.label).to eq(<<~TXT.strip)
64
+ A random operation label
65
+ Extra label
66
+ TXT
67
+ end
68
+ end
69
+
70
+ context 'with a LCS detail' do
71
+ let(:detail) { OpenStruct.new(body: '', detail_code: 'LCS', detail: ' Extra label ') }
72
+
73
+ it 'Adds the new label line' do
74
+ operation.merge_detail(detail)
75
+
76
+ expect(operation.label).to eq(<<~TXT.strip)
77
+ A random operation label
78
+ Extra label
79
+ TXT
80
+ end
81
+ end
82
+
83
+ context 'with a MMO detail' do
84
+ let(:detail) { OpenStruct.new(body: '', detail_code: 'MMO', detail: 'USD200000000001234') }
85
+
86
+ it 'Adds the original currency information' do
87
+ operation.merge_detail(detail)
88
+
89
+ expect(operation).to have_attributes(
90
+ original_currency: 'USD',
91
+ original_amount: -12.34
92
+ )
93
+ end
94
+ end
95
+
96
+ context 'with a NPY detail' do
97
+ let(:detail) { OpenStruct.new(body: '', detail_code: 'NPY', detail: 'Patrick') }
98
+
99
+ it 'Adds the debtor information' do
100
+ operation.merge_detail(detail)
101
+
102
+ expect(operation).to have_attributes(debtor: 'Patrick')
103
+ end
104
+ end
105
+
106
+ context 'with a NBE detail' do
107
+ let(:detail) { OpenStruct.new(body: '', detail_code: 'NBE', detail: 'Jean-Pierre') }
108
+
109
+ it 'Adds the creditor information' do
110
+ operation.merge_detail(detail)
111
+
112
+ expect(operation).to have_attributes(creditor: 'Jean-Pierre')
113
+ end
114
+ end
115
+
116
+ context 'with a RCN detail' do
117
+ let(:detail) do
118
+ OpenStruct.new(
119
+ body: '',
120
+ detail_code: 'RCN',
121
+ detail: 'SWILE-CMD-TR-YPDHMA TICKET RESTO '
122
+ )
123
+ end
124
+
125
+ it 'adds the reference information' do
126
+ operation.merge_detail(detail)
127
+
128
+ expect(operation.reference).to eq('42 - SWILE-CMD-TR-YPDHMA')
129
+ expect(operation.purpose).to eq('TICKET RESTO')
130
+ end
131
+ end
132
+
133
+ context 'with a REF detail' do
134
+ let(:detail) do
135
+ OpenStruct.new(
136
+ body: '0530002112701731EUR2E0000073337DA129082300 REFPENNYLANE B13A93908C36C82DF5C319/1 ',
137
+ detail_code: 'REF',
138
+ detail: 'PENNYLANE B13A93908C36C82DF5C319/1 '
139
+ )
140
+ end
141
+
142
+ it 'adds the reference information' do
143
+ operation.merge_detail(detail)
144
+
145
+ expect(operation.reference).to eq('42 - PENNYLANE B13A93908C36C82DF5C319/1')
146
+ end
147
+ end
148
+
149
+ context 'with a FEE detail' do
150
+ let(:detail) do
151
+ OpenStruct.new(
152
+ body: '0530004411001871EUR2 0001016255614090823 FEEEUR200000000000740',
153
+ detail_code: 'FEE',
154
+ detail: 'EUR200000000000740'
155
+ )
156
+ end
157
+
158
+ it 'adds the fee information' do
159
+ operation.merge_detail(detail)
160
+
161
+ expect(operation.fee_currency).to eq('EUR')
162
+ expect(operation.fee).to eq(-7.4)
163
+ end
164
+ end
165
+ end
166
+
167
+ describe '#type_code' do
168
+ context 'with positive amount' do
169
+ let(:line) { OpenStruct.new(amount: -15, interbank_operation_code: '15', label: 'a label') }
170
+
171
+ it 'returns a debit transaction type code' do
172
+ expect(operation.type_code).to eq('15D')
173
+ end
174
+ end
175
+
176
+ context 'with negative amount' do
177
+ let(:line) { OpenStruct.new(amount: 15, interbank_operation_code: '2B', label: 'a label') }
178
+
179
+ it 'returns a credit transaction type code' do
180
+ expect(operation.type_code).to eq('2BC')
181
+ end
182
+ end
183
+ end
184
+ end