- 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
124 lines
4.8 KiB
Clojure
124 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)))
|