Skip to content
This repository was archived by the owner on Feb 25, 2022. It is now read-only.
Draft
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
7 changes: 6 additions & 1 deletion lib/dumper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def to_ynab_transaction(transaction)
memo: memo(transaction),
amount: amount(transaction),
is_withdrawal: withdrawal?(transaction),
import_id: import_id(transaction)
import_id: import_id(transaction),
is_cleared: cleared?(transaction)
)
end
# rubocop:enable Metrics/MethodLength
Expand All @@ -43,4 +44,8 @@ def category_id(_transaction)
def normalize_iban(iban)
iban.delete(' ')
end

def cleared?(transaction)
date(transaction) < Time.now
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Maybe here we could use Date.current because the date method will return a date object (limitation of some dumpers, most banks don't return a timestamp..) and I think it reads a bit better to see a date comparing with a date. WDYT?

end
end
4 changes: 4 additions & 0 deletions lib/dumper/n26.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ def withdrawal?(transaction)
WITHDRAWAL_CATEGORIES.include?(transaction['category'])
end

def cleared?(transaction)
already_processed?(transaction)
end

def import_id(transaction)
data = [transaction['visibleTS'],
transaction['transactionNature'],
Expand Down
8 changes: 6 additions & 2 deletions lib/transaction_creator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
class TransactionCreator
attr_accessor :account_id, :date, :amount, :payee_name, :payee_id,
:category_name, :category_id, :memo,
:import_id, :is_withdrawal
:import_id, :is_withdrawal, :is_cleared

class <<self
require 'ynab/models/save_transaction'
Expand All @@ -22,7 +22,7 @@ def call(options = {})
memo: memo(options),
import_id: options.fetch(:import_id),
flag_color: flag_color(options),
cleared: 'cleared' # TODO: shouldn't be cleared if date is in the future
cleared: cleared(options)
)
end
# rubocop:enable Metrics/MethodLength
Expand Down Expand Up @@ -76,6 +76,10 @@ def withdrawal?(options)
options.fetch(:is_withdrawal, nil)
end

def cleared(options)
options.fetch(:is_cleared, true) ? 'cleared' : 'uncleared'
end

def account_payee_id(options)
result = Settings.all['accounts'].find do |account|
payee_iban = payee_iban(options)
Expand Down
19 changes: 18 additions & 1 deletion spec/dumper/n26_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@

describe '.accept?' do
subject(:accept?) { object.accept?(transaction) }
subject(:cleared?) { object.send(:cleared?, transaction) }

context 'when skip_pending_transactions feature is disabled' do
context 'when the transaction is pending' do
Expand All @@ -173,6 +174,10 @@
it 'returns true' do
expect(accept?).to be_truthy
end

it 'the transaction is not cleared' do
expect(cleared?).to be_falsy
end
end

context 'when the transaction is processed' do
Expand All @@ -181,10 +186,14 @@
it 'returns true' do
expect(accept?).to be_truthy
end

it 'the transaction is cleared' do
expect(cleared?).to be_truthy
end
end
end

context 'when skip_pending_transactions feature is disabled' do
context 'when skip_pending_transactions feature is enabled' do
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Good catch! Thank you

let(:skip_pending_transactions) { true }

context 'when the transaction is pending' do
Expand All @@ -193,6 +202,10 @@
it 'returns false' do
expect(accept?).to be_falsy
end

it 'the transaction is not cleared' do
expect(cleared?).to be_falsy
end
end

context 'when the transaction is processed' do
Expand All @@ -201,6 +214,10 @@
it 'returns true' do
expect(accept?).to be_truthy
end

it 'the transaction is cleared' do
expect(cleared?).to be_truthy
end
end
end
end
Expand Down