This repository was archived by the owner on Feb 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathn26_spec.rb
More file actions
220 lines (173 loc) · 5.41 KB
/
Copy pathn26_spec.rb
File metadata and controls
220 lines (173 loc) · 5.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
vcr_options = { cassette_name: 'dumper/n26',
record: :none,
match_requests_on: %i[method host path] }
RSpec.describe Dumper::N26, vcr: vcr_options do
subject(:object) { Dumper::N26.new(params) }
let(:skip_pending_transactions) { false }
let(:params) do
{
'ynab_id' => '123466',
'username' => 'username',
'password' => 'password',
'iban' => 'DE89370400440532013000',
'skip_pending_transactions' => skip_pending_transactions
}
end
let(:transaction_pending) do
JSON.parse(File.read('spec/fixtures/dumper/n26/transaction_pending.json'))
end
let(:transaction_processed) do
JSON.parse(File.read('spec/fixtures/dumper/n26/transaction_processed.json'))
end
let(:transactions) do
client = TwentySix::Core.authenticate('username', 'password')
client.transactions
end
describe '#fetch_transactions' do
subject(:method) { object.fetch_transactions }
before do
allow(TransactionCreator).to(
receive(:find_payee_id_by_account_id)
.and_return('12345')
)
end
it 'sets the transactions' do
expect(method).to be_truthy
end
it 'has the correct transaction amount' do
expect(method.size).to eq(4)
end
end
# describe '#category_name' do
# let(:method) { object.send(:category_name, transactions[2]) }
# before do
# categories = ['micro-v2-food-groceries' => 'Food']
# allow(object).to receive(:@categories).and_return(categories)
# end
# context 'when set_category is set to true' do
# let(:params) do
# {
# 'ynab_id' => '123466',
# 'username' => 'username',
# 'password' => 'password',
# 'iban' => 'DE89370400440532013000',
# 'set_category' => true
# }
# end
# it 'returns the N26 category name' do
# expect(method).to eq('Food & Groceries')
# end
# end
# context 'when set_category is set to false' do
# it 'returns nil' do
# expect(method).to eq(nil)
# end
# end
# end
describe '#memo' do
let(:method) { object.send(:memo, transaction) }
context 'when reference text and city are present' do
let(:transaction) { transactions.last }
it 'merges reference text and city name' do
expect(method).to eq('Bargeldabhebung BARCELONA')
end
end
context 'when only city name is present' do
let(:transaction) { transactions[2] }
it 'returns the city name' do
expect(method).to eq('BARCELONA')
end
end
context 'when only reference text is present' do
let(:transaction) { transactions[1] }
it 'returns the reference text' do
expect(method).to eq('Test fuer eine Api')
end
end
end
describe '#amount' do
let(:method) { object.send(:amount, transaction) }
context 'when amount is below 1 euro' do
let(:transaction) { transactions.first }
it 'converts it correctly to an integer' do
expect(method).to eq(-10)
end
end
context 'when amount is below 10 euros' do
let(:transaction) { transactions[2] }
it 'converts it correctly to an integer' do
expect(method).to eq(5440)
end
end
context 'when amount is greater than 100 euros' do
let(:transaction) { transactions[3] }
it 'converts it correctly to an integer' do
expect(method).to eq(-500_000)
end
end
end
describe '#withdrawal?' do
let(:method) { object.send(:withdrawal?, transaction) }
context 'when transaction is withdrawal' do
let(:transaction) { transactions.last }
it 'returns true' do
expect(method).to be_truthy
end
end
context 'when transaction is not a withdrawal' do
let(:transaction) { transactions.first }
it 'returns true' do
expect(method).to be_falsy
end
end
end
describe '#import_id' do
let(:method) { object.send(:import_id, transactions.first) }
it 'sets it correctly' do
expect(method).to eq('46c9ccde424652bc013dca9b408dcdec')
end
end
describe '.accept?' do
subject(:accept?) { object.accept?(transaction) }
context 'when skip_pending_transactions feature is disabled' do
context 'when the transaction is pending' do
let(:transaction) { transaction_pending }
it 'returns true' do
expect(accept?).to be_truthy
end
end
context 'when the transaction is processed' do
let(:transaction) { transaction_processed }
it 'returns true' do
expect(accept?).to be_truthy
end
end
end
context 'when skip_pending_transactions feature is disabled' do
let(:skip_pending_transactions) { true }
context 'when the transaction is pending' do
let(:transaction) { transaction_pending }
it 'returns false' do
expect(accept?).to be_falsy
end
end
context 'when the transaction is processed' do
let(:transaction) { transaction_processed }
it 'returns true' do
expect(accept?).to be_truthy
end
end
context 'when the transaction is processed ' \
'but a returned authorization' do
let(:transaction) do
t = transaction_processed
t['type'] = 'AV'
t
end
it 'returns true' do
expect(accept?).to be_falsy
end
end
end
end
end