Files
integreat/test/clj/auto_ap/integration/util.clj
Bryce 1a48abdd7c test(invoice): implement integration tests for invoice behaviors
Adds comprehensive integration tests covering:
- Invoice list filtering (vendor, account, date range, due date, amount, import status, scheduled payments, unresolved, location)
- Invoice list sorting (date, invoice number, due date, total, outstanding balance, vendor, client, location)
- Invoice list pagination (default 25, custom per-page)
- Selection behaviors (select all filtered)
- Permission gates (GraphQL layer behavior)
- Lock date behaviors (edit, void, unvoid, undo autopay, bulk operations)
- Single/Bulk void with payment exclusions
- Bulk edit with lock date exclusions
- Credit payment (net zero, multiple vendors blocked, positive balance blocked)
- Import validation (missing fields, unmatchable vendors, no client access)
- Import approve/disapprove
- Legacy route redirects

Updates docs/testing/behaviors/invoice.md with 76 completed behavior markers.

57 tests, 99 assertions, all passing.
2026-05-05 05:00:51 -07:00

128 lines
4.8 KiB
Clojure

(ns auto-ap.integration.util
(:require [datomic.api :as dc]
[auto-ap.datomic :refer [conn transact-schema install-functions]]
[clj-time.core :as time]))
(defn wrap-setup
[f]
(with-redefs [auto-ap.datomic/uri "datomic:mem://test"
auto-ap.solr/impl (auto-ap.solr/->InMemSolrClient (atom {}))]
(dc/create-database auto-ap.datomic/uri)
(with-redefs [auto-ap.datomic/conn (dc/connect auto-ap.datomic/uri)]
(transact-schema conn)
(install-functions)
(f)
(dc/delete-database auto-ap.datomic/uri))))
(defn admin-token []
{:user "TEST ADMIN"
:exp (time/plus (time/now) (time/days 1))
:user/role "admin"
:user/name "TEST ADMIN"})
(defn user-token
([] (user-token 1))
([client-id]
{:user "TEST USER"
:exp (time/plus (time/now) (time/days 1))
:user/role "user"
:user/name "TEST USER"
:user/clients [{:db/id client-id}]}))
(defn user-token-no-access []
{:user "TEST USER"
:exp (time/plus (time/now) (time/days 1))
:user/role "user"
:user/name "TEST USER"
:user/clients []})
(defn test-client [& kwargs]
(apply assoc {:db/id "client-id"
:client/code (str "CLIENT" (rand-int 100000))
:client/locations ["DT"]}
kwargs))
(defn test-vendor [& kwargs]
(apply assoc {:db/id "vendor-id"
:vendor/name "Vendorson"
:vendor/default-account "test-account-id"}
kwargs))
(defn test-bank-account [& kwargs]
(apply assoc {:db/id "bank-account-id"
:bank-account/code (str "CLIENT-" (rand-int 100000))
:bank-account/type :bank-account-type/check
:bank-account/check-number 1000}
kwargs))
(defn test-transaction [& kwargs]
(apply assoc {:db/id "transaction-id"
:transaction/date #inst "2022-01-01"
:transaction/client "test-client-id"
:transaction/bank-account "test-bank-account-id"
:transaction/id (str (java.util.UUID/randomUUID))
:transaction/amount 100.0
:transaction/description-original "original description"} kwargs))
(defn test-payment [& kwargs]
(apply assoc {:db/id "test-payment-id"
:payment/date #inst "2022-01-01"
:payment/client "test-client-id"
:payment/bank-account "test-bank-account-id"
:payment/type :payment-type/check
:payment/vendor "test-vendor-id"
:payment/amount 100.0}
kwargs))
(defn test-invoice [& kwargs]
(apply assoc {:db/id "test-invoice-id"
:invoice/date #inst "2022-01-01"
:invoice/client "test-client-id"
:invoice/status :invoice-status/unpaid
:invoice/import-status :import-status/imported
:invoice/total 100.0
:invoice/outstanding-balance 100.00
:invoice/vendor "test-vendor-id"
:invoice/invoice-number (str "INVOICE " (rand-int 1000000))
:invoice/expense-accounts [{:invoice-expense-account/account "test-account-id"
:invoice-expense-account/amount 100.0
:invoice-expense-account/location "DT"}]}
kwargs))
(defn test-account [& kwargs]
(apply assoc {:db/id "account-id"
:account/name "Account"
:account/type :account-type/asset}
kwargs))
(defn test-transaction-rule [& kwargs]
(apply assoc {:db/id "test-transaction-rule-id"
:transaction-rule/client "test-client-id"
:transaction-rule/transaction-approval-status :transaction-approval-status/approved
:transaction-rule/note "Test"}
kwargs))
(defn dissoc-id [x]
(dissoc x :id))
(defn setup-test-data [data]
(let [defaults [(test-account :db/id "test-account-id")
(test-client :db/id "test-client-id"
:client/bank-accounts [(test-bank-account :db/id "test-bank-account-id")])
(test-vendor :db/id "test-vendor-id")
{:db/id "accounts-payable-id"
:account/name "Accounts Payable"
:db/ident :account/accounts-payable
:account/numeric-code 21000
:account/account-set "default"}]
user-ids (set (keep :db/id data))
merged (into [] (concat data (remove #(user-ids (:db/id %)) defaults)))]
(:tempids @(dc/transact conn merged))))
(defn apply-tx [data]
(:db-after @(dc/transact conn data)))