scrubbed all reference to datomic.api

This commit is contained in:
2023-03-20 12:54:56 -07:00
parent 8290138156
commit 9260834135
19 changed files with 731 additions and 611 deletions

View File

@@ -1,43 +1,9 @@
(ns auto-ap.integration.graphql.accounts
(:require
[auto-ap.datomic :refer [conn uri]]
[auto-ap.datomic.migrate :as m]
[auto-ap.datomic :refer [conn]]
[auto-ap.graphql.accounts :as sut]
[clj-time.core :as time]
[clojure.test :as t :refer [deftest is testing use-fixtures]]
[datomic.api :as d]))
(defn wrap-setup
[f]
(with-redefs [auto-ap.datomic/uri "datomic:mem://datomic-transactor:4334/invoice"]
(d/create-database uri)
(with-redefs [auto-ap.datomic/conn (d/connect uri)]
(m/migrate conn)
@(d/transact conn (->> (d/q '[:find ?a
:where [?a :account/name]]
(d/db conn))
(map (fn [[a]]
{:db/id a
:account/applicability :account-applicability/global}))))
(f)
(d/release conn)
(d/delete-database uri))))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn admin-token []
{:user "TEST ADMIN"
:exp (time/plus (time/now) (time/days 1))
:user/role "admin"
:user/name "TEST ADMIN"})
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn user-token [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}]})
[auto-ap.integration.util :refer [admin-token user-token wrap-setup]]
[clojure.test :as t :refer [deftest is testing use-fixtures]]))
(use-fixtures :each wrap-setup)
@@ -55,24 +21,24 @@
))
1)))
(testing "It should filter out accounts that are not allowed for clients"
@(d/transact conn [{:account/name "CLIENT SPECIFIC"
:db/ident :client-specific-account
:account/numeric-code 99999
:account/search-terms "CLIENTSPECIFIC"
:account/applicability :account-applicability/customized
:account/default-allowance :allowance/allowed}])
(dc/transact conn {:tx-data [{:account/name "CLIENT SPECIFIC"
:db/ident :client-specific-account
:account/numeric-code 99999
:account/search-terms "CLIENTSPECIFIC"
:account/applicability :account-applicability/customized
:account/default-allowance :allowance/allowed}]})
(is (= 0 (count (sut/search {:id (admin-token)}
{:query "CLIENTSPECIFIC"}
nil
))))
(testing "It should show up for the client specific version"
(let [client-id (-> @(d/transact conn [{:client/name "CLIENT"
:db/id "client"}
{:db/ident :client-specific-account
:account/client-overrides [{:account-client-override/client "client"
:account-client-override/name "HI"
:account-client-override/search-terms "HELLOWORLD"}]}])
(let [client-id (-> (dc/transact conn {:tx-data [{:client/name "CLIENT"
:db/id "client"}
{:db/ident :client-specific-account
:account/client-overrides [{:account-client-override/client "client"
:account-client-override/name "HI"
:account-client-override/search-terms "HELLOWORLD"}]}]})
:tempids
(get "client"))]
(is (= 1 (count (sut/search {:id (admin-token)}
@@ -81,14 +47,14 @@
nil))))))
(testing "It should hide accounts that arent applicable"
@(d/transact conn [{:account/name "DENIED"
:db/ident :denied-account
:account/numeric-code 99998
:account/search-terms "DENIED"
:account/applicability :account-applicability/global
:account/default-allowance :allowance/denied
:account/vendor-allowance :allowance/denied
:account/invoice-allowance :allowance/denied}])
(dc/transact conn {:tx-data [{:account/name "DENIED"
:db/ident :denied-account
:account/numeric-code 99998
:account/search-terms "DENIED"
:account/applicability :account-applicability/global
:account/default-allowance :allowance/denied
:account/vendor-allowance :allowance/denied
:account/invoice-allowance :allowance/denied}]})
(is (= 0 (count (sut/search {:id (admin-token)}
{:query "DENIED"}
nil))))
@@ -102,14 +68,14 @@
nil)))))
(testing "It should warn when using a warn account"
@(d/transact conn [{:account/name "WARNING"
:db/ident :warn-account
:account/numeric-code 99997
:account/search-terms "WARNING"
:account/applicability :account-applicability/global
:account/default-allowance :allowance/warn
:account/vendor-allowance :allowance/warn
:account/invoice-allowance :allowance/warn}])
(dc/transact conn {:tx-data [{:account/name "WARNING"
:db/ident :warn-account
:account/numeric-code 99997
:account/search-terms "WARNING"
:account/applicability :account-applicability/global
:account/default-allowance :allowance/warn
:account/vendor-allowance :allowance/warn
:account/invoice-allowance :allowance/warn}]})
(is (some? (:warning (first (sut/search {:id (admin-token)}
{:query "WARNING"
:allowance :global}
@@ -123,14 +89,14 @@
:allowance :vendor}
nil))))))
(testing "It should only include admin accounts for admins"
@(d/transact conn [{:account/name "ADMINONLY"
:db/ident :warn-account
:account/numeric-code 99997
:account/search-terms "ADMINONLY"
:account/applicability :account-applicability/global
:account/default-allowance :allowance/admin-only
:account/vendor-allowance :allowance/admin-only
:account/invoice-allowance :allowance/admin-only}])
(dc/transact conn {:tx-data [{:account/name "ADMINONLY"
:db/ident :warn-account
:account/numeric-code 99997
:account/search-terms "ADMINONLY"
:account/applicability :account-applicability/global
:account/default-allowance :allowance/admin-only
:account/vendor-allowance :allowance/admin-only
:account/invoice-allowance :allowance/admin-only}]})
(is (= 1 (count (sut/search {:id (admin-token)}
{:query "ADMINONLY"}
nil))))
@@ -139,20 +105,21 @@
nil)))))
(testing "It should allow searching for vendor accounts for invoices"
(let [vendor-id (-> @(d/transact conn [{:account/name "VENDORONLY"
:db/id "vendor-only"
:db/ident :vendor-only
:account/numeric-code 99996
:account/search-terms "VENDORONLY"
:account/applicability :account-applicability/global
:account/default-allowance :allowance/allowed
:account/vendor-allowance :allowance/allowed
:account/invoice-allowance :allowance/denied}
{:vendor/name "Allowed"
:vendor/default-account "vendor-only"
:db/id "vendor"}])
:tempids
(get "vendor"))]
(let [vendor-id (-> (dc/transact conn {:tx-data
[{:account/name "VENDORONLY"
:db/id "vendor-only"
:db/ident :vendor-only
:account/numeric-code 99996
:account/search-terms "VENDORONLY"
:account/applicability :account-applicability/global
:account/default-allowance :allowance/allowed
:account/vendor-allowance :allowance/allowed
:account/invoice-allowance :allowance/denied}
{:vendor/name "Allowed"
:vendor/default-account "vendor-only"
:db/id "vendor"}]})
:tempids
(get "vendor"))]
(is (= 0 (count (sut/search {:id (admin-token)}
{:query "VENDORONLY"
:allowance :invoice}

View File

@@ -1,64 +1,68 @@
(ns auto-ap.integration.graphql.clients
(:require
[auto-ap.time-reader]
[auto-ap.datomic :refer [conn uri]]
[auto-ap.datomic :refer [conn pull-attr]]
[auto-ap.graphql.clients :as sut]
[auto-ap.integration.util :refer [admin-token user-token wrap-setup]]
[clojure.test :as t :refer [deftest is testing use-fixtures]]
[com.brunobonacci.mulog :as mu]
[datomic.api :as d]))
[auto-ap.integration.util :refer [wrap-setup user-token admin-token]]
[datomic.client.api :as dc]
[clojure.test :as t :refer [deftest is testing use-fixtures]]))
(use-fixtures :each wrap-setup)
(deftest current-balance
(testing "it should start with a balance of 0"
@(d/transact (d/connect uri)
[{:client/code "TEST"
:client/bank-accounts [{:bank-account/code "TEST-1"}]}])
(dc/transact conn
{:tx-data
[{:client/code "TEST"
:client/bank-accounts [{:bank-account/code "TEST-1"}]}]})
(sut/refresh-current-balance)
(is (= 0.00
(:bank-account/current-balance (d/entity (d/db conn) [:bank-account/code "TEST-1"])))))
(pull-attr (dc/db conn) :bank-account/current-balance [:bank-account/code "TEST-1"] ))))
(testing "it should consider a single transaction"
@(d/transact (d/connect uri)
[{:client/code "TEST"
:db/id "TEST"
:client/bank-accounts [{:bank-account/code "TEST-1"
:db/id "TEST-1"}]}
{:journal-entry-line/account "TEST-1"
:journal-entry-line/debit 13.50}
(dc/transact conn
{:tx-data
[{:client/code "TEST"
:db/id "TEST"
:client/bank-accounts [{:bank-account/code "TEST-1"
:db/id "TEST-1"}]}
{:journal-entry-line/account "TEST-1"
:journal-entry-line/debit 13.50}
{:journal-entry-line/account "TEST-1"
:journal-entry-line/debit 19.50}])
{:journal-entry-line/account "TEST-1"
:journal-entry-line/debit 19.50}]})
(sut/refresh-current-balance)
(is (= -33.0
(:bank-account/current-balance (d/entity (d/db conn) [:bank-account/code "TEST-1"])))))
(pull-attr (dc/db conn) :bank-account/current-balance [:bank-account/code "TEST-1"]))))
(testing "bank accounts should start in a needing refresh state"
(let [bank-account-id (-> @(d/transact (d/connect uri)
[{:client/code "TEST"
:db/id "TEST"
:client/bank-accounts [{:bank-account/code "TEST-2" :db/id "TEST-2"}]}
])
(let [bank-account-id (-> (dc/transact conn
{:tx-data
[{:client/code "TEST"
:db/id "TEST"
:client/bank-accounts [{:bank-account/code "TEST-2" :db/id "TEST-2"}]}
]})
:tempids
(get "TEST-2"))]
(is ((sut/bank-accounts-needing-refresh) bank-account-id ))))
(testing "bank accounts should not need a refresh if balance is up-to-date"
(let [bank-account-id (-> @(d/transact (d/connect uri)
[{:client/code "TEST"
:db/id "TEST"
:client/bank-accounts [{:bank-account/code "TEST-3" :db/id "TEST-3"}]}
])
(let [bank-account-id (-> (dc/transact conn
{:tx-data
[{:client/code "TEST"
:db/id "TEST"
:client/bank-accounts [{:bank-account/code "TEST-3" :db/id "TEST-3"}]}
]})
:tempids
(get "TEST-3"))]
(sut/refresh-bank-account-current-balance bank-account-id)
(is (not ((sut/bank-accounts-needing-refresh) bank-account-id )))
@(d/transact (d/connect uri)
[{:journal-entry-line/account [:bank-account/code "TEST-3"]
:journal-entry-line/debit -10.50}
])
(dc/transact conn
{:tx-data
[{:journal-entry-line/account [:bank-account/code "TEST-3"]
:journal-entry-line/debit -10.50}
]})
(is ((sut/bank-accounts-needing-refresh) bank-account-id ))
(sut/refresh-bank-account-current-balance bank-account-id)
(is (not ((sut/bank-accounts-needing-refresh) bank-account-id ))))))

View File

@@ -1,55 +1,26 @@
(ns auto-ap.integration.graphql.invoices
(:require
[auto-ap.datomic :refer [conn uri]]
[auto-ap.datomic.migrate :as m]
[auto-ap.time-reader]
[auto-ap.datomic :refer [conn]]
[auto-ap.graphql.invoices :as sut]
[clj-time.core :as time]
[clojure.test :as t :refer [deftest is testing use-fixtures]]
[datomic.api :as d]))
(defn wrap-setup
[f]
(with-redefs [auto-ap.datomic/uri "datomic:mem://datomic-transactor:4334/invoice"]
(d/create-database uri)
(with-redefs [auto-ap.datomic/conn (d/connect uri)]
(m/migrate conn)
(f)
(d/release conn)
(d/delete-database uri))))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn admin-token []
{:user "TEST ADMIN"
:exp (time/plus (time/now) (time/days 1))
:user/role "admin"
:user/name "TEST ADMIN"})
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn user-token [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}]})
[auto-ap.integration.util :refer [admin-token wrap-setup]]
[clojure.test :as t :refer [deftest is testing use-fixtures]]))
(use-fixtures :each wrap-setup)
(deftest test-add-invoice
(testing "It should Add an invoice"
(let [{:strs [vendor-id client-id account-id]}
(:tempids @(d/transact conn [{:client/code "ABC"
:db/id "client-id"
:client/locations ["DT"]}
{:vendor/name "Vendy"
:db/id "vendor-id"
:vendor/default-account "account-id"}
{:account/name "Account"
:account/numeric-code 123
:account/invoice-allowance :allowance/allowed
:db/id "account-id"}]))]
(:tempids (dc/transact conn
{:tx-data [{:client/code "ABC"
:db/id "client-id"
:client/locations ["DT"]}
{:vendor/name "Vendy"
:db/id "vendor-id"
:vendor/default-account "account-id"}
{:account/name "Account"
:account/numeric-code 123
:account/invoice-allowance :allowance/allowed
:db/id "account-id"}]}))]
(is (some? (sut/add-invoice {:id (admin-token)}
{:invoice {:client_id client-id
:vendor_id vendor-id
@@ -62,11 +33,11 @@
nil)))
(testing "It should prevent an expense account that isn't allowed"
(let [{:strs [denied-account-id]}
(:tempids @(d/transact conn [
{:account/name "Account"
:account/numeric-code 123
:account/invoice-allowance :allowance/denied
:db/id "denied-account-id"}]))]
(:tempids (dc/transact conn
{:tx-data [{:account/name "Account"
:account/numeric-code 123
:account/invoice-allowance :allowance/denied
:db/id "denied-account-id"}]}))]
(is (thrown? Exception (sut/add-invoice {:id (admin-token)}
{:invoice {:client_id client-id
:vendor_id vendor-id
@@ -80,15 +51,15 @@
(testing "It should allow an expense account that is valid for the vendor"
(let [{:strs [vendor-account-id vendor-2]}
(:tempids @(d/transact conn [
{:account/name "Account"
:account/numeric-code 123
:account/invoice-allowance :allowance/denied
:account/vendor-allowance :allowance/allowed
:db/id "vendor-account-id"}
{:vendor/name "Testy"
:vendor/default-account "vendor-account-id"
:db/id "vendor-2"}]))]
(:tempids (dc/transact conn {:tx-data [
{:account/name "Account"
:account/numeric-code 123
:account/invoice-allowance :allowance/denied
:account/vendor-allowance :allowance/allowed
:db/id "vendor-account-id"}
{:vendor/name "Testy"
:vendor/default-account "vendor-account-id"
:db/id "vendor-2"}]}))]
(is (some? (sut/add-invoice {:id (admin-token)}
{:invoice {:client_id client-id
:vendor_id vendor-2

View File

@@ -1,49 +1,21 @@
(ns auto-ap.integration.graphql.vendors
(:require [auto-ap.graphql.vendors :as sut2]
[auto-ap.datomic :refer [uri conn]]
[auto-ap.datomic.migrate :as m]
[clojure.test :as t :refer [deftest is testing use-fixtures]]
[datomic.api :as d]
[clj-time.core :as time]))
(defn wrap-setup
[f]
(with-redefs [auto-ap.datomic/uri "datomic:mem://datomic-transactor:4334/invoice"]
(d/create-database uri)
(with-redefs [auto-ap.datomic/conn (d/connect uri)]
(m/migrate conn)
(f)
(d/release conn)
(d/delete-database uri))))
(defn admin-token []
{:user "TEST ADMIN"
:exp (time/plus (time/now) (time/days 1))
:user/role "admin"
:user/name "TEST ADMIN"})
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn user-token [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}]})
(:require
[auto-ap.datomic :refer [conn]]
[auto-ap.graphql.vendors :as sut2]
[auto-ap.integration.util :refer [admin-token wrap-setup]]
[clojure.test :as t :refer [deftest is testing use-fixtures]]
[datomic.client.api :as dc]))
(use-fixtures :each wrap-setup)
(deftest vendors
(testing "vendors"
(let [{:strs [vendor]} (:tempids @(d/transact (d/connect uri) [{:vendor/name "Test" :db/id "vendor"}
{:db/id "client"
:client/code "DEF"}]))]
(let [{:strs [vendor]} (:tempids (dc/transact conn {:tx-data [{:vendor/name "Test" :db/id "vendor"}
{:db/id "client"
:client/code "DEF"}]}))]
(testing "it should find vendors"
(let [result (sut2/get-graphql {:id (admin-token)} {} {})]
(is ((into #{} (map :id (:vendors result))) vendor ))))
)))
(is ((into #{} (map :id (:vendors result))) vendor )))))))