Skip to content

Commit 1d46052

Browse files
committed
add tests with a new faked file
1 parent 2e715e4 commit 1d46052

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed

spec/example2_parse_spec.rb

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# frozen_string_literal: true
2+
3+
require "norma43"
4+
5+
RSpec.describe Norma43 do
6+
describe "parse" do
7+
let(:document) do
8+
file = File.open(File.join(__dir__, "fixtures/example2.n43"),
9+
encoding: "iso-8859-1")
10+
Norma43.parse file
11+
end
12+
13+
it "finds one account" do
14+
expect(document.accounts.size).to eq 1
15+
end
16+
17+
describe "first account" do
18+
let(:account) { document.accounts.first }
19+
20+
it "stores expected attributes from AccountStart parser" do
21+
expect(account).to have_attributes(
22+
"bank_code" => 81,
23+
"branch_code" => 4797,
24+
"account_number" => 6995216857,
25+
"start_date" => Date.parse("2025-03-17"),
26+
"end_date" => Date.parse("2025-03-17"),
27+
"currency_code" => 978,
28+
"information_mode_code" => 3,
29+
"abbreviated_name" => "SEQURA WORLDWIDE S.A.",
30+
)
31+
end
32+
33+
it "stores expected attributes from AccountEnd parser" do
34+
expect(account).to have_attributes(
35+
"balance_code" => 2,
36+
"balance_amount" => 8614571,
37+
"debit_entries" => nil,
38+
"debit_amount" => nil,
39+
"credit_entries" => nil,
40+
"credit_amount" => nil,
41+
)
42+
end
43+
44+
describe "transactions" do
45+
it "finds all transactions" do
46+
expect(account.transactions.size).to eq 4
47+
end
48+
49+
describe "first transaction" do
50+
let(:transaction) { account.transactions[0] }
51+
it "stores expected attributes" do
52+
expect(transaction).to have_attributes(
53+
"origin_branch_code" => 7013,
54+
"transaction_date" => Date.parse("2025-03-17"),
55+
"value_date" => Date.parse("2025-03-14"),
56+
"shared_item" => 4,
57+
"own_item" => 7,
58+
"amount_code" => 2,
59+
"amount" => 9726,
60+
"document_number" => 6871166755,
61+
"reference_1" => "TRANSFERENCI",
62+
"reference_2" => "A48555633617",
63+
)
64+
end
65+
end
66+
67+
it "each transaction has 5 additional_items as a maximum" do
68+
account.transactions.each do |transaction|
69+
expect(transaction.additional_items.size).to be <= 5
70+
end
71+
end
72+
73+
describe "first additional item" do
74+
let(:additional_item) { account.transactions[0].additional_items[0] }
75+
it "stores expected attributes" do
76+
expect(additional_item).to have_attributes(
77+
"data_code" => 1,
78+
"item_1" => "MARIA NARANJO ENFLOR",
79+
"item_2" => "A48555633617"
80+
)
81+
end
82+
end
83+
end
84+
end
85+
end
86+
end

spec/fixtures/example2.n43

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
110081479769952168572503172503172000000086145719783SEQURA WORLDWIDE S.A.
2+
2201827013250317250314040072000000000097266871166755TRANSFERENCIA48555633617
3+
2301MARIA NARANJO ENFLOR A48555633617
4+
2302 01826874
5+
2201827013250317250317040072000000000074332011157110TRANSFERENCISEQURA
6+
2301LAURA MARTINEZ PEREZ
7+
2302 01822011
8+
2201828510250317250317990512000000000082250000000000BIZUM
9+
2301NAYARA;MARTINEZ RODRIGUEZ PEDIDO 322200000000
10+
2302 15830001
11+
2201828510250317250317990512000000000088940000000000BIZUM
12+
2301DANIEL GARCIA GARCIA PEDIDO 322254909000
13+
2302 21000900

0 commit comments

Comments
 (0)