diff --git a/README.md b/README.md index 2405f10..a0854b0 100644 --- a/README.md +++ b/README.md @@ -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, diff --git a/lib/norma43/line_parsers/transaction.rb b/lib/norma43/line_parsers/transaction.rb index 1233433..5ceadb0 100644 --- a/lib/norma43/line_parsers/transaction.rb +++ b/lib/norma43/line_parsers/transaction.rb @@ -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 field :reference_2, 64..79 end end diff --git a/spec/example1_parse_spec.rb b/spec/example1_parse_spec.rb index b179b60..31760f5 100644 --- a/spec/example1_parse_spec.rb +++ b/spec/example1_parse_spec.rb @@ -58,7 +58,7 @@ "amount_code" => 2, "amount" => 1234, "document_number" => 0, - "reference_1" => 0, + "reference_1" => nil, "reference_2" => nil, ) end diff --git a/spec/example2_parse_spec.rb b/spec/example2_parse_spec.rb new file mode 100644 index 0000000..fa92b8f --- /dev/null +++ b/spec/example2_parse_spec.rb @@ -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 diff --git a/spec/fixtures/example2.n43 b/spec/fixtures/example2.n43 new file mode 100644 index 0000000..2d865f7 --- /dev/null +++ b/spec/fixtures/example2.n43 @@ -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 \ No newline at end of file diff --git a/spec/norma43/line_parsers/transaction_spec.rb b/spec/norma43/line_parsers/transaction_spec.rb index 7cb8859..ed02af3 100644 --- a/spec/norma43/line_parsers/transaction_spec.rb +++ b/spec/norma43/line_parsers/transaction_spec.rb @@ -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