@@ -60,9 +60,9 @@ def test_should_only_import_settled_transactions(setup_nubank, monkeypatch):
6060def test_should_expand_installment_transactions (setup_nubank , monkeypatch ):
6161 nu = setup_nubank
6262 installment_transaction = build_card_transaction ({
63+ 'amount' : 3000 ,
6364 'details' : {
6465 'status' : 'settled' ,
65- 'amount' : 3000 ,
6666 'charges' : {
6767 'count' : 3 ,
6868 'amount' : 1000
@@ -83,11 +83,68 @@ def test_should_expand_installment_transactions(setup_nubank, monkeypatch):
8383
8484 assert len (imported_transactions ) == 4
8585 assert imported_transactions [0 ]['amount' ] == - 30000
86+ assert imported_transactions [1 ]['memo' ] == 'Parcela 1 de 3. Valor total: R$ 30,00'
87+ assert imported_transactions [1 ]['flag' ] == 'red'
8688 assert imported_transactions [1 ]['amount' ] == - 10000
89+ assert imported_transactions [2 ]['memo' ] == 'Parcela 2 de 3. Valor total: R$ 30,00'
90+ assert imported_transactions [2 ]['flag' ] == 'red'
8791 assert imported_transactions [2 ]['amount' ] == - 10000
92+ assert imported_transactions [3 ]['memo' ] == 'Parcela 3 de 3. Valor total: R$ 30,00'
93+ assert imported_transactions [3 ]['flag' ] == 'red'
8894 assert imported_transactions [3 ]['amount' ] == - 10000
8995 # All ids should be unique
9096 assert len (ids ) == len (set (ids ))
91- # Installments should have the memo and flag set
92- assert imported_transactions [1 ]['memo' ] == 'Parcela 1 de 3. Valor total R$ 30,00'
93- assert imported_transactions [1 ]['flag' ] == 'Red'
97+
98+
99+
100+ def test_should_not_expand_transactions_with_one_installment (setup_nubank , monkeypatch ):
101+ nu = setup_nubank
102+ installment_transaction = build_card_transaction ({
103+ 'amount' : 3000 ,
104+ 'details' : {
105+ 'status' : 'settled' ,
106+ 'charges' : {
107+ 'count' : 1 ,
108+ 'amount' : 3000
109+ }
110+ }
111+ })
112+ transactions = [
113+ installment_transaction
114+ ]
115+ monkeypatch .setattr (nu , 'get_card_statements' , lambda : transactions )
116+
117+ importer = NubankCreditCardData (nu , 'some-id' )
118+ imported_transactions = list (importer .get_data ())
119+
120+ assert len (imported_transactions ) == 1
121+ assert imported_transactions [0 ]['amount' ] == - 30000
122+ assert imported_transactions [0 ]['memo' ] == ''
123+ assert imported_transactions [0 ]['flag' ] is None
124+
125+
126+ def test_should_set_the_day_to_first_for_following_installments (setup_nubank , monkeypatch ):
127+ nu = setup_nubank
128+ installment_transaction = build_card_transaction ({
129+ 'amount' : 3000 ,
130+ 'time' : '2021-01-15' ,
131+ 'details' : {
132+ 'status' : 'settled' ,
133+ 'charges' : {
134+ 'count' : 3 ,
135+ 'amount' : 1000
136+ }
137+ }
138+ })
139+ transactions = [
140+ installment_transaction
141+ ]
142+ monkeypatch .setattr (nu , 'get_card_statements' , lambda : transactions )
143+
144+ importer = NubankCreditCardData (nu , 'some-id' )
145+ imported_transactions = list (importer .get_data ())
146+
147+ assert len (imported_transactions ) == 3
148+ assert imported_transactions [0 ]['date' ] == '2021-01-15'
149+ assert imported_transactions [1 ]['date' ] == '2021-02-01'
150+ assert imported_transactions [2 ]['date' ] == '2021-03-01'
0 commit comments