Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ amount_code=2,
document_number=0,
origin_branch_code=123,
own_item=16,
reference_1=0,
reference_1=nil,
reference_2=nil,
shared_item=4,
transaction_date=Tue, 04 Feb 2016,
Expand Down
2 changes: 1 addition & 1 deletion lib/norma43/line_parsers/transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Transaction < LineParser
field :amount_code, 27, :integer
field :amount, 28..41, :integer
field :document_number, 42..51, :integer
field :reference_1, 52..63, :integer
field :reference_1, 52..63
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick (non-blocking): I suggest better being explicit and put :string in both references

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just copied the style of other places, there are more references that will need to change in other files, so I won't change them for now

field :reference_2, 64..79
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/example1_parse_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"amount_code" => 2,
"amount" => 1234,
"document_number" => 0,
"reference_1" => 0,
"reference_1" => nil,
"reference_2" => nil,
)
end
Expand Down
86 changes: 86 additions & 0 deletions spec/example2_parse_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# frozen_string_literal: true

require "norma43"

RSpec.describe Norma43 do
describe "parse" do
let(:document) do
file = File.open(File.join(__dir__, "fixtures/example2.n43"),
encoding: "iso-8859-1")
Norma43.parse file
end

it "finds one account" do
expect(document.accounts.size).to eq 1
end

describe "first account" do
let(:account) { document.accounts.first }

it "stores expected attributes from AccountStart parser" do
expect(account).to have_attributes(
"bank_code" => 81,
"branch_code" => 4797,
"account_number" => 6995216857,
"start_date" => Date.parse("2025-03-17"),
"end_date" => Date.parse("2025-03-17"),
"currency_code" => 978,
"information_mode_code" => 3,
"abbreviated_name" => "SEQURA WORLDWIDE S.A.",
)
end

it "stores expected attributes from AccountEnd parser" do
expect(account).to have_attributes(
"balance_code" => 2,
"balance_amount" => 8614571,
"debit_entries" => nil,
"debit_amount" => nil,
"credit_entries" => nil,
"credit_amount" => nil,
)
end

describe "transactions" do
it "finds all transactions" do
expect(account.transactions.size).to eq 4
end

describe "first transaction" do
let(:transaction) { account.transactions[0] }
it "stores expected attributes" do
expect(transaction).to have_attributes(
"origin_branch_code" => 7013,
"transaction_date" => Date.parse("2025-03-17"),
"value_date" => Date.parse("2025-03-14"),
"shared_item" => 4,
"own_item" => 7,
"amount_code" => 2,
"amount" => 9726,
"document_number" => 6871166755,
"reference_1" => "TRANSFERENCI",
"reference_2" => "A48555633617",
)
end
end

it "each transaction has 5 additional_items as a maximum" do
account.transactions.each do |transaction|
expect(transaction.additional_items.size).to be <= 5
end
end

describe "first additional item" do
let(:additional_item) { account.transactions[0].additional_items[0] }
it "stores expected attributes" do
expect(additional_item).to have_attributes(
"data_code" => 1,
"item_1" => "MARIA NARANJO ENFLOR",
"item_2" => "A48555633617"
)
end
end
end
end
end
end
13 changes: 13 additions & 0 deletions spec/fixtures/example2.n43
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
110081479769952168572503172503172000000086145719783SEQURA WORLDWIDE S.A.
2201827013250317250314040072000000000097266871166755TRANSFERENCIA48555633617
2301MARIA NARANJO ENFLOR A48555633617
2302 01826874
2201827013250317250317040072000000000074332011157110TRANSFERENCISEQURA
2301LAURA MARTINEZ PEREZ
2302 01822011
2201828510250317250317990512000000000082250000000000BIZUM
2301NAYARA;MARTINEZ RODRIGUEZ PEDIDO 322200000000
2302 15830001
2201828510250317250317990512000000000088940000000000BIZUM
2301DANIEL GARCIA GARCIA PEDIDO 322254909000
2302 21000900
2 changes: 1 addition & 1 deletion spec/norma43/line_parsers/transaction_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module LineParsers
end

it "parses the reference 1" do
expect(transaction.reference_1).to eq 0
expect(transaction.reference_1).to be_nil
end

it "parses the reference 2" do
Expand Down