diff --git a/JustAnotherExpenseManager/routes/transactions.py b/JustAnotherExpenseManager/routes/transactions.py index 27ef677..42fd352 100644 --- a/JustAnotherExpenseManager/routes/transactions.py +++ b/JustAnotherExpenseManager/routes/transactions.py @@ -276,7 +276,7 @@ def export_transactions() -> Response: for trans in all_transactions: writer.writerow([ trans.description, - f'{trans.amount_dollars:.2f}', + f'{(trans.amount_cents / 100):.2f}', trans.type.value, trans.category or '', trans.date, diff --git a/tests/test_routes.py b/tests/test_routes.py index e723980..f35b314 100644 --- a/tests/test_routes.py +++ b/tests/test_routes.py @@ -120,6 +120,13 @@ def test_update_transaction_invalid_type_returns_400(self, client, db): }) assert response.status_code == 400 + def test_export_transactions_csv(self, client, sample_transactions): + response = client.get('/api/transactions/export') + assert response.status_code == 200 + assert response.headers['Content-Disposition'].startswith('attachment; filename=') + assert b'description,amount,type,category,date,tags' in response.data + assert b'Restaurant' in response.data + # --------------------------------------------------------------------------- # Transaction filtering and pagination