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_commands_account.py | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'tests/unit/test_commands_account.py') diff --git a/tests/unit/test_commands_account.py b/tests/unit/test_commands_account.py index 4a01292..c328890 100644 --- a/tests/unit/test_commands_account.py +++ b/tests/unit/test_commands_account.py @@ -43,7 +43,8 @@ class TestAccountCmd(unittest.TestCase): class TestAccountCreate(unittest.TestCase): def _args(self, **kw): - base = dict(name=None, type=None, opening_balance=None, currency=None) + base = dict(name=None, type=None, opening_balance=None, currency=None, + if_not_exists=False) base.update(kw) m = MagicMock() m.configure_mock(**base) # 'name' is reserved in MagicMock ctor, not configure_mock @@ -89,3 +90,36 @@ class TestAccountCreate(unittest.TestCase): with self.assertRaises(FireflyError): acct.cmd_create(self._args(name="X", type="bogus"), ctx) client.request.assert_not_called() + + def test_if_not_exists_returns_existing_no_post(self): + ctx, client, resolver = make_ctx() + resolver.account.return_value = {"id": "5", "name": "Savings", + "type": "asset"} + rc = acct.cmd_create( + self._args(name="Savings", type="asset", if_not_exists=True), ctx) + self.assertEqual(rc, 0) + resolver.account.assert_called_once_with("Savings") + client.request.assert_not_called() # existed -> no create + + def test_if_not_exists_creates_when_missing(self): + from firefly_cli.errors import ResolutionError + ctx, client, resolver = make_ctx() + resolver.account.side_effect = ResolutionError('No account named "Savings"') + client.request.return_value = {"data": {"id": "9", "attributes": {}}} + rc = acct.cmd_create( + self._args(name="Savings", type="asset", if_not_exists=True), ctx) + self.assertEqual(rc, 0) + method, path = client.request.call_args[0][:2] + self.assertEqual((method, path), ("POST", "/api/v1/accounts")) + + def test_if_not_exists_emits_existed_flag(self): + import io, json + from contextlib import redirect_stdout + ctx, client, resolver = make_ctx() + resolver.account.return_value = {"id": "5", "name": "Savings"} + buf = io.StringIO() + with redirect_stdout(buf): + acct.cmd_create( + self._args(name="Savings", type="asset", if_not_exists=True), ctx) + self.assertEqual(json.loads(buf.getvalue()), + {"id": "5", "name": "Savings", "existed": True}) -- cgit v1.2.3