Added check printing test
This commit is contained in:
@@ -3,13 +3,20 @@
|
||||
[auto-ap.datomic :refer [conn]]
|
||||
[auto-ap.graphql.accounts :as sut]
|
||||
[auto-ap.integration.util :refer [admin-token user-token wrap-setup]]
|
||||
[clojure.test :as t :refer [deftest is testing use-fixtures]]
|
||||
[datomic.api :as d]))
|
||||
[datomic.client.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}]})
|
||||
(sut/rebuild-search-index)
|
||||
(is (> (count (sut/search {:id (admin-token)}
|
||||
{:query "Food Research"}
|
||||
nil
|
||||
@@ -17,45 +24,47 @@
|
||||
0)))
|
||||
(testing "It should find exact matches by numbers"
|
||||
(is (= (count (sut/search {:id (admin-token)}
|
||||
{:query "5110"}
|
||||
{:query "51100"}
|
||||
nil
|
||||
))
|
||||
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}])
|
||||
(is (= 0 (count (sut/search {:id (admin-token)}
|
||||
{:query "CLIENTSPECIFIC"}
|
||||
nil
|
||||
))))
|
||||
(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}]})
|
||||
(sut/rebuild-search-index)
|
||||
(is (= [] (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"))]
|
||||
(sut/rebuild-search-index)
|
||||
(is (= 1 (count (sut/search {:id (admin-token)}
|
||||
{:query "HELLOWORLD"
|
||||
:client_id client-id}
|
||||
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))))
|
||||
@@ -69,14 +78,15 @@
|
||||
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}]})
|
||||
(sut/rebuild-search-index)
|
||||
(is (some? (:warning (first (sut/search {:id (admin-token)}
|
||||
{:query "WARNING"
|
||||
:allowance :global}
|
||||
@@ -90,36 +100,39 @@
|
||||
: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}]})
|
||||
(sut/rebuild-search-index)
|
||||
(is (= 1 (count (sut/search {:id (admin-token)}
|
||||
{:query "ADMINONLY"}
|
||||
nil))))
|
||||
(is (= 0 (count (sut/search {:id (user-token 1)}
|
||||
(is (= 0 (count (sut/search {:id (user-token)}
|
||||
{:query "ADMINONLY"}
|
||||
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"))]
|
||||
(sut/rebuild-search-index)
|
||||
(is (= 0 (count (sut/search {:id (admin-token)}
|
||||
{:query "VENDORONLY"
|
||||
:allowance :invoice}
|
||||
@@ -133,11 +146,12 @@
|
||||
|
||||
(deftest get-graphql
|
||||
(testing "should retrieve a single account"
|
||||
(d/transact conn [{:account/numeric-code 1
|
||||
:account/default-allowance :allowance/allowed
|
||||
:account/type :account-type/asset
|
||||
:account/location "A"
|
||||
:account/name "Test"}])
|
||||
(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"}]})
|
||||
|
||||
(is (= {:name "Test",
|
||||
:invoice_allowance nil,
|
||||
:numeric_code 1,
|
||||
@@ -199,7 +213,5 @@
|
||||
:numeric_code)))
|
||||
(testing "Should not allow changing numeric code"
|
||||
|
||||
(is (= 123 (:numeric_code edit-result)))
|
||||
))))))
|
||||
|
||||
|
||||
(is (= 123 (:numeric_code edit-result))))))
|
||||
(testing "should disallow"))))
|
||||
|
||||
@@ -10,6 +10,19 @@
|
||||
|
||||
(use-fixtures :each wrap-setup)
|
||||
|
||||
(defn sample-payment [& kwargs]
|
||||
(apply assoc
|
||||
{: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"}
|
||||
kwargs))
|
||||
|
||||
|
||||
(deftest get-payment-page
|
||||
(testing "Should list payments"
|
||||
@@ -64,22 +77,223 @@
|
||||
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
(deftest void-payment
|
||||
(testing "Should void payments"
|
||||
(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"}])]
|
||||
(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)))))
|
||||
|
||||
:db/ident))))))
|
||||
(testing "Should not void payments if account is locked"
|
||||
(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 [{: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 [{: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 [{: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 [{: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 [{: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
|
||||
:bank_account_id bank-id
|
||||
:type :cash} nil)
|
||||
:invoices
|
||||
first)]
|
||||
(testing "Paying full balance should complete invoice"
|
||||
(is (= :paid (:status paid-invoice)))
|
||||
(is (= 0.0 (:outstanding_balance paid-invoice))))
|
||||
(testing "Payment should exist"
|
||||
(is (= 30.0 (-> paid-invoice
|
||||
:payments
|
||||
first
|
||||
:amount))))
|
||||
(testing "Should create a transaction for cash payments"
|
||||
(is (seq (d/q '[:find (pull ?t [* {:transaction/payment [*]}])
|
||||
:in $ ?p
|
||||
:where [?t :transaction/payment]
|
||||
[?t :transaction/amount -30.0]]
|
||||
(d/db conn)
|
||||
(-> paid-invoice
|
||||
:payments
|
||||
first
|
||||
:payment
|
||||
:id))))))))
|
||||
|
||||
(testing "Should allow 'printing' debit checks"
|
||||
(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
|
||||
:bank_account_id bank-id
|
||||
:type :debit} nil)
|
||||
:invoices
|
||||
first)]
|
||||
(testing "Paying full balance should complete invoice"
|
||||
(is (= :paid (:status paid-invoice)))
|
||||
(is (= 0.0 (:outstanding_balance paid-invoice))))
|
||||
(testing "Payment should exist"
|
||||
(is (= 50.0 (-> paid-invoice
|
||||
:payments
|
||||
first
|
||||
:amount))))
|
||||
(testing "Should not create a transaction for debit payments"
|
||||
(is (not (seq (d/q '[:find (pull ?t [* {:transaction/payment [*]}])
|
||||
:in $ ?p
|
||||
:where [?t :transaction/payment]
|
||||
[?t :transaction/amount -50.0]]
|
||||
(d/db conn)
|
||||
(-> paid-invoice
|
||||
:payments
|
||||
first
|
||||
:payment
|
||||
:id)))))))))
|
||||
|
||||
(testing "Should allow printing checks"
|
||||
(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)
|
||||
:invoices
|
||||
first)
|
||||
paid-invoice result]
|
||||
(testing "Paying full balance should complete invoice"
|
||||
(is (= :paid (:status paid-invoice)))
|
||||
(is (= 0.0 (:outstanding_balance paid-invoice))))
|
||||
(testing "Payment should exist"
|
||||
(is (= 150.0 (-> paid-invoice
|
||||
:payments
|
||||
first
|
||||
:amount))))
|
||||
(testing "Should create pdf"
|
||||
(is (-> paid-invoice
|
||||
:payments
|
||||
first
|
||||
:payment
|
||||
:s3_url))))))))
|
||||
|
||||
Reference in New Issue
Block a user