- Fix schema ordering: move :journal-entry-line/running-balance to schema.edn - Add invoice_behaviors_test.clj covering: - Permission gates (26.5, 26.6, 26.8) - Lock date blocking (27.1, 27.3) - New invoice validation (8.1, 8.5) - Edit invoice (11.1, 11.3) - Bulk edit (15.4) - Single/bulk void (16.3, 16.4, 17.1) - Unvoid restoring from history (18.1) - Undo autopay (19.1) - Invoice list filtering (2.6, 2.8, 2.10, 2.14) - Invoice list sorting (3.5, 3.7, 3.10) - Invoice list pagination (4.1, 4.3) - Legacy route redirects (28.1) - Mock Solr in wrap-setup fixture to prevent Connection refused - Fix setup-test-data to merge user-provided entities with defaults - Fix InMemSolrClient.index_documents to handle entity IDs - Fix ezcater_xls test to use dynamic entity IDs - Update invoice.md behavior checklist with completed items
127 lines
4.8 KiB
Clojure
127 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}
|
|
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)))
|