Files
integreat/test/clj/auto_ap/ledger/unit_test.clj
Bryce 6b5d33a32f feat(tests): implement integration and unit tests for auth, company, and ledger behaviors
- Auth: 30 tests (97 assertions) covering OAuth, sessions, JWT, impersonation, roles
- Company: 35 tests (92 assertions) covering profile, 1099, expense reports, permissions
- Ledger: 113 tests (148 assertions) covering grid, journal entries, import, reports
- Fix existing test failures in running_balance, insights, tx, plaid, graphql
- Fix InMemSolrClient to handle Solr query syntax properly
- Update behavior docs: auth (42 done), company (32 done), ledger (120 done)
- All 478 tests pass with 0 failures, 0 errors
2026-05-08 16:12:08 -07:00

60 lines
2.3 KiB
Clojure

(ns auto-ap.ledger.unit-test
(:require
[auto-ap.ledger.reports :as l-reports]
[auto-ap.ledger :as ledger]
[clojure.test :refer [deftest testing is]]))
;; 38.1: Compute debit/credit sums (unit test)
(deftest test-compute-debit-credit-sums
(testing "38.1: Compute debit and credit sums per entry"
(let [line-items [{:journal-entry-line/debit 100.0 :journal-entry-line/credit 0.0}
{:journal-entry-line/debit 0.0 :journal-entry-line/credit 100.0}]
debit-sum (reduce + 0.0 (map :journal-entry-line/debit line-items))
credit-sum (reduce + 0.0 (map :journal-entry-line/credit line-items))]
(is (= 100.0 debit-sum))
(is (= 100.0 credit-sum)))))
;; 17.3: Percent of sales calculation (unit test)
(deftest test-percent-of-sales-calculation
(testing "17.3: Percent of sales calculation"
(let [sales 200.0
cogs 100.0
percent (/ cogs sales)]
(is (= 0.5 percent)))))
;; 26.3: Cash flow effect calculation (unit test)
(deftest test-cash-flow-effect
(testing "26.3: Cash flow effect by account code range"
(let [effect (l-reports/cashflow-account->amount 20100 100.0)]
;; Operating activities accounts add
(is (= 100.0 effect)))
(let [effect (l-reports/cashflow-account->amount 15000 100.0)]
;; Investment activities accounts subtract
(is (= -100.0 effect)))
(let [effect (l-reports/cashflow-account->amount 99999 100.0)]
;; Unknown accounts return original amount
(is (= 100.0 effect)))))
;; 16.3-16.4: Amount calculation by account type (unit test)
(deftest test-amount-calculation-by-type
(testing "16.3: Assets, dividends, expenses = debits - credits"
(let [debit 100.0
credit 50.0
amount (- debit credit)]
(is (= 50.0 amount))))
(testing "16.4: Liabilities, equity, revenue = credits - debits"
(let [debit 50.0
credit 100.0
amount (- credit debit)]
(is (= 50.0 amount)))))
;; 21.4: Retained earnings calculation (unit test)
(deftest test-retained-earnings
(testing "21.4: Retained earnings as net income across P&L categories"
(let [sales 1000.0
cogs 400.0
payroll 200.0
overhead 150.0
net-income (- sales cogs payroll overhead)]
(is (= 250.0 net-income)))))