From 941ccb2cb34944e1321b3dc23731bfa93018d74f Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Wed, 1 Jul 2026 12:13:42 +0200 Subject: feat: tx list --flat, account create --if-not-exists, --since/--until doc (v0.3.6) Three smaller ISSUES.md items, one PATCH (two optional flags + a doc fix; no existing caller or JSON shape changes). - tx list --flat: emit one top-level object per split (journal id repeated), dropping the transactions[] nesting so single-split journals script cleanly. JSON-only; --human already explodes splits into a table. - account create --if-not-exists: resolve the name first; on a clash return the existing account with "existed": true (exit 0) instead of surfacing Firefly's 422, so import scripts are idempotent. Detects via resolver, not by parsing the error string. - SKILL.md documents that --since/--until filter on the transaction date (the value date); Firefly journals have a single date field, no separate book date (verified against firefly-iii TimeCollection setRange). Co-Authored-By: Claude Opus 4.8 --- tests/unit/test_output.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'tests/unit/test_output.py') diff --git a/tests/unit/test_output.py b/tests/unit/test_output.py index 2e3e5ea..069a21d 100644 --- a/tests/unit/test_output.py +++ b/tests/unit/test_output.py @@ -1,6 +1,6 @@ import io, json, unittest from contextlib import redirect_stdout -from firefly_cli.output import unwrap, emit +from firefly_cli.output import unwrap, emit, flatten_tx class TestOutput(unittest.TestCase): def test_unwrap_list_returns_clean_objects(self): @@ -22,6 +22,29 @@ class TestOutput(unittest.TestCase): emit([{"id": "1", "name": "x"}], human=False) self.assertEqual(json.loads(buf.getvalue()), [{"id": "1", "name": "x"}]) + def test_flatten_single_split(self): + rows = [{"id": "10", "group_title": None, "transactions": [ + {"amount": "5.00", "source_name": "A", "destination_name": "B", + "type": "withdrawal"}]}] + flat = flatten_tx(rows) + self.assertEqual(len(flat), 1) + self.assertNotIn("transactions", flat[0]) + self.assertEqual(flat[0]["id"], "10") + self.assertEqual(flat[0]["amount"], "5.00") + self.assertEqual(flat[0]["source_name"], "A") + + def test_flatten_multi_split_repeats_id(self): + rows = [{"id": "20", "transactions": [ + {"amount": "1", "type": "withdrawal"}, + {"amount": "2", "type": "withdrawal"}]}] + flat = flatten_tx(rows) + self.assertEqual([f["id"] for f in flat], ["20", "20"]) + self.assertEqual([f["amount"] for f in flat], ["1", "2"]) + + def test_flatten_passes_through_non_tx_rows(self): + rows = [{"id": "1", "name": "Checking"}] + self.assertEqual(flatten_tx(rows), rows) + def test_emit_human_table_contains_values(self): buf = io.StringIO() with redirect_stdout(buf): -- cgit v1.2.3