Migrates back to datomic on-prem
This commit is contained in:
@@ -3,19 +3,19 @@
|
||||
[auto-ap.datomic :refer [conn]]
|
||||
[auto-ap.graphql.accounts :as sut]
|
||||
[auto-ap.integration.util :refer [admin-token user-token wrap-setup]]
|
||||
[datomic.client.api :as dc]
|
||||
[datomic.api :as dc]
|
||||
[clojure.test :as t :refer [deftest is testing use-fixtures]]))
|
||||
|
||||
(use-fixtures :each wrap-setup)
|
||||
|
||||
(deftest test-account-search
|
||||
(testing "It should find matching account names"
|
||||
(dc/transact conn {:tx-data [{:account/name "Food Research"
|
||||
:db/ident :client-specific-account
|
||||
:account/numeric-code 51100
|
||||
:account/search-terms "Food Research"
|
||||
:account/applicability :account-applicability/global
|
||||
:account/default-allowance :allowance/allowed}]})
|
||||
(dc/transact conn [{:account/name "Food Research"
|
||||
:db/ident :client-specific-account
|
||||
:account/numeric-code 51100
|
||||
:account/search-terms "Food Research"
|
||||
:account/applicability :account-applicability/global
|
||||
:account/default-allowance :allowance/allowed}])
|
||||
(sut/rebuild-search-index)
|
||||
(is (> (count (sut/search {:id (admin-token)}
|
||||
{:query "Food Research"}
|
||||
@@ -29,12 +29,12 @@
|
||||
))
|
||||
1)))
|
||||
(testing "It should filter out accounts that are not allowed for clients"
|
||||
(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}]})
|
||||
(dc/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}])
|
||||
(sut/rebuild-search-index)
|
||||
(is (= [] (sut/search {:id (admin-token)}
|
||||
{:query "CLIENTSPECIFIC"}
|
||||
@@ -42,12 +42,12 @@
|
||||
)))
|
||||
|
||||
(testing "It should show up for the client specific version"
|
||||
(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"}]}]})
|
||||
(let [client-id (-> (dc/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"}]}])
|
||||
:tempids
|
||||
(get "client"))]
|
||||
(sut/rebuild-search-index)
|
||||
@@ -57,14 +57,14 @@
|
||||
nil))))))
|
||||
|
||||
(testing "It should hide accounts that arent applicable"
|
||||
(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}]})
|
||||
(dc/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}])
|
||||
(is (= 0 (count (sut/search {:id (admin-token)}
|
||||
{:query "DENIED"}
|
||||
nil))))
|
||||
@@ -78,14 +78,14 @@
|
||||
nil)))))
|
||||
|
||||
(testing "It should warn when using a warn account"
|
||||
(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}]})
|
||||
(dc/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}])
|
||||
(sut/rebuild-search-index)
|
||||
(is (some? (:warning (first (sut/search {:id (admin-token)}
|
||||
{:query "WARNING"
|
||||
@@ -100,14 +100,14 @@
|
||||
:allowance :vendor}
|
||||
nil))))))
|
||||
(testing "It should only include admin accounts for admins"
|
||||
(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}]})
|
||||
(dc/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}])
|
||||
(sut/rebuild-search-index)
|
||||
(is (= 1 (count (sut/search {:id (admin-token)}
|
||||
{:query "ADMINONLY"}
|
||||
@@ -117,19 +117,18 @@
|
||||
nil)))))
|
||||
|
||||
(testing "It should allow searching for vendor accounts for invoices"
|
||||
(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"}]})
|
||||
(let [vendor-id (-> (dc/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"))]
|
||||
(sut/rebuild-search-index)
|
||||
@@ -146,11 +145,11 @@
|
||||
|
||||
(deftest get-graphql
|
||||
(testing "should retrieve a single account"
|
||||
(dc/transact conn {:tx-data [{:account/numeric-code 1
|
||||
:account/default-allowance :allowance/allowed
|
||||
:account/type :account-type/asset
|
||||
:account/location "A"
|
||||
:account/name "Test"}]})
|
||||
(dc/transact conn [{:account/numeric-code 1
|
||||
:account/default-allowance :allowance/allowed
|
||||
:account/type :account-type/asset
|
||||
:account/location "A"
|
||||
:account/name "Test"}])
|
||||
|
||||
(is (= {:name "Test",
|
||||
:invoice_allowance nil,
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
wrap-setup]]
|
||||
[clojure.test :as t :refer [deftest is testing use-fixtures]]
|
||||
[com.brunobonacci.mulog :as mu]
|
||||
[datomic.client.api :as d]))
|
||||
[datomic.api :as d]))
|
||||
|
||||
(use-fixtures :each wrap-setup)
|
||||
|
||||
@@ -31,19 +31,19 @@
|
||||
|
||||
(deftest get-payment-page
|
||||
(testing "Should list payments"
|
||||
(let [{{:strs [bank-id check-id client-id]} :tempids} (d/transact conn {:tx-data [{:bank-account/code "bank"
|
||||
:db/id "bank-id"}
|
||||
{:client/code "client"
|
||||
:db/id "client-id"}
|
||||
{:db/id "check-id"
|
||||
:payment/check-number 1000
|
||||
:payment/bank-account "bank-id"
|
||||
:payment/client "client-id"
|
||||
:payment/type :payment-type/check
|
||||
:payment/amount 123.50
|
||||
:payment/paid-to "Someone"
|
||||
:payment/status :payment-status/pending
|
||||
:payment/date #inst "2022-01-01"}]})]
|
||||
(let [{{:strs [bank-id check-id client-id]} :tempids} (d/transact conn [{:bank-account/code "bank"
|
||||
:db/id "bank-id"}
|
||||
{:client/code "client"
|
||||
:db/id "client-id"}
|
||||
{:db/id "check-id"
|
||||
:payment/check-number 1000
|
||||
:payment/bank-account "bank-id"
|
||||
:payment/client "client-id"
|
||||
:payment/type :payment-type/check
|
||||
:payment/amount 123.50
|
||||
:payment/paid-to "Someone"
|
||||
:payment/status :payment-status/pending
|
||||
:payment/date #inst "2022-01-01"}])]
|
||||
(is (= [ {:amount 123.5,
|
||||
:type :check,
|
||||
:bank_account {:id bank-id, :code "bank"},
|
||||
@@ -86,103 +86,103 @@
|
||||
|
||||
(deftest void-payment
|
||||
(testing "Should void payments"
|
||||
(let [{{:strs [bank-id check-id client-id]} :tempids} (d/transact conn {:tx-data [{:bank-account/code "bank"
|
||||
:db/id "bank-id"}
|
||||
{:client/code "client"
|
||||
:db/id "client-id"}
|
||||
(sample-payment :db/id "check-id")]})]
|
||||
(let [{{:strs [bank-id check-id client-id]} :tempids} (d/transact conn [{:bank-account/code "bank"
|
||||
:db/id "bank-id"}
|
||||
{:client/code "client"
|
||||
:db/id "client-id"}
|
||||
(sample-payment :db/id "check-id")])]
|
||||
(sut/void-payment {:id (admin-token)} {:payment_id check-id} nil)
|
||||
(is (= :payment-status/voided (-> (d/pull (d/db conn) [{:payment/status [:db/ident ]}] check-id)
|
||||
:payment/status
|
||||
:db/ident)))))
|
||||
|
||||
(testing "Should not void payments if account is locked"
|
||||
(let [{{:strs [check-id]} :tempids} (d/transact conn {:tx-data [{:bank-account/code "bank"
|
||||
:db/id "bank-id"}
|
||||
{:client/code "client"
|
||||
:db/id "client-id"
|
||||
:client/locked-until #inst "2030-01-01"}
|
||||
(sample-payment :payment/client "client-id"
|
||||
:db/id "check-id"
|
||||
:payment/date #inst "2020-01-01")]})]
|
||||
(let [{{:strs [check-id]} :tempids} (d/transact conn [{:bank-account/code "bank"
|
||||
:db/id "bank-id"}
|
||||
{:client/code "client"
|
||||
:db/id "client-id"
|
||||
:client/locked-until #inst "2030-01-01"}
|
||||
(sample-payment :payment/client "client-id"
|
||||
:db/id "check-id"
|
||||
:payment/date #inst "2020-01-01")])]
|
||||
(is (thrown? Exception (sut/void-payment {:id (admin-token)} {:payment_id check-id} nil))))))
|
||||
|
||||
(deftest void-payments
|
||||
(testing "bulk void"
|
||||
(testing "Should bulk void payments if account is not locked"
|
||||
(let [{{:strs [check-id]} :tempids} (d/transact conn {:tx-data [{:bank-account/code "bank"
|
||||
:db/id "bank-id"}
|
||||
{:client/code "client-new"
|
||||
:db/id "client-id"}
|
||||
(sample-payment :payment/client "client-id"
|
||||
:db/id "check-id"
|
||||
:payment/date #inst "2020-01-01")]})]
|
||||
(let [{{:strs [check-id]} :tempids} (d/transact conn [{:bank-account/code "bank"
|
||||
:db/id "bank-id"}
|
||||
{:client/code "client-new"
|
||||
:db/id "client-id"}
|
||||
(sample-payment :payment/client "client-id"
|
||||
:db/id "check-id"
|
||||
:payment/date #inst "2020-01-01")])]
|
||||
(sut/void-payments {:id (admin-token)} {:filters {:date_range {:start #inst "2000-01-01"}}} nil)
|
||||
(is (= :payment-status/voided (-> (d/pull (d/db conn) '[{:payment/status [:db/ident]}] check-id)
|
||||
:payment/status
|
||||
:db/ident)))))
|
||||
|
||||
(testing "Should only void a payment if it matches filter criteria"
|
||||
(let [{{:strs [check-id]} :tempids} (d/transact conn {:tx-data [{:bank-account/code "bank"
|
||||
:db/id "bank-id"}
|
||||
{:client/code "client-new"
|
||||
:db/id "client-id"}
|
||||
(sample-payment :payment/client "client-id"
|
||||
:db/id "check-id"
|
||||
:payment/date #inst "2020-01-01")]})]
|
||||
(let [{{:strs [check-id]} :tempids} (d/transact conn [{:bank-account/code "bank"
|
||||
:db/id "bank-id"}
|
||||
{:client/code "client-new"
|
||||
:db/id "client-id"}
|
||||
(sample-payment :payment/client "client-id"
|
||||
:db/id "check-id"
|
||||
:payment/date #inst "2020-01-01")])]
|
||||
(sut/void-payments {:id (admin-token)} {:filters {:date_range {:start #inst "2022-01-01"}}} nil)
|
||||
(is (= :payment-status/pending (-> (d/pull (d/db conn) '[{:payment/status [:db/ident]}] check-id)
|
||||
:payment/status
|
||||
:db/ident)))))
|
||||
|
||||
(testing "Should not bulk void payments if account is locked"
|
||||
(let [{{:strs [check-id]} :tempids} (d/transact conn {:tx-data [{:bank-account/code "bank"
|
||||
:db/id "bank-id"}
|
||||
{:client/code "client"
|
||||
:db/id "client-id"
|
||||
:client/locked-until #inst "2030-01-01"}
|
||||
(sample-payment :payment/client "client-id"
|
||||
:db/id "check-id"
|
||||
:payment/date #inst "2020-01-01")]})]
|
||||
(let [{{:strs [check-id]} :tempids} (d/transact conn [{:bank-account/code "bank"
|
||||
:db/id "bank-id"}
|
||||
{:client/code "client"
|
||||
:db/id "client-id"
|
||||
:client/locked-until #inst "2030-01-01"}
|
||||
(sample-payment :payment/client "client-id"
|
||||
:db/id "check-id"
|
||||
:payment/date #inst "2020-01-01")])]
|
||||
(sut/void-payments {:id (admin-token)} {:filters {:date_range {:start #inst "2000-01-01"}}} nil)
|
||||
(is (= :payment-status/pending (-> (d/pull (d/db conn) '[{:payment/status [:db/ident]}] check-id)
|
||||
:payment/status
|
||||
:db/ident)))))
|
||||
|
||||
(testing "Only admins should be able to bulk void"
|
||||
(let [{{:strs [check-id]} :tempids} (d/transact conn {:tx-data [{:bank-account/code "bank"
|
||||
:db/id "bank-id"}
|
||||
{:client/code "client"
|
||||
:db/id "client-id"}
|
||||
(sample-payment :payment/client "client-id"
|
||||
:db/id "check-id"
|
||||
:payment/date #inst "2020-01-01")]})]
|
||||
(let [{{:strs [check-id]} :tempids} (d/transact conn [{:bank-account/code "bank"
|
||||
:db/id "bank-id"}
|
||||
{:client/code "client"
|
||||
:db/id "client-id"}
|
||||
(sample-payment :payment/client "client-id"
|
||||
:db/id "check-id"
|
||||
:payment/date #inst "2020-01-01")])]
|
||||
(is (thrown? Exception (sut/void-payments {:id (user-token)} {:filters {:date_range {:start #inst "2000-01-01"}}} nil)))))))
|
||||
|
||||
|
||||
(deftest print-checks
|
||||
(testing "Print checks"
|
||||
(testing "Should allow 'printing' cash checks"
|
||||
(let [{{:strs [invoice-id client-id bank-id]} :tempids} (d/transact conn {:tx-data [{:client/code "client"
|
||||
:db/id "client-id"
|
||||
:client/locked-until #inst "2030-01-01"
|
||||
:client/bank-accounts [{:bank-account/code "bank"
|
||||
:db/id "bank-id"}]}
|
||||
{:db/id "vendor-id"
|
||||
:vendor/name "V"
|
||||
:vendor/default-account "account-id"}
|
||||
{:db/id "account-id"
|
||||
:account/name "My account"
|
||||
:account/numeric-code 21000}
|
||||
{:db/id "invoice-id"
|
||||
:invoice/client "client-id"
|
||||
:invoice/date #inst "2022-01-01"
|
||||
:invoice/vendor "vendor-id"
|
||||
:invoice/total 30.0
|
||||
:invoice/outstanding-balance 30.0
|
||||
:invoice/expense-accounts [{:db/id "invoice-expense-account"
|
||||
:invoice-expense-account/account "account-id"
|
||||
:invoice-expense-account/amount 30.0}]}]})]
|
||||
(let [{{:strs [invoice-id client-id bank-id]} :tempids} (d/transact conn [{:client/code "client"
|
||||
:db/id "client-id"
|
||||
:client/locked-until #inst "2030-01-01"
|
||||
:client/bank-accounts [{:bank-account/code "bank"
|
||||
:db/id "bank-id"}]}
|
||||
{:db/id "vendor-id"
|
||||
:vendor/name "V"
|
||||
:vendor/default-account "account-id"}
|
||||
{:db/id "account-id"
|
||||
:account/name "My account"
|
||||
:account/numeric-code 21000}
|
||||
{:db/id "invoice-id"
|
||||
:invoice/client "client-id"
|
||||
:invoice/date #inst "2022-01-01"
|
||||
:invoice/vendor "vendor-id"
|
||||
:invoice/total 30.0
|
||||
:invoice/outstanding-balance 30.0
|
||||
:invoice/expense-accounts [{:db/id "invoice-expense-account"
|
||||
:invoice-expense-account/account "account-id"
|
||||
:invoice-expense-account/amount 30.0}]}])]
|
||||
(let [paid-invoice (-> (sut/print-checks {:id (admin-token)} {:invoice_payments [{:invoice_id invoice-id
|
||||
:amount 30.0}]
|
||||
:client_id client-id
|
||||
@@ -211,25 +211,25 @@
|
||||
:id))))))))
|
||||
|
||||
(testing "Should allow 'printing' debit checks"
|
||||
(let [{{:strs [invoice-id client-id bank-id]} :tempids} (d/transact conn {:tx-data [{:client/code "client"
|
||||
:db/id "client-id"
|
||||
:client/bank-accounts [{:bank-account/code "bank"
|
||||
:db/id "bank-id"}]}
|
||||
{:db/id "vendor-id"
|
||||
:vendor/name "V"
|
||||
:vendor/default-account "account-id"}
|
||||
{:db/id "account-id"
|
||||
:account/name "My account"
|
||||
:account/numeric-code 21000}
|
||||
{:db/id "invoice-id"
|
||||
:invoice/client "client-id"
|
||||
:invoice/date #inst "2022-01-01"
|
||||
:invoice/vendor "vendor-id"
|
||||
:invoice/total 50.0
|
||||
:invoice/outstanding-balance 50.0
|
||||
:invoice/expense-accounts [{:db/id "invoice-expense-account"
|
||||
:invoice-expense-account/account "account-id"
|
||||
:invoice-expense-account/amount 50.0}]}]})]
|
||||
(let [{{:strs [invoice-id client-id bank-id]} :tempids} (d/transact conn [{:client/code "client"
|
||||
:db/id "client-id"
|
||||
:client/bank-accounts [{:bank-account/code "bank"
|
||||
:db/id "bank-id"}]}
|
||||
{:db/id "vendor-id"
|
||||
:vendor/name "V"
|
||||
:vendor/default-account "account-id"}
|
||||
{:db/id "account-id"
|
||||
:account/name "My account"
|
||||
:account/numeric-code 21000}
|
||||
{:db/id "invoice-id"
|
||||
:invoice/client "client-id"
|
||||
:invoice/date #inst "2022-01-01"
|
||||
:invoice/vendor "vendor-id"
|
||||
:invoice/total 50.0
|
||||
:invoice/outstanding-balance 50.0
|
||||
:invoice/expense-accounts [{:db/id "invoice-expense-account"
|
||||
:invoice-expense-account/account "account-id"
|
||||
:invoice-expense-account/amount 50.0}]}])]
|
||||
(let [paid-invoice (-> (sut/print-checks {:id (admin-token)} {:invoice_payments [{:invoice_id invoice-id
|
||||
:amount 50.0}]
|
||||
:client_id client-id
|
||||
@@ -258,33 +258,33 @@
|
||||
:id)))))))))
|
||||
|
||||
(testing "Should allow printing checks"
|
||||
(let [{{:strs [invoice-id client-id bank-id]} :tempids} (d/transact conn {:tx-data [{:client/code "client"
|
||||
:db/id "client-id"
|
||||
:client/bank-accounts [{:bank-account/code "bank"
|
||||
:bank-account/type :bank-account-type/check
|
||||
(let [{{:strs [invoice-id client-id bank-id]} :tempids} (d/transact conn [{:client/code "client"
|
||||
:db/id "client-id"
|
||||
:client/bank-accounts [{:bank-account/code "bank"
|
||||
:bank-account/type :bank-account-type/check
|
||||
|
||||
:bank-account/check-number 10000
|
||||
:db/id "bank-id"}]}
|
||||
{:db/id "vendor-id"
|
||||
:vendor/name "V"
|
||||
:vendor/default-account "account-id"}
|
||||
{:db/id "account-id"
|
||||
:account/name "My account"
|
||||
:account/numeric-code 21000}
|
||||
{:db/id "invoice-id"
|
||||
:invoice/client "client-id"
|
||||
:invoice/date #inst "2022-01-01"
|
||||
:invoice/vendor "vendor-id"
|
||||
:invoice/total 150.0
|
||||
:invoice/outstanding-balance 150.0
|
||||
:invoice/expense-accounts [{:db/id "invoice-expense-account"
|
||||
:invoice-expense-account/account "account-id"
|
||||
:invoice-expense-account/amount 150.0}]}]})]
|
||||
(let [result (-> (sut/print-checks {:id (admin-token)} {:invoice_payments [{:invoice_id invoice-id
|
||||
:amount 150.0}]
|
||||
:client_id client-id
|
||||
:bank_account_id bank-id
|
||||
:type :check} nil)
|
||||
:bank-account/check-number 10000
|
||||
:db/id "bank-id"}]}
|
||||
{:db/id "vendor-id"
|
||||
:vendor/name "V"
|
||||
:vendor/default-account "account-id"}
|
||||
{:db/id "account-id"
|
||||
:account/name "My account"
|
||||
:account/numeric-code 21000}
|
||||
{:db/id "invoice-id"
|
||||
:invoice/client "client-id"
|
||||
:invoice/date #inst "2022-01-01"
|
||||
:invoice/vendor "vendor-id"
|
||||
:invoice/total 150.0
|
||||
:invoice/outstanding-balance 150.0
|
||||
:invoice/expense-accounts [{:db/id "invoice-expense-account"
|
||||
:invoice-expense-account/account "account-id"
|
||||
:invoice-expense-account/amount 150.0}]}])]
|
||||
(let [result (-> (sut/print-checks {:id (admin-token)} {:invoice_payments [{:invoice_id invoice-id
|
||||
:amount 150.0}]
|
||||
:client_id client-id
|
||||
:bank_account_id bank-id
|
||||
:type :check} nil)
|
||||
:invoices
|
||||
first)
|
||||
paid-invoice result]
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
[auto-ap.datomic :refer [conn pull-attr]]
|
||||
[auto-ap.graphql.clients :as sut]
|
||||
[auto-ap.integration.util :refer [wrap-setup user-token admin-token]]
|
||||
[datomic.client.api :as dc]
|
||||
[datomic.api :as dc]
|
||||
[clojure.test :as t :refer [deftest is testing use-fixtures]]))
|
||||
|
||||
(use-fixtures :each wrap-setup)
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
test-invoice
|
||||
test-vendor
|
||||
wrap-setup]]
|
||||
[datomic.client.api :as d]))
|
||||
[datomic.api :as d]))
|
||||
(use-fixtures :each wrap-setup)
|
||||
|
||||
(deftest test-add-invoice
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
[iol-ion.tx :refer [upsert-ledger]]
|
||||
[auto-ap.integration.util :refer [wrap-setup]]
|
||||
[clojure.test :as t :refer [deftest is testing use-fixtures]]
|
||||
[datomic.client.api :as d]))
|
||||
[datomic.api :as d]))
|
||||
|
||||
(use-fixtures :each wrap-setup)
|
||||
|
||||
@@ -22,48 +22,48 @@
|
||||
line-2-1
|
||||
line-2-2
|
||||
line-3-1
|
||||
line-3-2]} (:tempids (d/transact conn {:tx-data [{:db/id "test-account-1"
|
||||
:account/type :account-type/asset}
|
||||
{:db/id "test-account-2"
|
||||
:account/type :account-type/equity}
|
||||
{:db/id "test-client"
|
||||
:client/code "TEST"}
|
||||
`(upsert-ledger {:db/id "journal-entry-1"
|
||||
:journal-entry/external-id "1"
|
||||
:journal-entry/date #inst "2022-01-01"
|
||||
:journal-entry/client "test-client"
|
||||
:journal-entry/line-items [{:db/id "line-1-1"
|
||||
:journal-entry-line/account "test-account-1"
|
||||
:journal-entry-line/location "A"
|
||||
:journal-entry-line/debit 10.0}
|
||||
{:db/id "line-1-2"
|
||||
:journal-entry-line/account "test-account-2"
|
||||
:journal-entry-line/location "A"
|
||||
:journal-entry-line/credit 10.0}]})
|
||||
`(upsert-ledger {:db/id "journal-entry-2"
|
||||
:journal-entry/date #inst "2022-01-02"
|
||||
:journal-entry/external-id "2"
|
||||
:journal-entry/client "test-client"
|
||||
:journal-entry/line-items [{:db/id "line-2-1"
|
||||
:journal-entry-line/account "test-account-1"
|
||||
:journal-entry-line/location "A"
|
||||
:journal-entry-line/debit 50.0}
|
||||
{:db/id "line-2-2"
|
||||
:journal-entry-line/account "test-account-2"
|
||||
:journal-entry-line/location "A"
|
||||
:journal-entry-line/credit 50.0}]})
|
||||
`(upsert-ledger {:db/id "journal-entry-3"
|
||||
:journal-entry/date #inst "2022-01-03"
|
||||
:journal-entry/external-id "3"
|
||||
:journal-entry/client "test-client"
|
||||
:journal-entry/line-items [{:db/id "line-3-1"
|
||||
:journal-entry-line/account "test-account-1"
|
||||
:journal-entry-line/location "A"
|
||||
:journal-entry-line/debit 150.0}
|
||||
{:db/id "line-3-2"
|
||||
:journal-entry-line/account "test-account-2"
|
||||
:journal-entry-line/location "A"
|
||||
:journal-entry-line/credit 150.0}]})]}))]
|
||||
line-3-2]} (:tempids (d/transact conn [{:db/id "test-account-1"
|
||||
:account/type :account-type/asset}
|
||||
{:db/id "test-account-2"
|
||||
:account/type :account-type/equity}
|
||||
{:db/id "test-client"
|
||||
:client/code "TEST"}
|
||||
`(upsert-ledger {:db/id "journal-entry-1"
|
||||
:journal-entry/external-id "1"
|
||||
:journal-entry/date #inst "2022-01-01"
|
||||
:journal-entry/client "test-client"
|
||||
:journal-entry/line-items [{:db/id "line-1-1"
|
||||
:journal-entry-line/account "test-account-1"
|
||||
:journal-entry-line/location "A"
|
||||
:journal-entry-line/debit 10.0}
|
||||
{:db/id "line-1-2"
|
||||
:journal-entry-line/account "test-account-2"
|
||||
:journal-entry-line/location "A"
|
||||
:journal-entry-line/credit 10.0}]})
|
||||
`(upsert-ledger {:db/id "journal-entry-2"
|
||||
:journal-entry/date #inst "2022-01-02"
|
||||
:journal-entry/external-id "2"
|
||||
:journal-entry/client "test-client"
|
||||
:journal-entry/line-items [{:db/id "line-2-1"
|
||||
:journal-entry-line/account "test-account-1"
|
||||
:journal-entry-line/location "A"
|
||||
:journal-entry-line/debit 50.0}
|
||||
{:db/id "line-2-2"
|
||||
:journal-entry-line/account "test-account-2"
|
||||
:journal-entry-line/location "A"
|
||||
:journal-entry-line/credit 50.0}]})
|
||||
`(upsert-ledger {:db/id "journal-entry-3"
|
||||
:journal-entry/date #inst "2022-01-03"
|
||||
:journal-entry/external-id "3"
|
||||
:journal-entry/client "test-client"
|
||||
:journal-entry/line-items [{:db/id "line-3-1"
|
||||
:journal-entry-line/account "test-account-1"
|
||||
:journal-entry-line/location "A"
|
||||
:journal-entry-line/debit 150.0}
|
||||
{:db/id "line-3-2"
|
||||
:journal-entry-line/account "test-account-2"
|
||||
:journal-entry-line/location "A"
|
||||
:journal-entry-line/credit 150.0}]})]))]
|
||||
|
||||
(testing "should set running-balance on ledger entries missing them"
|
||||
|
||||
@@ -79,10 +79,9 @@
|
||||
(testing "should recompute if the data is out of date"
|
||||
|
||||
(d/transact conn
|
||||
{:tx-data
|
||||
[{:db/id line-1-1
|
||||
:journal-entry-line/dirty true
|
||||
:journal-entry-line/running-balance 123810.23}]})
|
||||
[{:db/id line-1-1
|
||||
:journal-entry-line/dirty true
|
||||
:journal-entry-line/running-balance 123810.23}])
|
||||
(sut/refresh-running-balance-cache)
|
||||
|
||||
(is (= [-10.0 -60.0 -210.0]
|
||||
@@ -91,20 +90,18 @@
|
||||
(testing "should recompute every entry after the out of date one"
|
||||
|
||||
(d/transact conn
|
||||
{:tx-data
|
||||
[{:db/id line-1-1
|
||||
:journal-entry-line/dirty true
|
||||
:journal-entry-line/debit 70.0}]})
|
||||
[{:db/id line-1-1
|
||||
:journal-entry-line/dirty true
|
||||
:journal-entry-line/debit 70.0}])
|
||||
(sut/refresh-running-balance-cache)
|
||||
(is (= [-70.0 -120.0 -270.0]
|
||||
(map #(pull-attr (d/db conn) :journal-entry-line/running-balance %) [line-1-1 line-2-1 line-3-1]))))
|
||||
(testing "should not recompute entries that aren't dirty"
|
||||
|
||||
(d/transact conn
|
||||
{:tx-data
|
||||
[{:db/id line-1-1
|
||||
:journal-entry-line/dirty false
|
||||
:journal-entry-line/debit 90.0}]})
|
||||
[{:db/id line-1-1
|
||||
:journal-entry-line/dirty false
|
||||
:journal-entry-line/debit 90.0}])
|
||||
(sut/refresh-running-balance-cache)
|
||||
(is (= [-70.0 -120.0 -270.0]
|
||||
(map #(pull-attr (d/db conn) :journal-entry-line/running-balance %) [line-1-1 line-2-1 line-3-1])))
|
||||
@@ -112,19 +109,18 @@
|
||||
)
|
||||
(testing "changing a ledger entry should mark the line items as dirty"
|
||||
(d/transact conn
|
||||
{:tx-data
|
||||
[`(upsert-ledger ~{:db/id journal-entry-2
|
||||
:journal-entry/date #inst "2022-01-02"
|
||||
:journal-entry/client test-client
|
||||
:journal-entry/external-id "2"
|
||||
:journal-entry/line-items [{:db/id "line-2-1"
|
||||
:journal-entry-line/account test-account-1
|
||||
:journal-entry-line/location "A"
|
||||
:journal-entry-line/debit 50.0}
|
||||
{:db/id "line-2-2"
|
||||
:journal-entry-line/account test-account-2
|
||||
:journal-entry-line/location "A"
|
||||
:journal-entry-line/credit 50.0}]})]})
|
||||
[`(upsert-ledger ~{:db/id journal-entry-2
|
||||
:journal-entry/date #inst "2022-01-02"
|
||||
:journal-entry/client test-client
|
||||
:journal-entry/external-id "2"
|
||||
:journal-entry/line-items [{:db/id "line-2-1"
|
||||
:journal-entry-line/account test-account-1
|
||||
:journal-entry-line/location "A"
|
||||
:journal-entry-line/debit 50.0}
|
||||
{:db/id "line-2-2"
|
||||
:journal-entry-line/account test-account-2
|
||||
:journal-entry-line/location "A"
|
||||
:journal-entry-line/credit 50.0}]})])
|
||||
(is (= [true true]
|
||||
(->> (d/pull (d/db conn) '[{:journal-entry/line-items [:journal-entry-line/dirty]}] journal-entry-2)
|
||||
(:journal-entry/line-items)
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
user-token
|
||||
wrap-setup]]
|
||||
[clojure.test :as t :refer [deftest is testing use-fixtures]]
|
||||
[datomic.client.api :as dc]))
|
||||
[datomic.api :as dc]))
|
||||
|
||||
(use-fixtures :each wrap-setup)
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
[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.client.api :as d]))
|
||||
[datomic.api :as d]))
|
||||
|
||||
(use-fixtures :each wrap-setup)
|
||||
|
||||
@@ -15,12 +15,12 @@
|
||||
(testing "should allow editing a user"
|
||||
|
||||
|
||||
(let [{{:strs [user-id] } :tempids} (d/transact conn {:tx-data [{:db/id "user-id" :user/name "Bryce"}]})
|
||||
(let [{{:strs [user-id] } :tempids} (d/transact conn [{:db/id "user-id" :user/name "Bryce"}])
|
||||
result (sut/edit-user {:id (admin-token)} {:edit_user {:role :power_user :id user-id}} nil)]
|
||||
(is (some? (:id result))
|
||||
(= :power_user (:role result)))
|
||||
(testing "Should allow adding clients"
|
||||
(let [{{:strs [client-id] } :tempids} (d/transact conn {:tx-data [{:db/id "client-id" :client/name "Bryce"}]})
|
||||
(let [{{:strs [client-id] } :tempids} (d/transact conn [{:db/id "client-id" :client/name "Bryce"}])
|
||||
result (sut/edit-user {:id (admin-token)} {:edit_user {:role :power_user
|
||||
:id user-id
|
||||
:clients [(str client-id)]}} nil)]
|
||||
|
||||
Reference in New Issue
Block a user