summaryrefslogtreecommitdiffstats
path: root/tests/unit/test_commands_account.py
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-06-30 13:07:06 +0200
committerDanilo M. <danix@danix.xyz>2026-06-30 13:07:06 +0200
commit93dbbe18e934d87ebf6ae6c614bb26f0e9e5afa5 (patch)
tree73770fb498e16103528bdd350d9159d3ead170aa /tests/unit/test_commands_account.py
parent2db11aa5d34766e4d23ccc308c57c470b6aa6dba (diff)
downloadfirefly-cli-0.2.0.tar.gz
firefly-cli-0.2.0.zip
account create: add verb for asset/expense/revenue accountsv0.2.0
New `firefly account create <name> --type asset|expense|revenue` [--opening-balance N] [--currency CODE]. asset accounts default to the defaultAsset role; opening balance is dated today (Firefly pairs the two). Unsupported types (liability, etc.) are a hard client-side error with no API call. Live-verified against the test instance. Bumps to 0.2.0. Docs synced: README, CLAUDE.md, SKILL.md, including the category/tag auto-create clarification. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'tests/unit/test_commands_account.py')
-rw-r--r--tests/unit/test_commands_account.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/unit/test_commands_account.py b/tests/unit/test_commands_account.py
index 4d28802..2c07780 100644
--- a/tests/unit/test_commands_account.py
+++ b/tests/unit/test_commands_account.py
@@ -2,6 +2,7 @@ import unittest
from unittest.mock import MagicMock
from firefly_cli.commands import account as acct
from firefly_cli.context import Context
+from firefly_cli.errors import FireflyError
def make_ctx():
client = MagicMock()
@@ -25,3 +26,52 @@ class TestAccountCmd(unittest.TestCase):
rc = acct.cmd_balance(args, ctx)
resolver.account.assert_called_once_with("Checking")
self.assertEqual(rc, 0)
+
+class TestAccountCreate(unittest.TestCase):
+ def _args(self, **kw):
+ base = dict(name=None, type=None, opening_balance=None, currency=None)
+ base.update(kw)
+ m = MagicMock()
+ m.configure_mock(**base) # 'name' is reserved in MagicMock ctor, not configure_mock
+ return m
+
+ def test_asset_posts_with_default_role(self):
+ ctx, client, _ = make_ctx()
+ client.request.return_value = {"data": {"id": "9", "attributes": {}}}
+ rc = acct.cmd_create(self._args(name="Savings", type="asset"), ctx)
+ self.assertEqual(rc, 0)
+ method, path = client.request.call_args[0][:2]
+ body = client.request.call_args[1]["body"]
+ self.assertEqual((method, path), ("POST", "/api/v1/accounts"))
+ self.assertEqual(body["name"], "Savings")
+ self.assertEqual(body["type"], "asset")
+ self.assertEqual(body["account_role"], "defaultAsset")
+
+ def test_expense_has_no_role(self):
+ ctx, client, _ = make_ctx()
+ client.request.return_value = {"data": {"id": "9", "attributes": {}}}
+ acct.cmd_create(self._args(name="Rent", type="expense"), ctx)
+ body = client.request.call_args[1]["body"]
+ self.assertNotIn("account_role", body)
+
+ def test_opening_balance_adds_date(self):
+ ctx, client, _ = make_ctx()
+ client.request.return_value = {"data": {"id": "9", "attributes": {}}}
+ acct.cmd_create(
+ self._args(name="Savings", type="asset", opening_balance="500"), ctx)
+ body = client.request.call_args[1]["body"]
+ self.assertEqual(body["opening_balance"], "500")
+ self.assertIn("opening_balance_date", body) # required_with by Firefly
+
+ def test_currency_passed_through(self):
+ ctx, client, _ = make_ctx()
+ client.request.return_value = {"data": {"id": "9", "attributes": {}}}
+ acct.cmd_create(
+ self._args(name="Savings", type="asset", currency="EUR"), ctx)
+ self.assertEqual(client.request.call_args[1]["body"]["currency_code"], "EUR")
+
+ def test_bad_type_is_hard_error_no_request(self):
+ ctx, client, _ = make_ctx()
+ with self.assertRaises(FireflyError):
+ acct.cmd_create(self._args(name="X", type="bogus"), ctx)
+ client.request.assert_not_called()