Add vendor pre-population for bulk code and individual edit forms
- Add vendor-changed HTMX handlers for both bulk code and individual edit - Pre-populate default account at 100% when vendor is selected and no accounts exist - Fix render-accounts-section to render from step-params correctly - Change bulk code vendor-changed from hx-get to hx-post to include form data - Add routes for vendor-changed endpoints - Update e2e tests to cover vendor pre-population - Run lein cljfmt fix across codebase
This commit is contained in:
@@ -53,28 +53,26 @@
|
||||
(t/testing "It should find the order from ezcater"
|
||||
(with-redefs [sut/get-caterer (fn [k]
|
||||
(t/is (= k "91541331-d7ae-4634-9e8b-ccbbcfb2ce70"))
|
||||
{
|
||||
:ezcater-integration/_caterers {:ezcater-integration/api-key "bmlrdHNpZ2FyaXNAZ21haWwuY29tOmQwMzQwMjYzOWI2ODQxNmVkMjdmZWYxMWFhZTk3YzU1MDlmNTcyNjYwMDAzOTA5MDE2OGMzODllNDBjNTVkZGE"}
|
||||
{:ezcater-integration/_caterers {:ezcater-integration/api-key "bmlrdHNpZ2FyaXNAZ21haWwuY29tOmQwMzQwMjYzOWI2ODQxNmVkMjdmZWYxMWFhZTk3YzU1MDlmNTcyNjYwMDAzOTA5MDE2OGMzODllNDBjNTVkZGE"}
|
||||
:ezcater-location/_caterer [{:ezcater-location/location "DT"
|
||||
:client/_ezcater-locations {:client/code "ABC"}}]
|
||||
})]
|
||||
:client/_ezcater-locations {:client/code "ABC"}}]})]
|
||||
(t/is (= known-order
|
||||
(sut/lookup-order sample-event))))))
|
||||
|
||||
(t/deftest order->sales-order
|
||||
(t/testing "It should use the date"
|
||||
(t/is (= #clj-time/date-time "2022-01-01T00:00:00-08:00"
|
||||
(-> known-order
|
||||
(assoc-in [:event :timestamp]
|
||||
"2022-01-01T08:00:00Z")
|
||||
(sut/order->sales-order)
|
||||
(:sales-order/date ))))
|
||||
(-> known-order
|
||||
(assoc-in [:event :timestamp]
|
||||
"2022-01-01T08:00:00Z")
|
||||
(sut/order->sales-order)
|
||||
(:sales-order/date))))
|
||||
(t/is (= #clj-time/date-time "2022-06-01T00:00:00-07:00"
|
||||
(-> known-order
|
||||
(assoc-in [:event :timestamp]
|
||||
"2022-06-01T07:00:00Z")
|
||||
(sut/order->sales-order)
|
||||
(:sales-order/date )))))
|
||||
(:sales-order/date)))))
|
||||
(t/testing "It should simulate a single line item for everything"
|
||||
(t/is (= 1
|
||||
(-> known-order
|
||||
@@ -83,49 +81,48 @@
|
||||
count)))
|
||||
(t/is (= #{"EZCater Catering"}
|
||||
(->> known-order
|
||||
sut/order->sales-order
|
||||
:sales-order/line-items
|
||||
(map :order-line-item/category)
|
||||
set))))
|
||||
sut/order->sales-order
|
||||
:sales-order/line-items
|
||||
(map :order-line-item/category)
|
||||
set))))
|
||||
|
||||
(t/testing "It should generate an external-id"
|
||||
(t/is (= "ezcater/order/ABC-DT-9ab05fee-a9c5-483b-a7f2-14debde4b7a8"
|
||||
(:sales-order/external-id (sut/order->sales-order known-order)))))
|
||||
|
||||
|
||||
(t/testing "Should capture amounts"
|
||||
(t/is (= 35.09 (-> known-order
|
||||
sut/order->sales-order
|
||||
:sales-order/tax)))
|
||||
(t/is (= 0.0 (-> known-order
|
||||
sut/order->sales-order
|
||||
:sales-order/tip))))
|
||||
sut/order->sales-order
|
||||
:sales-order/tip))))
|
||||
(t/testing "Should calculate 7% commision on ezcater orders"
|
||||
(t/is (dollars= 7.0
|
||||
(-> known-order
|
||||
(assoc :orderSourceType "EZCATER")
|
||||
(assoc-in [:totals :subTotal :subunits] 10000)
|
||||
sut/commision)))
|
||||
(t/is (dollars= 7.0
|
||||
(-> known-order
|
||||
(assoc :orderSourceType "EZCATER")
|
||||
(assoc-in [:totals :subTotal :subunits] 10000)
|
||||
sut/commision)))
|
||||
(t/testing "Should inlclude delivery fee in commision"
|
||||
(t/is (dollars= 14.0
|
||||
(-> known-order
|
||||
(assoc :orderSourceType "EZCATER")
|
||||
(assoc-in [:totals :subTotal :subunits] 10000)
|
||||
(assoc-in [:catererCart :feesAndDiscounts 0 :cost :subunits] 10000)
|
||||
sut/commision)))))
|
||||
(t/is (dollars= 14.0
|
||||
(-> known-order
|
||||
(assoc :orderSourceType "EZCATER")
|
||||
(assoc-in [:totals :subTotal :subunits] 10000)
|
||||
(assoc-in [:catererCart :feesAndDiscounts 0 :cost :subunits] 10000)
|
||||
sut/commision)))))
|
||||
(t/testing "Should calculate 15% commision on marketplace orders"
|
||||
(t/is (dollars= 15.0
|
||||
(-> known-order
|
||||
(assoc :orderSourceType "MARKETPLACE")
|
||||
(assoc-in [:totals :subTotal :subunits] 10000)
|
||||
sut/commision)))
|
||||
(t/is (dollars= 15.0
|
||||
(-> known-order
|
||||
(assoc :orderSourceType "MARKETPLACE")
|
||||
(assoc-in [:totals :subTotal :subunits] 10000)
|
||||
sut/commision)))
|
||||
(t/testing "Should inlclude delivery fee in commision"
|
||||
(t/is (dollars= 30.0
|
||||
(-> known-order
|
||||
(assoc :orderSourceType "MARKETPLACE")
|
||||
(assoc-in [:totals :subTotal :subunits] 10000)
|
||||
(assoc-in [:catererCart :feesAndDiscounts 0 :cost :subunits] 10000)
|
||||
sut/commision)))))
|
||||
(t/is (dollars= 30.0
|
||||
(-> known-order
|
||||
(assoc :orderSourceType "MARKETPLACE")
|
||||
(assoc-in [:totals :subTotal :subunits] 10000)
|
||||
(assoc-in [:catererCart :feesAndDiscounts 0 :cost :subunits] 10000)
|
||||
sut/commision)))))
|
||||
(t/testing "Should calculate 2.75% ccp fee"
|
||||
(t/is (dollars= 8.97
|
||||
(-> known-order
|
||||
@@ -138,7 +135,7 @@
|
||||
(t/is (dollars= 454.09
|
||||
(-> known-order
|
||||
sut/order->sales-order
|
||||
:sales-order/total))))
|
||||
:sales-order/total))))
|
||||
(t/testing "Should derive adjustments food-total + sales-tax - caterer-total - service fee - ccp fee"
|
||||
(t/is (dollars= -42.99
|
||||
(-> known-order
|
||||
|
||||
@@ -8,9 +8,8 @@
|
||||
:amount 123.45
|
||||
:date "2023-01-01"})
|
||||
|
||||
(t/deftest plaid->transaction
|
||||
(t/deftest plaid->transaction
|
||||
|
||||
|
||||
(t/testing "Should assign a plaid merchant if a merchant is found"
|
||||
(t/is (= "Home Depot" (-> (sut/plaid->transaction (assoc base-transaction
|
||||
:merchant_name "Home Depot")
|
||||
@@ -19,6 +18,6 @@
|
||||
:plaid-merchant/name))))
|
||||
(t/testing "Should assign a default vendor if a merchant is found, with a matching vendor lookup"
|
||||
(t/is (= 12354 (-> (sut/plaid->transaction (assoc base-transaction
|
||||
:merchant_name "Home Depot")
|
||||
{"Home Depot" 12354})
|
||||
:transaction/default-vendor)))))
|
||||
:merchant_name "Home Depot")
|
||||
{"Home Depot" 12354})
|
||||
:transaction/default-vendor)))))
|
||||
|
||||
@@ -71,7 +71,6 @@
|
||||
bank-account
|
||||
{}))))))
|
||||
|
||||
|
||||
(t/deftest transaction->txs
|
||||
(t/testing "Should import and code transactions"
|
||||
(t/testing "Should import one transaction"
|
||||
@@ -83,8 +82,8 @@
|
||||
:client/locations ["Z" "E"]
|
||||
:client/bank-accounts ["bank-account-id"]}]))
|
||||
result (sut/transaction->txs base-transaction
|
||||
(dc/pull (dc/db conn) sut/bank-account-pull bank-account-id)
|
||||
noop-rule)]
|
||||
(dc/pull (dc/db conn) sut/bank-account-pull bank-account-id)
|
||||
noop-rule)]
|
||||
(t/is (= (assoc base-transaction
|
||||
:transaction/approval-status :transaction-approval-status/unapproved
|
||||
:transaction/bank-account bank-account-id
|
||||
@@ -92,11 +91,11 @@
|
||||
result))))
|
||||
|
||||
(t/testing "Should apply a default vendor"
|
||||
(let [ {:strs [test-client-id test-bank-account-id test-vendor-id]} (setup-test-data [])
|
||||
(let [{:strs [test-client-id test-bank-account-id test-vendor-id]} (setup-test-data [])
|
||||
result (sut/transaction->txs (assoc base-transaction
|
||||
:transaction/default-vendor test-vendor-id)
|
||||
(dc/pull (dc/db conn) sut/bank-account-pull test-bank-account-id)
|
||||
noop-rule)]
|
||||
(dc/pull (dc/db conn) sut/bank-account-pull test-bank-account-id)
|
||||
noop-rule)]
|
||||
(t/is (= (assoc base-transaction
|
||||
:transaction/approval-status :transaction-approval-status/unapproved
|
||||
:transaction/bank-account test-bank-account-id
|
||||
@@ -125,21 +124,20 @@
|
||||
:transaction/description-original "CHECK 10001"
|
||||
:transaction/check-number 10001
|
||||
:transaction/amount -30.0)
|
||||
(dc/pull (dc/db conn ) sut/bank-account-pull bank-account-id)
|
||||
(dc/pull (dc/db conn) sut/bank-account-pull bank-account-id)
|
||||
noop-rule)]
|
||||
|
||||
|
||||
(t/is (= {:db/id payment-id
|
||||
:payment/status :payment-status/cleared}
|
||||
(:transaction/payment transaction-result))))
|
||||
|
||||
|
||||
(t/testing "Should match a check that matches on amount if check number does not match"
|
||||
(let [transaction-result (sut/transaction->txs (assoc base-transaction
|
||||
:transaction/description-original "CHECK 12301"
|
||||
:transaction/amount -30.0)
|
||||
(dc/pull (dc/db conn ) sut/bank-account-pull bank-account-id)
|
||||
(dc/pull (dc/db conn) sut/bank-account-pull bank-account-id)
|
||||
noop-rule)]
|
||||
|
||||
|
||||
(t/is (= {:db/id payment-id
|
||||
:payment/status :payment-status/cleared}
|
||||
(:transaction/payment transaction-result)))))
|
||||
@@ -151,11 +149,10 @@
|
||||
:transaction/amount -30.0)
|
||||
(dc/pull (dc/db conn) sut/bank-account-pull bank-account-id)
|
||||
noop-rule)]
|
||||
|
||||
|
||||
(t/is (= nil
|
||||
(:transaction/payment result)))))))
|
||||
|
||||
|
||||
(t/testing "Should match expected-deposits"
|
||||
(let [{:strs [bank-account-id client-id expected-deposit-id]} (->> [#:expected-deposit {:client "client-id"
|
||||
:date #inst "2021-07-01T00:00:00-08:00"
|
||||
@@ -174,7 +171,6 @@
|
||||
deref
|
||||
:tempids)]
|
||||
|
||||
|
||||
(t/testing "Should match within 10 days"
|
||||
(let [transaction-result (sut/transaction->txs (assoc base-transaction
|
||||
:transaction/date #inst "2021-07-03T00:00:00-08:00"
|
||||
@@ -183,7 +179,7 @@
|
||||
noop-rule)]
|
||||
(t/is (= expected-deposit-id
|
||||
(:db/id (sut/find-expected-deposit client-id 100.0 (clj-time.coerce/to-date-time #inst "2021-07-03T00:00:00-08:00")))))
|
||||
|
||||
|
||||
(t/is (= {:db/id expected-deposit-id
|
||||
:expected-deposit/status :expected-deposit-status/cleared}
|
||||
(:transaction/expected-deposit transaction-result)))))
|
||||
@@ -194,7 +190,7 @@
|
||||
(dc/pull (dc/db conn) sut/bank-account-pull bank-account-id)
|
||||
noop-rule)]
|
||||
(t/is (= :vendor/ccp-square
|
||||
(:transaction/vendor transaction-result)))))
|
||||
(:transaction/vendor transaction-result)))))
|
||||
|
||||
(t/testing "Should credit CCP"
|
||||
(let [transaction-result (sut/transaction->txs (assoc base-transaction
|
||||
@@ -262,7 +258,6 @@
|
||||
first
|
||||
:transaction/raw-id)))))
|
||||
|
||||
|
||||
(t/deftest match-transaction-to-single-unfulfilled-payments
|
||||
(t/testing "Auto-pay Invoices"
|
||||
(let [{:strs [vendor1-id vendor2-id]} (->> [#:vendor {:name "Autopay vendor 1"
|
||||
@@ -281,12 +276,11 @@
|
||||
:total 30.0
|
||||
:db/id "invoice-id"}
|
||||
#:client {:name "Client" :db/id "client-id"}]
|
||||
(dc/transact conn)
|
||||
deref
|
||||
:tempids)
|
||||
(dc/transact conn)
|
||||
deref
|
||||
:tempids)
|
||||
invoices-matches (sut/match-transaction-to-single-unfulfilled-autopayments -30.0 client-id)]
|
||||
(t/is (= 1 (count invoices-matches)))
|
||||
))
|
||||
(t/is (= 1 (count invoices-matches)))))
|
||||
|
||||
(t/testing "Should not match paid invoice that isn't a scheduled payment"
|
||||
(let [{:strs [client-id]} (->> [#:invoice{:status :invoice-status/paid
|
||||
@@ -300,13 +294,13 @@
|
||||
deref
|
||||
:tempids)
|
||||
invoices-matches (sut/match-transaction-to-single-unfulfilled-autopayments -30.0 client-id)]
|
||||
|
||||
|
||||
(t/is (= [] invoices-matches))))
|
||||
|
||||
(t/testing "Should not match unpaid invoice"
|
||||
(let [{:strs [client-id]} (->> [#:invoice {:status :invoice-status/unpaid
|
||||
:scheduled-payment #inst "2019-01-04"
|
||||
:vendor vendor1-id
|
||||
:vendor vendor1-id
|
||||
:date #inst "2019-01-01"
|
||||
:client "client-id"
|
||||
:total 30.0
|
||||
@@ -316,7 +310,7 @@
|
||||
deref
|
||||
:tempids)
|
||||
invoices-matches (sut/match-transaction-to-single-unfulfilled-autopayments -30.0 client-id)]
|
||||
|
||||
|
||||
(t/is (= [] invoices-matches))))
|
||||
|
||||
(t/testing "Should not match invoice that already has a payment"
|
||||
@@ -335,7 +329,7 @@
|
||||
deref
|
||||
:tempids)
|
||||
invoices-matches (sut/match-transaction-to-single-unfulfilled-autopayments -30.0
|
||||
client-id)]
|
||||
client-id)]
|
||||
(t/is (= [] invoices-matches))))
|
||||
(t/testing "Should match multiple invoices for same vendor that total to transaction amount"
|
||||
(let [{:strs [client-id]} (->> [#:invoice {:status :invoice-status/paid
|
||||
@@ -436,45 +430,41 @@
|
||||
(t/is (= [] (sut/match-transaction-to-single-unfulfilled-autopayments -31.0 client-id))
|
||||
(str "Expected to not match, because there is invoice-3 is between invoice-1 and invoice-2.")))))))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#_(t/testing "Auto-pay Invoices"
|
||||
(t/testing "Should match paid invoice that doesn't have a payment yet"
|
||||
(let [{:strs [bank-account-id client-id invoice1-id invoice2-id vendor-id]} (->> [#:invoice {:status :invoice-status/paid
|
||||
:vendor "vendor-id"
|
||||
:scheduled-payment #inst "2019-01-04"
|
||||
:date #inst "2019-01-01"
|
||||
:client "client-id"
|
||||
:total 20.0
|
||||
:db/id "invoice1-id"}
|
||||
#:invoice {:status :invoice-status/paid
|
||||
:vendor "vendor-id"
|
||||
:scheduled-payment #inst "2019-01-04"
|
||||
:date #inst "2019-01-01"
|
||||
:client "client-id"
|
||||
:total 10.0
|
||||
:db/id "invoice2-id"}
|
||||
#:vendor {:name "Autopay vendor"
|
||||
:db/id "vendor-id"}
|
||||
#:bank-account {:name "Bank account"
|
||||
:db/id "bank-account-id"}
|
||||
#:client {:name "Client"
|
||||
:db/id "client-id"
|
||||
:bank-accounts ["bank-account-id"]}]
|
||||
(d/transact (d/connect uri))
|
||||
deref
|
||||
:tempids)
|
||||
:vendor "vendor-id"
|
||||
:scheduled-payment #inst "2019-01-04"
|
||||
:date #inst "2019-01-01"
|
||||
:client "client-id"
|
||||
:total 20.0
|
||||
:db/id "invoice1-id"}
|
||||
#:invoice {:status :invoice-status/paid
|
||||
:vendor "vendor-id"
|
||||
:scheduled-payment #inst "2019-01-04"
|
||||
:date #inst "2019-01-01"
|
||||
:client "client-id"
|
||||
:total 10.0
|
||||
:db/id "invoice2-id"}
|
||||
#:vendor {:name "Autopay vendor"
|
||||
:db/id "vendor-id"}
|
||||
#:bank-account {:name "Bank account"
|
||||
:db/id "bank-account-id"}
|
||||
#:client {:name "Client"
|
||||
:db/id "client-id"
|
||||
:bank-accounts ["bank-account-id"]}]
|
||||
(d/transact (d/connect uri))
|
||||
deref
|
||||
:tempids)
|
||||
[[transaction-tx payment-tx invoice-payments1-tx invoice-payments2-tx]] (sut/yodlees->transactions [(assoc base-yodlee-transaction
|
||||
:amount {:amount 30.0}
|
||||
:bank-account {:db/id bank-account-id
|
||||
:client/_bank-accounts {:db/id client-id
|
||||
:client/locations ["A"]}})]
|
||||
:bank-account
|
||||
noop-rule
|
||||
#{})]
|
||||
|
||||
:amount {:amount 30.0}
|
||||
:bank-account {:db/id bank-account-id
|
||||
:client/_bank-accounts {:db/id client-id
|
||||
:client/locations ["A"]}})]
|
||||
:bank-account
|
||||
noop-rule
|
||||
#{})]
|
||||
|
||||
(t/is (= :transaction-approval-status/approved
|
||||
(:transaction/approval-status transaction-tx))
|
||||
(str "Should have approved transaction " transaction-tx))
|
||||
@@ -519,14 +509,14 @@
|
||||
deref
|
||||
:tempids)
|
||||
[[transaction-tx payment-tx]] (sut/yodlees->transactions [(assoc base-yodlee-transaction
|
||||
:amount {:amount 30.0}
|
||||
:bank-account {:db/id bank-account-id
|
||||
:client/_bank-accounts {:db/id client-id
|
||||
:client/locations ["A"]}})]
|
||||
:bank-account
|
||||
noop-rule
|
||||
#{})]
|
||||
|
||||
:amount {:amount 30.0}
|
||||
:bank-account {:db/id bank-account-id
|
||||
:client/_bank-accounts {:db/id client-id
|
||||
:client/locations ["A"]}})]
|
||||
:bank-account
|
||||
noop-rule
|
||||
#{})]
|
||||
|
||||
(t/is (= :transaction-approval-status/unapproved
|
||||
(:transaction/approval-status transaction-tx)))
|
||||
(t/is (nil? (:transaction/payment transaction-tx))))))
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
(:require [auto-ap.import.yodlee2 :as sut]
|
||||
[clojure.test :as t]))
|
||||
|
||||
|
||||
(def base-transaction {:postDate "2014-01-04"
|
||||
:accountId 1234
|
||||
:date "2014-01-02"
|
||||
@@ -26,6 +25,6 @@
|
||||
:baseType "DEBIT")
|
||||
false))))
|
||||
(t/is (= 12.0 (:transaction/amount (sut/yodlee->transaction (assoc base-transaction
|
||||
:amount {:amount 12.0}
|
||||
:baseType "CREDIT")
|
||||
:amount {:amount 12.0}
|
||||
:baseType "CREDIT")
|
||||
false))))))
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
[auto-ap.integration.util :refer [wrap-setup admin-token user-token setup-test-data test-transaction]]
|
||||
[auto-ap.datomic :refer [conn]]))
|
||||
|
||||
|
||||
(defn new-client [args]
|
||||
(merge {:client/name "Test client"
|
||||
:client/code (.toString (java.util.UUID/randomUUID))
|
||||
@@ -29,7 +28,7 @@
|
||||
(deftest transaction-page
|
||||
(testing "transaction page"
|
||||
(let [{:strs [test-client-id]} (setup-test-data [(test-transaction :transaction/description-original "hi")])]
|
||||
|
||||
|
||||
(testing "It should find all transactions"
|
||||
(let [result (:transaction-page (:data (sut/query (admin-token) "{ transaction_page(filters: {}) { count, start, data { id } }}" {:clients [{:db/id test-client-id}]})))]
|
||||
(is (= 1 (:count result)))
|
||||
@@ -42,13 +41,12 @@
|
||||
(is (= 0 (:start result)))
|
||||
(is (= 0 (count (:data result)))))))))
|
||||
|
||||
|
||||
(deftest invoice-page
|
||||
(testing "invoice page"
|
||||
@(dc/transact conn
|
||||
[(new-client {:db/id "client"})
|
||||
(new-invoice {:invoice/client "client"
|
||||
:invoice/status :invoice-status/paid})])
|
||||
[(new-client {:db/id "client"})
|
||||
(new-invoice {:invoice/client "client"
|
||||
:invoice/status :invoice-status/paid})])
|
||||
(testing "It should find all invoices"
|
||||
(let [result (first (:invoice-page (:data (sut/query (admin-token) "{ invoice_page(filters: { status:paid}) { count, start, invoices { id } }}"))))]
|
||||
(is (= 1 (:count result)))
|
||||
@@ -69,7 +67,6 @@
|
||||
(is (int? (:start result)))
|
||||
(is (seqable? (:journal-entries result)))))))
|
||||
|
||||
|
||||
(deftest vendors
|
||||
(testing "vendors"
|
||||
(testing "it should find vendors"
|
||||
@@ -88,17 +85,17 @@
|
||||
(is (seqable? (:transaction-rules result))))))
|
||||
|
||||
(deftest upsert-transaction-rule
|
||||
(let [{:strs [vendor-id account-id yodlee-merchant-id]} (->
|
||||
@(dc/transact
|
||||
conn
|
||||
[{:vendor/name "Bryce's Meat Co"
|
||||
:db/id "vendor-id"}
|
||||
{:account/name "hello"
|
||||
:db/id "account-id"}
|
||||
{:yodlee-merchant/name "yodlee"
|
||||
:db/id "yodlee-merchant-id"}])
|
||||
|
||||
:tempids)]
|
||||
(let [{:strs [vendor-id account-id yodlee-merchant-id]} (->
|
||||
@(dc/transact
|
||||
conn
|
||||
[{:vendor/name "Bryce's Meat Co"
|
||||
:db/id "vendor-id"}
|
||||
{:account/name "hello"
|
||||
:db/id "account-id"}
|
||||
{:yodlee-merchant/name "yodlee"
|
||||
:db/id "yodlee-merchant-id"}])
|
||||
|
||||
:tempids)]
|
||||
(testing "it should reject rules that don't add up to 100%"
|
||||
(let [q (v/graphql-query {:venia/operation {:operation/type :mutation
|
||||
:operation/name "UpsertTransactionRule"}
|
||||
@@ -106,10 +103,9 @@
|
||||
{:transaction-rule {:accounts [{:account-id account-id
|
||||
:percentage "0.25"
|
||||
:location "Shared"}]}}
|
||||
[:id ]])}]})]
|
||||
[:id]])}]})]
|
||||
(is (thrown? clojure.lang.ExceptionInfo (sut/query (admin-token) q)))))
|
||||
|
||||
|
||||
(testing "It should reject rules that are missing both description and merchant"
|
||||
(let [q (v/graphql-query {:venia/operation {:operation/type :mutation
|
||||
:operation/name "UpsertTransactionRule"}
|
||||
@@ -117,7 +113,7 @@
|
||||
{:transaction-rule {:accounts [{:account-id account-id
|
||||
:percentage "1.0"
|
||||
:location "Shared"}]}}
|
||||
[:id ]])}]})]
|
||||
[:id]])}]})]
|
||||
(is (thrown? clojure.lang.ExceptionInfo (sut/query (admin-token) q)))))
|
||||
(testing "it should add rules"
|
||||
(let [q (v/graphql-query {:venia/operation {:operation/type :mutation
|
||||
@@ -141,12 +137,12 @@
|
||||
result (-> (sut/query (admin-token) q)
|
||||
:data
|
||||
:upsert-transaction-rule)]
|
||||
|
||||
|
||||
(is (= "123" (:description result)))
|
||||
(is (= "Bryce's Meat Co" (-> result :vendor :name)))
|
||||
(is (= "yodlee" (-> result :yodlee-merchant :name)))
|
||||
(is (= :approved (:transaction-approval-status result)))
|
||||
(is (= "hello" (-> result :accounts (get 0) :account :name )))
|
||||
(is (= "hello" (-> result :accounts (get 0) :account :name)))
|
||||
(is (:id result))
|
||||
|
||||
(testing "it should unset removed fields"
|
||||
@@ -185,40 +181,39 @@
|
||||
|
||||
(is (= 1 (count (:accounts result))))))))))
|
||||
|
||||
|
||||
(deftest test-transaction-rule
|
||||
(testing "it should match rules"
|
||||
(let [matching-transaction @(dc/transact conn
|
||||
[{:transaction/description-original "matching-desc"
|
||||
:transaction/date #inst "2019-01-05T00:00:00.000-08:00"
|
||||
:transaction/client {:client/name "1"
|
||||
:db/id "client-1"}
|
||||
:transaction/bank-account {:db/id "bank-account-1"
|
||||
:bank-account/name "1"}
|
||||
[{:transaction/description-original "matching-desc"
|
||||
:transaction/date #inst "2019-01-05T00:00:00.000-08:00"
|
||||
:transaction/client {:client/name "1"
|
||||
:db/id "client-1"}
|
||||
:transaction/bank-account {:db/id "bank-account-1"
|
||||
:bank-account/name "1"}
|
||||
|
||||
:transaction/amount 1.00
|
||||
:transaction/id "2019-01-05 matching-desc 1"
|
||||
:db/id "a"}
|
||||
:transaction/amount 1.00
|
||||
:transaction/id "2019-01-05 matching-desc 1"
|
||||
:db/id "a"}
|
||||
|
||||
{:transaction/description-original "nonmatching-desc"
|
||||
:transaction/client {:client/name "2"
|
||||
:db/id "client-2"}
|
||||
:transaction/bank-account {:db/id "bank-account-2"
|
||||
:bank-account/name "2"}
|
||||
:transaction/date #inst "2019-01-15T23:23:00.000-08:00"
|
||||
:transaction/amount 2.00
|
||||
:transaction/id "2019-01-15 nonmatching-desc 2"
|
||||
:db/id "b"}])
|
||||
{:transaction/description-original "nonmatching-desc"
|
||||
:transaction/client {:client/name "2"
|
||||
:db/id "client-2"}
|
||||
:transaction/bank-account {:db/id "bank-account-2"
|
||||
:bank-account/name "2"}
|
||||
:transaction/date #inst "2019-01-15T23:23:00.000-08:00"
|
||||
:transaction/amount 2.00
|
||||
:transaction/id "2019-01-15 nonmatching-desc 2"
|
||||
:db/id "b"}])
|
||||
{:strs [a b client-1 client-2 bank-account-1 bank-account-2]} (get-in matching-transaction [:tempids])
|
||||
a (str a)
|
||||
b (str b)
|
||||
|
||||
rule-test (fn [rule]
|
||||
(-> (sut/query (admin-token) (v/graphql-query {:venia/operation {:operation/type :query
|
||||
:operation/name "TestTransactionRule"}
|
||||
:venia/queries [{:query/data (sut/->graphql [:test-transaction-rule
|
||||
{:transaction-rule rule}
|
||||
[:id]])}]}))
|
||||
:operation/name "TestTransactionRule"}
|
||||
:venia/queries [{:query/data (sut/->graphql [:test-transaction-rule
|
||||
{:transaction-rule rule}
|
||||
[:id]])}]}))
|
||||
:data
|
||||
:test-transaction-rule))]
|
||||
(testing "based on date "
|
||||
@@ -233,8 +228,8 @@
|
||||
|
||||
(testing "based on amount"
|
||||
(is (= [{:id a}] (rule-test {:amount-gte 1.0 :amount-lte 1.0})))
|
||||
(is (= (set [{:id a} {:id b}]) (set (rule-test {:amount-gte 1.0 }))) )
|
||||
(is (= (set [{:id a} {:id b}]) (set (rule-test {:amount-lte 2.0 }))) ))
|
||||
(is (= (set [{:id a} {:id b}]) (set (rule-test {:amount-gte 1.0}))))
|
||||
(is (= (set [{:id a} {:id b}]) (set (rule-test {:amount-lte 2.0})))))
|
||||
|
||||
(testing "based on client"
|
||||
(is (= [{:id a}] (rule-test {:client-id (str client-1)})))
|
||||
@@ -247,40 +242,40 @@
|
||||
(deftest test-match-transaction-rule
|
||||
(testing "it should apply a rules"
|
||||
(let [{:strs [transaction-id transaction-rule-id uneven-transaction-rule-id]} (-> @(dc/transact conn
|
||||
[{:transaction/description-original "matching-desc"
|
||||
:transaction/date #inst "2019-01-05T00:00:00.000-08:00"
|
||||
:transaction/client {:client/name "1"
|
||||
:db/id "client-1"}
|
||||
:transaction/bank-account {:db/id "bank-account-1"
|
||||
:bank-account/name "1"}
|
||||
:transaction/amount 1.00
|
||||
:db/id "transaction-id"}
|
||||
[{:transaction/description-original "matching-desc"
|
||||
:transaction/date #inst "2019-01-05T00:00:00.000-08:00"
|
||||
:transaction/client {:client/name "1"
|
||||
:db/id "client-1"}
|
||||
:transaction/bank-account {:db/id "bank-account-1"
|
||||
:bank-account/name "1"}
|
||||
:transaction/amount 1.00
|
||||
:db/id "transaction-id"}
|
||||
|
||||
{:db/id "transaction-rule-id"
|
||||
:transaction-rule/note "transaction rule note"
|
||||
:transaction-rule/description "matching-desc"
|
||||
:transaction-rule/accounts [{:transaction-rule-account/location "A"
|
||||
:transaction-rule-account/account {:account/numeric-code 123 :db/id "123"}
|
||||
:transaction-rule-account/percentage 1.0}]}
|
||||
{:db/id "uneven-transaction-rule-id"
|
||||
:transaction-rule/note "transaction rule note"
|
||||
:transaction-rule/description "matching-desc"
|
||||
:transaction-rule/accounts [{:transaction-rule-account/location "A"
|
||||
:transaction-rule-account/account {:account/numeric-code 123 :db/id "123"}
|
||||
:transaction-rule-account/percentage 0.3333333}
|
||||
{:transaction-rule-account/location "B"
|
||||
:transaction-rule-account/account {:account/numeric-code 123 :db/id "123"}
|
||||
:transaction-rule-account/percentage 0.33333333}
|
||||
{:transaction-rule-account/location "c"
|
||||
:transaction-rule-account/account {:account/numeric-code 123 :db/id "123"}
|
||||
:transaction-rule-account/percentage 0.333333}]}])
|
||||
:tempids)
|
||||
{:db/id "transaction-rule-id"
|
||||
:transaction-rule/note "transaction rule note"
|
||||
:transaction-rule/description "matching-desc"
|
||||
:transaction-rule/accounts [{:transaction-rule-account/location "A"
|
||||
:transaction-rule-account/account {:account/numeric-code 123 :db/id "123"}
|
||||
:transaction-rule-account/percentage 1.0}]}
|
||||
{:db/id "uneven-transaction-rule-id"
|
||||
:transaction-rule/note "transaction rule note"
|
||||
:transaction-rule/description "matching-desc"
|
||||
:transaction-rule/accounts [{:transaction-rule-account/location "A"
|
||||
:transaction-rule-account/account {:account/numeric-code 123 :db/id "123"}
|
||||
:transaction-rule-account/percentage 0.3333333}
|
||||
{:transaction-rule-account/location "B"
|
||||
:transaction-rule-account/account {:account/numeric-code 123 :db/id "123"}
|
||||
:transaction-rule-account/percentage 0.33333333}
|
||||
{:transaction-rule-account/location "c"
|
||||
:transaction-rule-account/account {:account/numeric-code 123 :db/id "123"}
|
||||
:transaction-rule-account/percentage 0.333333}]}])
|
||||
:tempids)
|
||||
rule-test (-> (sut/query (admin-token) (v/graphql-query {:venia/operation {:operation/type :mutation
|
||||
:operation/name "MatchTransactionRules"}
|
||||
:venia/queries [{:query/data (sut/->graphql [:match-transaction-rules
|
||||
{:transaction-rule-id transaction-rule-id
|
||||
:transaction-ids [transaction-id]}
|
||||
[[:matched-rule [:id :note]] [:accounts [:id]] ]])}]}))
|
||||
[[:matched-rule [:id :note]] [:accounts [:id]]]])}]}))
|
||||
:data
|
||||
:match-transaction-rules)]
|
||||
|
||||
@@ -293,7 +288,7 @@
|
||||
:venia/queries [{:query/data (sut/->graphql [:match-transaction-rules
|
||||
{:transaction-rule-id transaction-rule-id
|
||||
:transaction-ids [transaction-id]}
|
||||
[[:matched-rule [:id :note]] [:accounts [:id]] ]])}]}))
|
||||
[[:matched-rule [:id :note]] [:accounts [:id]]]])}]}))
|
||||
:data
|
||||
:match-transaction-rules)]
|
||||
(is (= 1 (-> rule-test first :accounts count)))))
|
||||
@@ -304,7 +299,7 @@
|
||||
:venia/queries [{:query/data (sut/->graphql [:match-transaction-rules
|
||||
{:transaction-rule-id uneven-transaction-rule-id
|
||||
:transaction-ids [transaction-id]}
|
||||
[[:matched-rule [:id :note]] [:accounts [:id :amount]] ]])}]}))
|
||||
[[:matched-rule [:id :note]] [:accounts [:id :amount]]]])}]}))
|
||||
:data
|
||||
:match-transaction-rules)]
|
||||
(is (= 3 (-> rule-test first :accounts count)))
|
||||
|
||||
@@ -10,206 +10,206 @@
|
||||
|
||||
#_(deftest test-account-search
|
||||
|
||||
(with-redefs [auto-ap.solr/impl (auto-ap.solr/->InMemSolrClient (atom {}))]
|
||||
(testing "It should find matching account names"
|
||||
@(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)
|
||||
(clojure.pprint/pprint auto-ap.solr/impl)
|
||||
(is (> (count (sut/search {:id (admin-token)}
|
||||
{:query "Food Research"}
|
||||
nil))
|
||||
0)))
|
||||
(testing "It should find exact matches by numbers"
|
||||
(is (= (count (sut/search {:id (admin-token)}
|
||||
{:query "51100"}
|
||||
nil))
|
||||
1)))
|
||||
(testing "It should filter out accounts that are not allowed for clients"
|
||||
@(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"}
|
||||
nil)))
|
||||
|
||||
(testing "It should show up for the client specific version"
|
||||
(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)
|
||||
(is (= 1 (count (sut/search {:id (admin-token)}
|
||||
{:query "HELLOWORLD"
|
||||
:client_id client-id}
|
||||
nil))))))
|
||||
|
||||
(testing "It should hide accounts that arent applicable"
|
||||
@(dc/transact conn [{:account/name "DENIED"
|
||||
:db/ident :denied-account
|
||||
:account/numeric-code 99998
|
||||
:account/search-terms "DENIED"
|
||||
(with-redefs [auto-ap.solr/impl (auto-ap.solr/->InMemSolrClient (atom {}))]
|
||||
(testing "It should find matching account names"
|
||||
@(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/denied
|
||||
:account/vendor-allowance :allowance/denied
|
||||
:account/invoice-allowance :allowance/denied}])
|
||||
(is (= 0 (count (sut/search {:id (admin-token)}
|
||||
{:query "DENIED"}
|
||||
nil))))
|
||||
(is (= 0 (count (sut/search {:id (admin-token)}
|
||||
{:query "DENIED"
|
||||
:allowance :invoice}
|
||||
nil))))
|
||||
(is (= 0 (count (sut/search {:id (admin-token)}
|
||||
{:query "DENIED"
|
||||
:allowance :vendor}
|
||||
nil)))))
|
||||
|
||||
(testing "It should warn when using a warn account"
|
||||
@(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}])
|
||||
:account/default-allowance :allowance/allowed}])
|
||||
(sut/rebuild-search-index)
|
||||
(is (some? (:warning (first (sut/search {:id (admin-token)}
|
||||
{:query "WARNING"
|
||||
:allowance :global}
|
||||
nil)))))
|
||||
(is (some? (:warning (first (sut/search {:id (admin-token)}
|
||||
{:query "WARNING"
|
||||
:allowance :invoice}
|
||||
nil)))))
|
||||
(is (some? (:warning (first (sut/search {:id (admin-token)}
|
||||
{:query "WARNING"
|
||||
:allowance :vendor}
|
||||
nil))))))
|
||||
(testing "It should only include admin accounts for admins"
|
||||
@(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}])
|
||||
(clojure.pprint/pprint auto-ap.solr/impl)
|
||||
(is (> (count (sut/search {:id (admin-token)}
|
||||
{:query "Food Research"}
|
||||
nil))
|
||||
0)))
|
||||
(testing "It should find exact matches by numbers"
|
||||
(is (= (count (sut/search {:id (admin-token)}
|
||||
{:query "51100"}
|
||||
nil))
|
||||
1)))
|
||||
(testing "It should filter out accounts that are not allowed for clients"
|
||||
@(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 (= 1 (count (sut/search {:id (admin-token)}
|
||||
{:query "ADMINONLY"}
|
||||
nil))))
|
||||
(is (= 0 (count (sut/search {:id (user-token)}
|
||||
{:query "ADMINONLY"}
|
||||
nil)))))
|
||||
(is (= [] (sut/search {:id (admin-token)}
|
||||
{:query "CLIENTSPECIFIC"}
|
||||
nil)))
|
||||
|
||||
(testing "It should allow searching for vendor accounts for invoices"
|
||||
(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)
|
||||
(testing "It should show up for the client specific version"
|
||||
(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)
|
||||
(is (= 1 (count (sut/search {:id (admin-token)}
|
||||
{:query "HELLOWORLD"
|
||||
:client_id client-id}
|
||||
nil))))))
|
||||
|
||||
(testing "It should hide accounts that arent applicable"
|
||||
@(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 "VENDORONLY"
|
||||
{:query "DENIED"}
|
||||
nil))))
|
||||
(is (= 0 (count (sut/search {:id (admin-token)}
|
||||
{:query "DENIED"
|
||||
:allowance :invoice}
|
||||
nil))))
|
||||
(is (= 0 (count (sut/search {:id (admin-token)}
|
||||
{:query "DENIED"
|
||||
:allowance :vendor}
|
||||
nil)))))
|
||||
|
||||
(testing "It should warn when using a warn account"
|
||||
@(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"
|
||||
:allowance :global}
|
||||
nil)))))
|
||||
(is (some? (:warning (first (sut/search {:id (admin-token)}
|
||||
{:query "WARNING"
|
||||
:allowance :invoice}
|
||||
nil)))))
|
||||
(is (some? (:warning (first (sut/search {:id (admin-token)}
|
||||
{:query "WARNING"
|
||||
:allowance :vendor}
|
||||
nil))))))
|
||||
(testing "It should only include admin accounts for admins"
|
||||
@(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 "VENDORONLY"
|
||||
:allowance :invoice
|
||||
:vendor_id vendor-id}
|
||||
nil)))))))
|
||||
{:query "ADMINONLY"}
|
||||
nil))))
|
||||
(is (= 0 (count (sut/search {:id (user-token)}
|
||||
{:query "ADMINONLY"}
|
||||
nil)))))
|
||||
|
||||
(deftest get-graphql
|
||||
(testing "should retrieve a single account"
|
||||
@(dc/transact conn [{:account/numeric-code 1
|
||||
:account/default-allowance :allowance/allowed
|
||||
:account/type :account-type/asset
|
||||
:account/location "A"
|
||||
:account/name "Test"}])
|
||||
(testing "It should allow searching for vendor accounts for invoices"
|
||||
(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)
|
||||
(is (= 0 (count (sut/search {:id (admin-token)}
|
||||
{:query "VENDORONLY"
|
||||
:allowance :invoice}
|
||||
nil))))
|
||||
|
||||
(is (= {:name "Test",
|
||||
:invoice_allowance nil,
|
||||
:numeric_code 1,
|
||||
:vendor_allowance nil,
|
||||
:location "A",
|
||||
:applicability nil}
|
||||
(dissoc (first (:accounts (sut/get-graphql {:id (admin-token)} {} nil)))
|
||||
:id
|
||||
:type
|
||||
:default_allowance)))))))
|
||||
(is (= 1 (count (sut/search {:id (admin-token)}
|
||||
{:query "VENDORONLY"
|
||||
:allowance :invoice
|
||||
:vendor_id vendor-id}
|
||||
nil)))))))
|
||||
|
||||
#_(deftest upsert-account
|
||||
(testing "should create a new account"
|
||||
(let [result (sut/upsert-account {:id (admin-token)} {:account {:client_overrides []
|
||||
:numeric_code 123
|
||||
:location "A"
|
||||
:applicability :global
|
||||
:account-set "global"
|
||||
:name "Test"
|
||||
:invoice-allowance :allowed
|
||||
:vendor-allowance :allowed
|
||||
:type :asset}} nil)]
|
||||
(is (= {:search_terms "Test",
|
||||
:name "Test",
|
||||
:invoice_allowance :allowed,
|
||||
:numeric_code 123,
|
||||
:code "123",
|
||||
:account_set "global",
|
||||
:vendor_allowance :allowed,
|
||||
:location "A",
|
||||
:applicability :global}
|
||||
(dissoc result
|
||||
:id
|
||||
:type
|
||||
:default_allowance)))
|
||||
(testing "Should allow updating account"
|
||||
(let [edit-result (sut/upsert-account {:id (admin-token)} {:account {:client_overrides []
|
||||
:id (:id result)
|
||||
:numeric_code 890
|
||||
:location "B"
|
||||
:applicability :global
|
||||
:account-set "global"
|
||||
:name "Hello"
|
||||
:invoice-allowance :denied
|
||||
:vendor-allowance :denied
|
||||
:type :expense}} nil)]
|
||||
(is (= {:search_terms "Hello",
|
||||
:name "Hello",
|
||||
:invoice_allowance :denied,
|
||||
:code "123",
|
||||
:account_set "global",
|
||||
:vendor_allowance :denied,
|
||||
:location "B",
|
||||
:applicability :global}
|
||||
(dissoc edit-result
|
||||
(deftest get-graphql
|
||||
(testing "should retrieve a single account"
|
||||
@(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,
|
||||
:numeric_code 1,
|
||||
:vendor_allowance nil,
|
||||
:location "A",
|
||||
:applicability nil}
|
||||
(dissoc (first (:accounts (sut/get-graphql {:id (admin-token)} {} nil)))
|
||||
:id
|
||||
:type
|
||||
:default_allowance
|
||||
:numeric_code)))
|
||||
(testing "Should not allow changing numeric code"
|
||||
:default_allowance)))))))
|
||||
|
||||
(is (= 123 (:numeric_code edit-result)))))))))
|
||||
#_(deftest upsert-account
|
||||
(testing "should create a new account"
|
||||
(let [result (sut/upsert-account {:id (admin-token)} {:account {:client_overrides []
|
||||
:numeric_code 123
|
||||
:location "A"
|
||||
:applicability :global
|
||||
:account-set "global"
|
||||
:name "Test"
|
||||
:invoice-allowance :allowed
|
||||
:vendor-allowance :allowed
|
||||
:type :asset}} nil)]
|
||||
(is (= {:search_terms "Test",
|
||||
:name "Test",
|
||||
:invoice_allowance :allowed,
|
||||
:numeric_code 123,
|
||||
:code "123",
|
||||
:account_set "global",
|
||||
:vendor_allowance :allowed,
|
||||
:location "A",
|
||||
:applicability :global}
|
||||
(dissoc result
|
||||
:id
|
||||
:type
|
||||
:default_allowance)))
|
||||
(testing "Should allow updating account"
|
||||
(let [edit-result (sut/upsert-account {:id (admin-token)} {:account {:client_overrides []
|
||||
:id (:id result)
|
||||
:numeric_code 890
|
||||
:location "B"
|
||||
:applicability :global
|
||||
:account-set "global"
|
||||
:name "Hello"
|
||||
:invoice-allowance :denied
|
||||
:vendor-allowance :denied
|
||||
:type :expense}} nil)]
|
||||
(is (= {:search_terms "Hello",
|
||||
:name "Hello",
|
||||
:invoice_allowance :denied,
|
||||
:code "123",
|
||||
:account_set "global",
|
||||
:vendor_allowance :denied,
|
||||
:location "B",
|
||||
:applicability :global}
|
||||
(dissoc edit-result
|
||||
:id
|
||||
:type
|
||||
:default_allowance
|
||||
:numeric_code)))
|
||||
(testing "Should not allow changing numeric code"
|
||||
|
||||
(is (= 123 (:numeric_code edit-result)))))))))
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
(use-fixtures :each wrap-setup)
|
||||
|
||||
(defn sample-payment [& kwargs]
|
||||
(apply assoc
|
||||
(apply assoc
|
||||
{:db/id "check-id"
|
||||
:payment/check-number 1000
|
||||
:payment/bank-account "bank-id"
|
||||
@@ -28,31 +28,30 @@
|
||||
:payment/date #inst "2022-01-01"}
|
||||
kwargs))
|
||||
|
||||
|
||||
(deftest get-payment-page
|
||||
(testing "Should list 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"}])]
|
||||
(is (= [ {:amount 123.5,
|
||||
:type :check,
|
||||
:bank_account {:id bank-id, :code "bank"},
|
||||
:client {:id client-id, :code "client"},
|
||||
:status :pending,
|
||||
:id check-id,
|
||||
:paid_to "Someone",
|
||||
:_payment [],
|
||||
:check_number 1000}],
|
||||
: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"},
|
||||
:client {:id client-id, :code "client"},
|
||||
:status :pending,
|
||||
:id check-id,
|
||||
:paid_to "Someone",
|
||||
:_payment [],
|
||||
:check_number 1000}],
|
||||
(map #(dissoc % :date) (:payments (first (sut/get-payment-page {:clients [{:db/id client-id}]} {} nil))))))
|
||||
(testing "Should omit clients that can't be seen"
|
||||
(is (not (seq (:payments (first (sut/get-payment-page {:clients nil} {} nil))))))
|
||||
@@ -76,47 +75,43 @@
|
||||
:payments
|
||||
seq)))
|
||||
(is (-> (sut/get-payment-page {:clients [{:db/id client-id}]} {:filters {:date_range {:end #inst "2022-01-02"}}} nil)
|
||||
first
|
||||
:payments
|
||||
seq))))
|
||||
|
||||
)
|
||||
|
||||
)
|
||||
first
|
||||
:payments
|
||||
seq))))))
|
||||
|
||||
(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"}
|
||||
(sample-payment :db/id "check-id")])]
|
||||
: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)
|
||||
(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 [{: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")])]
|
||||
: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")])]
|
||||
: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
|
||||
@@ -124,12 +119,12 @@
|
||||
|
||||
(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")])]
|
||||
: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
|
||||
@@ -137,13 +132,13 @@
|
||||
|
||||
(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")])]
|
||||
: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
|
||||
@@ -151,38 +146,37 @@
|
||||
|
||||
(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")])]
|
||||
: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}]}])]
|
||||
: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
|
||||
@@ -200,36 +194,36 @@
|
||||
: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))))))))
|
||||
: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}]}])]
|
||||
: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
|
||||
@@ -259,43 +253,43 @@
|
||||
|
||||
(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
|
||||
: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}]}])]
|
||||
: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)
|
||||
: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))))
|
||||
:payments
|
||||
first
|
||||
:amount))))
|
||||
(testing "Should create pdf"
|
||||
(is (-> paid-invoice
|
||||
:payments
|
||||
@@ -303,20 +297,19 @@
|
||||
:payment
|
||||
:s3_url))))))))
|
||||
|
||||
|
||||
(deftest get-potential-payments
|
||||
(testing "should match payments for a transaction"
|
||||
(let [{:strs [transaction-id
|
||||
payment-id
|
||||
test-client-id]} (setup-test-data [(test-payment
|
||||
:db/id "payment-id"
|
||||
:payment/status :payment-status/pending
|
||||
:payment/amount 100.0
|
||||
:payment/date #inst "2021-05-25")
|
||||
(test-transaction
|
||||
:db/id "transaction-id"
|
||||
:transaction/amount -100.0
|
||||
:transaction/date #inst "2021-06-01")])]
|
||||
:db/id "payment-id"
|
||||
:payment/status :payment-status/pending
|
||||
:payment/amount 100.0
|
||||
:payment/date #inst "2021-05-25")
|
||||
(test-transaction
|
||||
:db/id "transaction-id"
|
||||
:transaction/amount -100.0
|
||||
:transaction/date #inst "2021-06-01")])]
|
||||
(is (= [payment-id] (->> (sut/get-potential-payments {:id (admin-token) :clients [{:db/id test-client-id}]}
|
||||
{:transaction_id transaction-id}
|
||||
nil)
|
||||
@@ -325,26 +318,26 @@
|
||||
(let [{:strs [transaction-id
|
||||
older-payment-id
|
||||
newer-payment-id]} (setup-test-data [(test-payment
|
||||
:db/id "newer-payment-id"
|
||||
:payment/status :payment-status/pending
|
||||
:payment/amount 100.0
|
||||
:payment/date #inst "2021-05-25")
|
||||
(test-payment
|
||||
:db/id "older-payment-id"
|
||||
:payment/status :payment-status/pending
|
||||
:payment/amount 100.0
|
||||
:payment/date #inst "2021-05-20")
|
||||
(test-payment
|
||||
:db/id "payment-too-old-id"
|
||||
:payment/status :payment-status/pending
|
||||
:payment/amount 100.0
|
||||
:payment/date #inst "2021-01-01")
|
||||
(test-transaction
|
||||
:db/id "transaction-id"
|
||||
:transaction/amount -100.0
|
||||
:transaction/date #inst "2021-06-01")])]
|
||||
:db/id "newer-payment-id"
|
||||
:payment/status :payment-status/pending
|
||||
:payment/amount 100.0
|
||||
:payment/date #inst "2021-05-25")
|
||||
(test-payment
|
||||
:db/id "older-payment-id"
|
||||
:payment/status :payment-status/pending
|
||||
:payment/amount 100.0
|
||||
:payment/date #inst "2021-05-20")
|
||||
(test-payment
|
||||
:db/id "payment-too-old-id"
|
||||
:payment/status :payment-status/pending
|
||||
:payment/amount 100.0
|
||||
:payment/date #inst "2021-01-01")
|
||||
(test-transaction
|
||||
:db/id "transaction-id"
|
||||
:transaction/amount -100.0
|
||||
:transaction/date #inst "2021-06-01")])]
|
||||
(is (= [newer-payment-id
|
||||
older-payment-id] (->> (sut/get-potential-payments {:id (admin-token)}
|
||||
{:transaction_id transaction-id}
|
||||
nil)
|
||||
(map :id)))))))
|
||||
{:transaction_id transaction-id}
|
||||
nil)
|
||||
(map :id)))))))
|
||||
|
||||
@@ -77,7 +77,7 @@
|
||||
:expense_accounts [{:amount 100.0
|
||||
:location "DT"
|
||||
:account_id new-account-id}]}}
|
||||
nil)))
|
||||
nil)))
|
||||
(is (= #:invoice{:invoice-number "890213"
|
||||
:date #inst "2023-01-01T00:00:00.000-00:00"
|
||||
:total 100.0
|
||||
@@ -118,11 +118,11 @@
|
||||
(setup-test-data [(test-invoice :db/id "invoice-id")
|
||||
(test-account :db/id "new-account-id")])]
|
||||
(is (some? (sut/edit-expense-accounts {:id (admin-token)}
|
||||
{:invoice_id invoice-id
|
||||
:expense_accounts [{:amount 100.0
|
||||
:account_id new-account-id
|
||||
:location "DT"}]}
|
||||
nil)))
|
||||
{:invoice_id invoice-id
|
||||
:expense_accounts [{:amount 100.0
|
||||
:account_id new-account-id
|
||||
:location "DT"}]}
|
||||
nil)))
|
||||
(is (= [#:invoice-expense-account{:amount 100.0
|
||||
:location "DT"
|
||||
:account {:db/id new-account-id}}]
|
||||
@@ -145,7 +145,7 @@
|
||||
:accounts [{:percentage 1.0
|
||||
:account_id new-account-id
|
||||
:location "Shared"}]}
|
||||
nil)))
|
||||
nil)))
|
||||
(is (= [#:invoice-expense-account{:amount 100.0
|
||||
:location "DT"
|
||||
:account {:db/id new-account-id}}]
|
||||
@@ -163,35 +163,7 @@
|
||||
(test-account :db/id "new-account-id")])]
|
||||
|
||||
(is (some? (sut/void-invoices {:id (admin-token) :clients [{:db/id test-client-id}]}
|
||||
{:filters {:client_id test-client-id}}
|
||||
nil)))
|
||||
(is (= :invoice-status/voided
|
||||
(-> (d/pull (d/db conn) [{:invoice/status [:db/ident]}]
|
||||
invoice-id)
|
||||
:invoice/status
|
||||
:db/ident)))
|
||||
|
||||
(testing "Should unvoid invoice"
|
||||
(is (some? (sut/unvoid-invoice {:id (admin-token)}
|
||||
{:invoice_id invoice-id}
|
||||
nil)))
|
||||
(is (= :invoice-status/unpaid
|
||||
(-> (d/pull (d/db conn) [{:invoice/status [:db/ident]}]
|
||||
invoice-id)
|
||||
:invoice/status
|
||||
:db/ident)))))))
|
||||
|
||||
|
||||
(deftest void-invoice
|
||||
(testing "It should voide invoices in bulk"
|
||||
(let [{:strs [invoice-id]}
|
||||
(setup-test-data [(test-invoice :db/id "invoice-id"
|
||||
:invoice/status :invoice-status/unpaid)
|
||||
(test-account :db/id "new-account-id")])]
|
||||
|
||||
|
||||
(is (some? (sut/void-invoice {:id (admin-token)}
|
||||
{:invoice_id invoice-id}
|
||||
{:filters {:client_id test-client-id}}
|
||||
nil)))
|
||||
(is (= :invoice-status/voided
|
||||
(-> (d/pull (d/db conn) [{:invoice/status [:db/ident]}]
|
||||
@@ -201,8 +173,34 @@
|
||||
|
||||
(testing "Should unvoid invoice"
|
||||
(is (some? (sut/unvoid-invoice {:id (admin-token)}
|
||||
{:invoice_id invoice-id}
|
||||
nil)))
|
||||
{:invoice_id invoice-id}
|
||||
nil)))
|
||||
(is (= :invoice-status/unpaid
|
||||
(-> (d/pull (d/db conn) [{:invoice/status [:db/ident]}]
|
||||
invoice-id)
|
||||
:invoice/status
|
||||
:db/ident)))))))
|
||||
|
||||
(deftest void-invoice
|
||||
(testing "It should voide invoices in bulk"
|
||||
(let [{:strs [invoice-id]}
|
||||
(setup-test-data [(test-invoice :db/id "invoice-id"
|
||||
:invoice/status :invoice-status/unpaid)
|
||||
(test-account :db/id "new-account-id")])]
|
||||
|
||||
(is (some? (sut/void-invoice {:id (admin-token)}
|
||||
{:invoice_id invoice-id}
|
||||
nil)))
|
||||
(is (= :invoice-status/voided
|
||||
(-> (d/pull (d/db conn) [{:invoice/status [:db/ident]}]
|
||||
invoice-id)
|
||||
:invoice/status
|
||||
:db/ident)))
|
||||
|
||||
(testing "Should unvoid invoice"
|
||||
(is (some? (sut/unvoid-invoice {:id (admin-token)}
|
||||
{:invoice_id invoice-id}
|
||||
nil)))
|
||||
(is (= :invoice-status/unpaid
|
||||
(-> (d/pull (d/db conn) [{:invoice/status [:db/ident]}]
|
||||
invoice-id)
|
||||
|
||||
@@ -23,11 +23,11 @@
|
||||
line-2-2
|
||||
line-3-1
|
||||
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"}
|
||||
: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"
|
||||
@@ -66,19 +66,18 @@
|
||||
:journal-entry-line/credit 150.0}]}]]))]
|
||||
|
||||
(testing "should set running-balance on ledger entries missing them"
|
||||
|
||||
|
||||
(sut/upsert-running-balance)
|
||||
(println (d/pull (d/db conn) '[*] line-1-1))
|
||||
|
||||
(is (= [-10.0 -60.0 -210.0]
|
||||
(map #(pull-attr (d/db conn) :journal-entry-line/running-balance %) [line-1-1 line-2-1 line-3-1
|
||||
])))
|
||||
(map #(pull-attr (d/db conn) :journal-entry-line/running-balance %) [line-1-1 line-2-1 line-3-1])))
|
||||
(is (= [10.0 60.0 210.0]
|
||||
(map #(pull-attr (d/db conn) :journal-entry-line/running-balance %) [line-1-2 line-2-2 line-3-2]))))
|
||||
|
||||
(testing "should recompute if the data is out of date"
|
||||
|
||||
(d/transact conn
|
||||
(d/transact conn
|
||||
[{:db/id line-1-1
|
||||
:journal-entry-line/dirty true
|
||||
:journal-entry-line/running-balance 123810.23}])
|
||||
@@ -89,7 +88,7 @@
|
||||
|
||||
(testing "should recompute every entry after the out of date one"
|
||||
|
||||
(d/transact conn
|
||||
(d/transact conn
|
||||
[{:db/id line-1-1
|
||||
:journal-entry-line/dirty true
|
||||
:journal-entry-line/debit 70.0}])
|
||||
@@ -98,40 +97,39 @@
|
||||
(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
|
||||
(d/transact conn
|
||||
[{:db/id line-1-1
|
||||
:journal-entry-line/dirty false
|
||||
:journal-entry-line/debit 90.0}])
|
||||
(sut/upsert-running-balance)
|
||||
(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])))
|
||||
(map #(pull-attr (d/db conn) :journal-entry-line/running-balance %) [line-1-1 line-2-1 line-3-1]))))
|
||||
|
||||
)
|
||||
(testing "changing a ledger entry should mark the line items as dirty"
|
||||
(println "AFTER HERE")
|
||||
@(d/transact conn
|
||||
[[: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}]}]])
|
||||
@(d/transact conn
|
||||
[[: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)
|
||||
(map :journal-entry-line/dirty))))
|
||||
(testing "should also mark the next entry as dirty, so that if a ledger entry is changed, the old accounts get updated"
|
||||
(is (= [false false]
|
||||
(->> (d/pull (d/db conn) '[{:journal-entry/line-items [:journal-entry-line/dirty]}] journal-entry-1)
|
||||
(:journal-entry/line-items)
|
||||
(map :journal-entry-line/dirty))))
|
||||
(is (= [true true]
|
||||
(->> (d/pull (d/db conn) '[{:journal-entry/line-items [:journal-entry-line/dirty]}] journal-entry-2)
|
||||
(:journal-entry/line-items)
|
||||
(map :journal-entry-line/dirty))))
|
||||
(testing "should also mark the next entry as dirty, so that if a ledger entry is changed, the old accounts get updated"
|
||||
(is (= [false false]
|
||||
(->> (d/pull (d/db conn) '[{:journal-entry/line-items [:journal-entry-line/dirty]}] journal-entry-1)
|
||||
(:journal-entry/line-items)
|
||||
(map :journal-entry-line/dirty))))
|
||||
(is (= [true true]
|
||||
(->> (d/pull (d/db conn) '[{:journal-entry/line-items [:journal-entry-line/dirty]}] journal-entry-2)
|
||||
(:journal-entry/line-items)
|
||||
(map :journal-entry-line/dirty))))))))
|
||||
(map :journal-entry-line/dirty))))))))
|
||||
|
||||
@@ -11,11 +11,11 @@
|
||||
(testing "Should find a single rule that matches a transaction"
|
||||
(let [{:strs [transaction-id
|
||||
transaction-rule-id]} (setup-test-data [(test-transaction
|
||||
:db/id "transaction-id"
|
||||
:transaction/description-original "Disneyland")
|
||||
:db/id "transaction-id"
|
||||
:transaction/description-original "Disneyland")
|
||||
(test-transaction-rule
|
||||
:db/id "transaction-rule-id"
|
||||
:transaction-rule/description ".*")])]
|
||||
:db/id "transaction-rule-id"
|
||||
:transaction-rule/description ".*")])]
|
||||
(is (= [transaction-rule-id] (->> (sut2/get-transaction-rule-matches {:id (admin-token)}
|
||||
{:transaction_id transaction-id}
|
||||
nil)
|
||||
|
||||
@@ -22,8 +22,8 @@
|
||||
(testing "Should list transactions"
|
||||
(let [{:strs [transaction-id
|
||||
test-client-id]} (setup-test-data [(test-transaction :db/id "transaction-id"
|
||||
:transaction/client "test-client-id"
|
||||
:transaction/bank-account "test-bank-account-id")])]
|
||||
:transaction/client "test-client-id"
|
||||
:transaction/bank-account "test-bank-account-id")])]
|
||||
(is (= 1 (:total (sut/get-transaction-page {:id (admin-token)} {} nil))))
|
||||
(is (= transaction-id (:id (first (:data (sut/get-transaction-page {:id (admin-token)} {} nil))))))
|
||||
(testing "Should only show transactions you have access to"
|
||||
@@ -39,18 +39,17 @@
|
||||
(testing "Should only show potential duplicates if filtered enough"
|
||||
(is (thrown? Exception (:total (sut/get-transaction-page {:id (admin-token)} {:filters {:potential_duplicates true}} nil))))))))
|
||||
|
||||
|
||||
(deftest bulk-change-status
|
||||
(testing "Should change status of multiple transactions"
|
||||
(let [{:strs [transaction-id
|
||||
test-client-id]} (setup-test-data [(test-transaction :db/id "transaction-id"
|
||||
:transaction/client "test-client-id"
|
||||
:transaction/approval-status :transaction-approval-status/approved
|
||||
:transaction/bank-account "test-bank-account-id")])]
|
||||
:transaction/client "test-client-id"
|
||||
:transaction/approval-status :transaction-approval-status/approved
|
||||
:transaction/bank-account "test-bank-account-id")])]
|
||||
(is (= "Succesfully changed 1 transactions to be unapproved."
|
||||
(:message (sut/bulk-change-status {:id (admin-token)
|
||||
:clients [{:db/id test-client-id}]} {:filters {}
|
||||
:status :unapproved} nil))))
|
||||
:status :unapproved} nil))))
|
||||
(is (= :transaction-approval-status/unapproved
|
||||
(:db/ident (:transaction/approval-status (dc/pull (dc/db conn) '[{:transaction/approval-status [:db/ident]}] transaction-id)))))
|
||||
|
||||
@@ -65,9 +64,9 @@
|
||||
test-client-id
|
||||
test-account-id
|
||||
test-vendor-id]} (setup-test-data [(test-transaction :db/id "transaction-id"
|
||||
:transaction/client "test-client-id"
|
||||
:transaction/bank-account "test-bank-account-id"
|
||||
:transaction/amount 40.0)])]
|
||||
:transaction/client "test-client-id"
|
||||
:transaction/bank-account "test-bank-account-id"
|
||||
:transaction/amount 40.0)])]
|
||||
(is (= "Successfully coded 1 transactions."
|
||||
(:message (sut/bulk-code-transactions {:id (admin-token)
|
||||
:clients [{:db/id test-client-id}]}
|
||||
@@ -94,18 +93,17 @@
|
||||
(let [{:strs [transaction-id-1
|
||||
transaction-id-2
|
||||
test-client-id-2
|
||||
test-client-id]} (setup-test-data [
|
||||
(test-transaction :db/id "transaction-id-1"
|
||||
:transaction/client "test-client-id"
|
||||
:transaction/bank-account "test-bank-account-id"
|
||||
:transaction/amount 40.0)
|
||||
(test-transaction :db/id "transaction-id-2"
|
||||
:transaction/client "test-client-id-2"
|
||||
:transaction/bank-account "test-bank-account-id-2"
|
||||
:transaction/amount 40.0)
|
||||
(test-client :db/id "test-client-id-2"
|
||||
:client/locations ["GR"])
|
||||
(test-bank-account :db/id "test-bank-account-id-2")])]
|
||||
test-client-id]} (setup-test-data [(test-transaction :db/id "transaction-id-1"
|
||||
:transaction/client "test-client-id"
|
||||
:transaction/bank-account "test-bank-account-id"
|
||||
:transaction/amount 40.0)
|
||||
(test-transaction :db/id "transaction-id-2"
|
||||
:transaction/client "test-client-id-2"
|
||||
:transaction/bank-account "test-bank-account-id-2"
|
||||
:transaction/amount 40.0)
|
||||
(test-client :db/id "test-client-id-2"
|
||||
:client/locations ["GR"])
|
||||
(test-bank-account :db/id "test-bank-account-id-2")])]
|
||||
(is (= "Successfully coded 2 transactions."
|
||||
(:message (sut/bulk-code-transactions {:id (admin-token)
|
||||
:clients [{:db/id test-client-id}
|
||||
@@ -116,7 +114,7 @@
|
||||
:accounts [{:account_id test-account-id
|
||||
:location "Shared"
|
||||
:percentage 1.0}]} nil))))
|
||||
|
||||
|
||||
(is (= #:transaction{:vendor {:db/id test-vendor-id}
|
||||
:approval-status {:db/ident :transaction-approval-status/unapproved}
|
||||
:accounts [#:transaction-account{:account {:db/id test-account-id}
|
||||
@@ -143,8 +141,7 @@
|
||||
|
||||
(testing "should reject a location that doesnt exist"
|
||||
(let [{:strs [test-client-id-1
|
||||
test-client-id-2]} (setup-test-data [
|
||||
(test-transaction :db/id "transaction-id-1"
|
||||
test-client-id-2]} (setup-test-data [(test-transaction :db/id "transaction-id-1"
|
||||
:transaction/client "test-client-id-1"
|
||||
:transaction/bank-account "test-bank-account-id"
|
||||
:transaction/amount 40.0)
|
||||
@@ -158,14 +155,14 @@
|
||||
:client/locations ["GR" "BOTH"])
|
||||
(test-bank-account :db/id "test-bank-account-id-2")])]
|
||||
(is (thrown? Exception (sut/bulk-code-transactions {:id (admin-token)
|
||||
:clients [{:db/id test-client-id}
|
||||
{:db/id test-client-id-2}]}
|
||||
{:filters {}
|
||||
:vendor test-vendor-id
|
||||
:approval_status :unapproved
|
||||
:accounts [{:account_id test-account-id
|
||||
:location "OG"
|
||||
:percentage 1.0}]} nil)))
|
||||
:clients [{:db/id test-client-id}
|
||||
{:db/id test-client-id-2}]}
|
||||
{:filters {}
|
||||
:vendor test-vendor-id
|
||||
:approval_status :unapproved
|
||||
:accounts [{:account_id test-account-id
|
||||
:location "OG"
|
||||
:percentage 1.0}]} nil)))
|
||||
(is (thrown? Exception (sut/bulk-code-transactions {:id (admin-token)
|
||||
:clients [{:db/id test-client-id}
|
||||
{:db/id test-client-id-2}]}
|
||||
@@ -223,7 +220,6 @@
|
||||
:location "DT"
|
||||
:amount 20.0}]}} nil)))))))
|
||||
|
||||
|
||||
(deftest match-transaction
|
||||
(testing "Should link a transaction to a payment, mark it as accounts payable"
|
||||
(let [{:strs [transaction-id
|
||||
@@ -275,36 +271,33 @@
|
||||
:payment/bank-account "mismatched-bank-account-id"
|
||||
:payment/amount 50.0)])]
|
||||
(is (thrown? Exception (sut/match-transaction {:id (admin-token)} {:transaction_id transaction-id :payment_id mismatched-amount-payment-id} nil)))
|
||||
(is (thrown? Exception (sut/match-transaction {:id (admin-token)} {:transaction_id transaction-id :payment_id mismatched-bank-account-payment-id} nil)))
|
||||
)))
|
||||
(is (thrown? Exception (sut/match-transaction {:id (admin-token)} {:transaction_id transaction-id :payment_id mismatched-bank-account-payment-id} nil))))))
|
||||
|
||||
(deftest match-transaction-autopay-invoices
|
||||
(testing "Should link transaction to a set of autopaid invoices"
|
||||
(let [{:strs [transaction-id
|
||||
test-vendor-id
|
||||
invoice-1
|
||||
invoice-2
|
||||
]} (setup-test-data [(test-transaction :db/id "transaction-id"
|
||||
:transaction/amount -50.0)
|
||||
(test-invoice :db/id "invoice-1"
|
||||
:invoice/total 30.0)
|
||||
(test-invoice :db/id "invoice-2"
|
||||
:invoice/total 20.0)])]
|
||||
invoice-2]} (setup-test-data [(test-transaction :db/id "transaction-id"
|
||||
:transaction/amount -50.0)
|
||||
(test-invoice :db/id "invoice-1"
|
||||
:invoice/total 30.0)
|
||||
(test-invoice :db/id "invoice-2"
|
||||
:invoice/total 20.0)])]
|
||||
(sut/match-transaction-autopay-invoices {:id (admin-token)} {:transaction_id transaction-id :autopay_invoice_ids [invoice-1 invoice-2]} nil)
|
||||
(let [result (dc/pull (dc/db conn) '[:transaction/vendor
|
||||
{:transaction/payment [:db/id {:payment/status [:db/ident]}]}
|
||||
{:transaction/approval-status [:db/ident]
|
||||
:transaction/accounts [:transaction-account/account
|
||||
:transaction-account/location
|
||||
:transaction-account/amount]}
|
||||
]
|
||||
:transaction-account/amount]}]
|
||||
transaction-id)]
|
||||
(testing "should have created a payment"
|
||||
(is (some? (:transaction/payment result)))
|
||||
(is (= :payment-status/cleared (-> result
|
||||
:transaction/payment
|
||||
:payment/status
|
||||
:db/ident)))
|
||||
:transaction/payment
|
||||
:payment/status
|
||||
:db/ident)))
|
||||
(is (= :transaction-approval-status/approved (-> result :transaction/approval-status :db/ident))))
|
||||
(testing "Should have completed the invoice"
|
||||
(is (= :invoice-status/paid (->> invoice-1
|
||||
@@ -320,11 +313,10 @@
|
||||
(let [{:strs [transaction-id
|
||||
test-vendor-id
|
||||
invoice-1
|
||||
invoice-2
|
||||
]} (setup-test-data [(test-transaction :db/id "transaction-id"
|
||||
:transaction/amount -50.0)
|
||||
(test-invoice :db/id "invoice-1"
|
||||
:invoice/total 30.0)])]
|
||||
invoice-2]} (setup-test-data [(test-transaction :db/id "transaction-id"
|
||||
:transaction/amount -50.0)
|
||||
(test-invoice :db/id "invoice-1"
|
||||
:invoice/total 30.0)])]
|
||||
(is (thrown? Exception (sut/match-transaction-autopay-invoices {:id (admin-token)} {:transaction_id transaction-id :autopay_invoice_ids [invoice-1 invoice-2]} nil))))))
|
||||
|
||||
(deftest match-transaction-unpaid-invoices
|
||||
@@ -332,30 +324,28 @@
|
||||
(let [{:strs [transaction-id
|
||||
test-vendor-id
|
||||
invoice-1
|
||||
invoice-2
|
||||
]} (setup-test-data [(test-transaction :db/id "transaction-id"
|
||||
:transaction/amount -50.0)
|
||||
(test-invoice :db/id "invoice-1"
|
||||
:invoice/outstanding-balance 30.0 ;; TODO this part is a little different
|
||||
:invoice/total 30.0)
|
||||
(test-invoice :db/id "invoice-2"
|
||||
:invoice/outstanding-balance 20.0 ;; TODO this part is a little different
|
||||
:invoice/total 20.0)])]
|
||||
invoice-2]} (setup-test-data [(test-transaction :db/id "transaction-id"
|
||||
:transaction/amount -50.0)
|
||||
(test-invoice :db/id "invoice-1"
|
||||
:invoice/outstanding-balance 30.0 ;; TODO this part is a little different
|
||||
:invoice/total 30.0)
|
||||
(test-invoice :db/id "invoice-2"
|
||||
:invoice/outstanding-balance 20.0 ;; TODO this part is a little different
|
||||
:invoice/total 20.0)])]
|
||||
(sut/match-transaction-unpaid-invoices {:id (admin-token)} {:transaction_id transaction-id :unpaid_invoice_ids [invoice-1 invoice-2]} nil)
|
||||
(let [result (dc/pull (dc/db conn) '[:transaction/vendor
|
||||
{:transaction/payment [:db/id {:payment/status [:db/ident]}]}
|
||||
{:transaction/approval-status [:db/ident]
|
||||
:transaction/accounts [:transaction-account/account
|
||||
:transaction-account/location
|
||||
:transaction-account/amount]}
|
||||
]
|
||||
:transaction-account/amount]}]
|
||||
transaction-id)]
|
||||
(testing "should have created a payment"
|
||||
(is (some? (:transaction/payment result)))
|
||||
(is (= :payment-status/cleared (-> result
|
||||
:transaction/payment
|
||||
:payment/status
|
||||
:db/ident)))
|
||||
:transaction/payment
|
||||
:payment/status
|
||||
:db/ident)))
|
||||
(is (= :transaction-approval-status/approved (-> result :transaction/approval-status :db/ident))))
|
||||
(testing "Should have completed the invoice"
|
||||
(is (= :invoice-status/paid (->> invoice-1
|
||||
@@ -371,29 +361,25 @@
|
||||
(let [{:strs [transaction-id
|
||||
test-vendor-id
|
||||
invoice-1
|
||||
invoice-2
|
||||
]} (setup-test-data [(test-transaction :db/id "transaction-id"
|
||||
:transaction/amount -50.0)
|
||||
(test-invoice :db/id "invoice-1"
|
||||
:invoice/total 30.0)])]
|
||||
invoice-2]} (setup-test-data [(test-transaction :db/id "transaction-id"
|
||||
:transaction/amount -50.0)
|
||||
(test-invoice :db/id "invoice-1"
|
||||
:invoice/total 30.0)])]
|
||||
(is (thrown? Exception (sut/match-transaction-autopay-invoices {:id (admin-token)} {:transaction_id transaction-id :autopay_invoice_ids [invoice-1 invoice-2]} nil))))))
|
||||
|
||||
|
||||
(deftest match-transaction-rules
|
||||
(testing "Should match transactions without linked payments"
|
||||
(let [{:strs [transaction-id
|
||||
transaction-rule-id
|
||||
]} (setup-test-data [(test-transaction :db/id "transaction-id"
|
||||
:transaction/amount -50.0)
|
||||
(test-transaction-rule :db/id "transaction-rule-id"
|
||||
:transaction-rule/client "test-client-id"
|
||||
:transaction-rule/transaction-approval-status :transaction-approval-status/excluded
|
||||
:transaction-rule/description ".*"
|
||||
)])]
|
||||
transaction-rule-id]} (setup-test-data [(test-transaction :db/id "transaction-id"
|
||||
:transaction/amount -50.0)
|
||||
(test-transaction-rule :db/id "transaction-rule-id"
|
||||
:transaction-rule/client "test-client-id"
|
||||
:transaction-rule/transaction-approval-status :transaction-approval-status/excluded
|
||||
:transaction-rule/description ".*")])]
|
||||
(is (= transaction-rule-id (-> (sut/match-transaction-rules {:id (admin-token)} {:transaction_ids [transaction-id] :transaction_rule_id transaction-rule-id} nil)
|
||||
first
|
||||
:matched_rule
|
||||
:id)))
|
||||
first
|
||||
:matched_rule
|
||||
:id)))
|
||||
|
||||
(testing "Should apply statuses"
|
||||
(is (= :excluded
|
||||
@@ -401,8 +387,7 @@
|
||||
{:transaction_ids [transaction-id] :transaction_rule_id transaction-rule-id}
|
||||
nil)
|
||||
first
|
||||
:approval_status
|
||||
))))))
|
||||
:approval_status))))))
|
||||
|
||||
(testing "Should not apply to transactions if they don't match"
|
||||
(let [{:strs [transaction-id
|
||||
@@ -410,12 +395,11 @@
|
||||
(setup-test-data [(test-transaction :db/id "transaction-id"
|
||||
:transaction/amount -50.0)
|
||||
(test-transaction-rule :db/id "transaction-rule-id"
|
||||
:transaction-rule/description "NOMATCH"
|
||||
)])]
|
||||
:transaction-rule/description "NOMATCH")])]
|
||||
(is (thrown? Exception (-> (sut/match-transaction-rules {:id (admin-token)} {:transaction_ids [transaction-id] :transaction_rule_id transaction-rule-id} nil)
|
||||
first
|
||||
:matched_rule
|
||||
:id)))))
|
||||
first
|
||||
:matched_rule
|
||||
:id)))))
|
||||
(testing "Should not apply to transactions if they are already matched"
|
||||
(let [{:strs [transaction-id
|
||||
transaction-rule-id]}
|
||||
@@ -424,8 +408,7 @@
|
||||
:transaction/payment {:db/id "extant-payment-id"}
|
||||
:transaction/amount -50.0)
|
||||
(test-transaction-rule :db/id "transaction-rule-id"
|
||||
:transaction-rule/description ".*"
|
||||
)])]
|
||||
:transaction-rule/description ".*")])]
|
||||
(is (thrown? Exception (-> (sut/match-transaction-rules {:id (admin-token)} {:transaction_ids [transaction-id] :transaction_rule_id transaction-rule-id} nil)
|
||||
first
|
||||
:matched_rule
|
||||
@@ -438,8 +421,7 @@
|
||||
:transaction/description-original "MATCH"
|
||||
:transaction/amount -50.0)
|
||||
(test-transaction-rule :db/id "transaction-rule-id"
|
||||
:transaction-rule/description ".*"
|
||||
)])]
|
||||
:transaction-rule/description ".*")])]
|
||||
(sut/match-transaction-rules {:id (admin-token)} {:all true
|
||||
:transaction_rule_id transaction-rule-id} nil)
|
||||
(= {:transaction/matched-rule {:db/id transaction-rule-id}}
|
||||
|
||||
@@ -9,27 +9,25 @@
|
||||
|
||||
(use-fixtures :each wrap-setup)
|
||||
|
||||
|
||||
#_(deftest edit-user
|
||||
(testing "should allow editing a user"
|
||||
|
||||
(testing "should allow editing a user"
|
||||
|
||||
(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 [{: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)]
|
||||
(is (= client-id (get-in result [:clients 0 :id])))))
|
||||
(testing "Should allow adding clients"
|
||||
(let [result (sut/edit-user {:id (admin-token)} {:edit_user {:role :power_user
|
||||
:id user-id
|
||||
:clients []}} nil)]
|
||||
(is (not (seq (:clients result))))))
|
||||
(testing "Should disallow normies"
|
||||
(is (thrown? Exception (sut/edit-user {:id (user-token)} {:edit_user {:role :power_user
|
||||
:id user-id
|
||||
:clients []}} nil)))))))
|
||||
(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 [{: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)]
|
||||
(is (= client-id (get-in result [:clients 0 :id])))))
|
||||
(testing "Should allow adding clients"
|
||||
(let [result (sut/edit-user {:id (admin-token)} {:edit_user {:role :power_user
|
||||
:id user-id
|
||||
:clients []}} nil)]
|
||||
(is (not (seq (:clients result))))))
|
||||
(testing "Should disallow normies"
|
||||
(is (thrown? Exception (sut/edit-user {:id (user-token)} {:edit_user {:role :power_user
|
||||
:id user-id
|
||||
:clients []}} nil)))))))
|
||||
|
||||
@@ -3,16 +3,14 @@
|
||||
[auto-ap.integration.util :refer [wrap-setup admin-token setup-test-data test-vendor test-account dissoc-id]]
|
||||
[clojure.test :as t :refer [deftest is testing use-fixtures]]))
|
||||
|
||||
|
||||
(use-fixtures :each wrap-setup)
|
||||
|
||||
|
||||
(deftest vendors
|
||||
(testing "vendors"
|
||||
(let [{:strs [test-vendor-id]} (setup-test-data [])]
|
||||
(testing "it should find vendors"
|
||||
(let [result (sut2/get-graphql {:id (admin-token)} {} {})]
|
||||
(is ((into #{} (map :id (:vendors result))) test-vendor-id )))))))
|
||||
(is ((into #{} (map :id (:vendors result))) test-vendor-id)))))))
|
||||
|
||||
(deftest upsert-vendor
|
||||
(testing "Should allow upsert of an extant vendor"
|
||||
@@ -38,9 +36,9 @@
|
||||
:schedule_payment_dom [{:client_id test-client-id
|
||||
:dom 12}]
|
||||
:terms_overrides [{:client_id test-client-id
|
||||
:terms 100}]
|
||||
:terms 100}]
|
||||
:account_overrides [{:client_id test-client-id
|
||||
:account_id test-account-id-2}]
|
||||
:account_id test-account-id-2}]
|
||||
:automatically_paid_when_due [test-client-id]}}
|
||||
nil)]
|
||||
(is (= {:address {:street1 "1900 Penn ave",
|
||||
@@ -52,7 +50,7 @@
|
||||
:search_terms ["New Vendor Name!"],
|
||||
:terms 30,
|
||||
:name "New Vendor Name!",
|
||||
:secondary_contact { :name "Ben"},
|
||||
:secondary_contact {:name "Ben"},
|
||||
:usage nil,
|
||||
:hidden true,
|
||||
:id test-vendor-id,
|
||||
@@ -72,7 +70,6 @@
|
||||
(update :schedule_payment_dom #(map dissoc-id %))
|
||||
(update :terms_overrides #(map dissoc-id %))
|
||||
(update :account_overrides #(map dissoc-id %)))))
|
||||
(is (= 1 (count (:automatically_paid_when_due result))))
|
||||
))))
|
||||
(is (= 1 (count (:automatically_paid_when_due result))))))))
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
[clojure.test :as t :refer [deftest is testing use-fixtures]]
|
||||
[clojure.java.io :as io]))
|
||||
|
||||
|
||||
(use-fixtures :each wrap-setup)
|
||||
|
||||
(deftest extract-invoice-details-cintas
|
||||
@@ -14,23 +13,22 @@
|
||||
:client/locations ["OP"]
|
||||
:client/matches ["2034 BROADWAY ST"]}]
|
||||
(is (=
|
||||
[{:invoice/invoice-number "1500000592"
|
||||
:invoice/date #inst "2023-03-09T08:00:00-00:00"
|
||||
:invoice/due #inst "2023-04-08T07:00:00-00:00"
|
||||
:invoice/import-status :import-status/imported
|
||||
:invoice/client-identifier "2034 BROADWAY ST"
|
||||
:invoice/location "OP"
|
||||
:invoice/status :invoice-status/unpaid
|
||||
:invoice/vendor :vendor/cintas
|
||||
:invoice/scheduled-payment #inst "2023-04-08T07:00:00-00:00"
|
||||
:invoice/client 1
|
||||
:invoice/total 39.88
|
||||
:invoice/outstanding-balance 39.88
|
||||
}]
|
||||
(map #(dissoc % :invoice/expense-accounts :db/id)
|
||||
(sut/extract-invoice-details "ntg-invoices/Cintas/123.zcic"
|
||||
(io/input-stream (io/resource "test-cintas/o.zcic.230310093903"))
|
||||
[client]))))))
|
||||
[{:invoice/invoice-number "1500000592"
|
||||
:invoice/date #inst "2023-03-09T08:00:00-00:00"
|
||||
:invoice/due #inst "2023-04-08T07:00:00-00:00"
|
||||
:invoice/import-status :import-status/imported
|
||||
:invoice/client-identifier "2034 BROADWAY ST"
|
||||
:invoice/location "OP"
|
||||
:invoice/status :invoice-status/unpaid
|
||||
:invoice/vendor :vendor/cintas
|
||||
:invoice/scheduled-payment #inst "2023-04-08T07:00:00-00:00"
|
||||
:invoice/client 1
|
||||
:invoice/total 39.88
|
||||
:invoice/outstanding-balance 39.88}]
|
||||
(map #(dissoc % :invoice/expense-accounts :db/id)
|
||||
(sut/extract-invoice-details "ntg-invoices/Cintas/123.zcic"
|
||||
(io/input-stream (io/resource "test-cintas/o.zcic.230310093903"))
|
||||
[client]))))))
|
||||
|
||||
(testing "Should disable automatic payment based on feature flag"
|
||||
(let [client {:db/id 1
|
||||
@@ -50,8 +48,8 @@
|
||||
:client/locations ["OP"]
|
||||
:client/matches ["123 time square"]}]
|
||||
(is (=
|
||||
[]
|
||||
(sut/extract-invoice-details "ntg-invoices/Cintas/123"
|
||||
(io/input-stream (io/resource "test-cintas/o.zcic.230310093903"))
|
||||
[client]))))))
|
||||
[]
|
||||
(sut/extract-invoice-details "ntg-invoices/Cintas/123"
|
||||
(io/input-stream (io/resource "test-cintas/o.zcic.230310093903"))
|
||||
[client]))))))
|
||||
|
||||
|
||||
@@ -24,12 +24,12 @@
|
||||
:account/name "Food"})
|
||||
|
||||
(defn invoice-count-for-client [c]
|
||||
(or
|
||||
(first (first (dc/q '[:find (count ?i)
|
||||
(or
|
||||
(first (first (dc/q '[:find (count ?i)
|
||||
:in $ ?c
|
||||
:where [?i :invoice/client ?c]]
|
||||
(dc/db conn) c)))
|
||||
0))
|
||||
0))
|
||||
|
||||
(def invoice {:customer-identifier "ABC"
|
||||
:date (coerce/to-date-time #inst "2021-01-01")
|
||||
@@ -49,11 +49,10 @@
|
||||
|
||||
(t/testing "Should only import the same invoice once"
|
||||
(t/is (thrown? Exception (sut/import-uploaded-invoice user [(assoc invoice :customer-identifier "ABC")])))
|
||||
|
||||
|
||||
|
||||
(t/is (thrown? Exception (sut/import-uploaded-invoice user [(assoc invoice
|
||||
:customer-identifier "ABC"
|
||||
:total "456.32")]))))
|
||||
:customer-identifier "ABC"
|
||||
:total "456.32")]))))
|
||||
|
||||
(t/testing "Should override location"
|
||||
(sut/import-uploaded-invoice user [(assoc invoice
|
||||
@@ -61,26 +60,26 @@
|
||||
:customer-identifier "ABC"
|
||||
:invoice-number "789")])
|
||||
(t/is (= #{["DE"]} (dc/q '[:find ?l
|
||||
:where [?i :invoice/invoice-number "789"]
|
||||
[?i :invoice/expense-accounts ?ea]
|
||||
[?ea :invoice-expense-account/location ?l]]
|
||||
(dc/db conn)))))
|
||||
:where [?i :invoice/invoice-number "789"]
|
||||
[?i :invoice/expense-accounts ?ea]
|
||||
[?ea :invoice-expense-account/location ?l]]
|
||||
(dc/db conn)))))
|
||||
|
||||
(t/testing "Should code invoice"
|
||||
(let [{{:strs [my-default-account coded-vendor]} :tempids} @(dc/transact conn
|
||||
[{:vendor/name "Coded"
|
||||
:db/id "coded-vendor"
|
||||
:vendor/terms 12
|
||||
:vendor/default-account "my-default-account"}
|
||||
{:db/id "my-default-account"
|
||||
:account/name "My default-account"}])]
|
||||
[{:vendor/name "Coded"
|
||||
:db/id "coded-vendor"
|
||||
:vendor/terms 12
|
||||
:vendor/default-account "my-default-account"}
|
||||
{:db/id "my-default-account"
|
||||
:account/name "My default-account"}])]
|
||||
(sut/import-uploaded-invoice user [(assoc invoice
|
||||
:invoice-number "456"
|
||||
:customer-identifier "ABC"
|
||||
:vendor-code "Coded")])
|
||||
:invoice-number "456"
|
||||
:customer-identifier "ABC"
|
||||
:vendor-code "Coded")])
|
||||
(let [[[result]] (dc/q '[:find (pull ?i [*])
|
||||
:where [?i :invoice/invoice-number "456"]]
|
||||
(dc/db conn))]
|
||||
:where [?i :invoice/invoice-number "456"]]
|
||||
(dc/db conn))]
|
||||
(t/is (= coded-vendor (:db/id (:invoice/vendor result))))
|
||||
(t/is (= [my-default-account]
|
||||
(map (comp :db/id :invoice-expense-account/account) (:invoice/expense-accounts result))))
|
||||
|
||||
@@ -19,15 +19,13 @@
|
||||
:approval-status :transaction-approval-status/unapproved
|
||||
:description-simple "simple-description"})
|
||||
|
||||
|
||||
|
||||
(t/deftest rule-applying-fn
|
||||
(t/testing "Should apply if description matches"
|
||||
(t/is (sut/rule-applies?
|
||||
base-transaction
|
||||
{:transaction-rule/description #"original-description"
|
||||
:transaction-rule/transaction-approval-status :transaction-approval-status/approved}))
|
||||
|
||||
|
||||
(t/is (not (sut/rule-applies?
|
||||
base-transaction
|
||||
{:transaction-rule/description #"xxx"
|
||||
@@ -42,7 +40,7 @@
|
||||
(let [process (sut/rule-applying-fn [{:transaction-rule/description "simple-description"
|
||||
:transaction-rule/transaction-approval-status :transaction-approval-status/approved}])
|
||||
transaction (assoc base-transaction :transaction/description-original "simple-description")]
|
||||
(t/is (= :transaction-approval-status/approved
|
||||
(t/is (= :transaction-approval-status/approved
|
||||
(:transaction/approval-status (process transaction ["NG"]))))))
|
||||
|
||||
(t/testing "spread cents"
|
||||
@@ -79,5 +77,4 @@
|
||||
(t/is (= [0.01 0.01]
|
||||
(map :transaction-account/amount (:transaction/accounts (process (assoc transaction :transaction/amount 0.02) ["NG" "BT" "DE"])))))
|
||||
(t/is (= [0.02 0.01 0.01]
|
||||
(map :transaction-account/amount (:transaction/accounts (process (assoc transaction :transaction/amount 0.04) ["NG" "BT" "DE"])))))
|
||||
)))
|
||||
(map :transaction-account/amount (:transaction/accounts (process (assoc transaction :transaction/amount 0.04) ["NG" "BT" "DE"]))))))))
|
||||
|
||||
@@ -22,15 +22,11 @@
|
||||
(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}]}))
|
||||
|
||||
|
||||
|
||||
|
||||
{: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 test-client [& kwargs]
|
||||
(apply assoc {:db/id "client-id"
|
||||
@@ -102,15 +98,15 @@
|
||||
|
||||
(defn setup-test-data [data]
|
||||
(:tempids @(dc/transact conn (into data
|
||||
[(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"}]))))
|
||||
[(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"}]))))
|
||||
|
||||
(defn apply-tx [data]
|
||||
(:db-after @(dc/transact conn data)))
|
||||
|
||||
@@ -5,40 +5,37 @@
|
||||
|
||||
(t/use-fixtures :each wrap-setup)
|
||||
|
||||
|
||||
(t/deftest entity-change->ledger
|
||||
#_(t/testing "Should code an expected deposit"
|
||||
(let [{:strs [ed ccp receipts-split client]}
|
||||
(:tempids @(d/transact conn [#:expected-deposit {:status :expected-deposit-status/pending
|
||||
:client {:db/id "client"
|
||||
:client/code "BRYCE"
|
||||
:client/locations ["M"]}
|
||||
:total 4.0
|
||||
:fee 1.0
|
||||
:date #inst "2021-01-01T00:00:00-08:00"
|
||||
:location "M"
|
||||
:db/id "ed"}]))
|
||||
result (sut/entity-change->ledger (d/db conn) [:expected-deposit ed])]
|
||||
(t/is (= #:journal-entry
|
||||
{:source "expected-deposit"
|
||||
:client {:db/id client}
|
||||
:date #inst "2021-01-01T00:00:00-08:00"
|
||||
:original-entity ed
|
||||
:vendor :vendor/ccp-square
|
||||
:amount 4.0
|
||||
}
|
||||
(dissoc result :journal-entry/line-items)))
|
||||
(let [{:strs [ed ccp receipts-split client]}
|
||||
(:tempids @(d/transact conn [#:expected-deposit {:status :expected-deposit-status/pending
|
||||
:client {:db/id "client"
|
||||
:client/code "BRYCE"
|
||||
:client/locations ["M"]}
|
||||
:total 4.0
|
||||
:fee 1.0
|
||||
:date #inst "2021-01-01T00:00:00-08:00"
|
||||
:location "M"
|
||||
:db/id "ed"}]))
|
||||
result (sut/entity-change->ledger (d/db conn) [:expected-deposit ed])]
|
||||
(t/is (= #:journal-entry
|
||||
{:source "expected-deposit"
|
||||
:client {:db/id client}
|
||||
:date #inst "2021-01-01T00:00:00-08:00"
|
||||
:original-entity ed
|
||||
:vendor :vendor/ccp-square
|
||||
:amount 4.0}
|
||||
(dissoc result :journal-entry/line-items)))
|
||||
|
||||
(t/testing "should debit ccp"
|
||||
(t/is (= [#:journal-entry-line
|
||||
{:debit 4.0
|
||||
:location "A"
|
||||
:account :account/ccp}]
|
||||
(filter :journal-entry-line/debit (:journal-entry/line-items result))))
|
||||
)
|
||||
(t/testing "should credit receipts split ccp"
|
||||
(t/is (= [#:journal-entry-line
|
||||
{:credit 4.0
|
||||
:location "A"
|
||||
:account :account/receipts-split}]
|
||||
(filter :journal-entry-line/credit (:journal-entry/line-items result))))))))
|
||||
(t/testing "should debit ccp"
|
||||
(t/is (= [#:journal-entry-line
|
||||
{:debit 4.0
|
||||
:location "A"
|
||||
:account :account/ccp}]
|
||||
(filter :journal-entry-line/debit (:journal-entry/line-items result)))))
|
||||
(t/testing "should credit receipts split ccp"
|
||||
(t/is (= [#:journal-entry-line
|
||||
{:credit 4.0
|
||||
:location "A"
|
||||
:account :account/receipts-split}]
|
||||
(filter :journal-entry-line/credit (:journal-entry/line-items result))))))))
|
||||
|
||||
@@ -126,8 +126,8 @@
|
||||
;; Test passes if sorting parameter is accepted and function returns successfully
|
||||
(is (number? matching-count)))))
|
||||
|
||||
(deftest account-sorting-by-numeric-code
|
||||
(testing "Account sorting by numeric code should work (default)"
|
||||
(deftest account-sorting-by-numeric-code
|
||||
(testing "Account sorting by numeric code should work (default)"
|
||||
(with-redefs [auto-ap.solr/impl (auto-ap.solr/->InMemSolrClient (atom {}))]
|
||||
;; Create test accounts before sorting
|
||||
(sut/account-save {:form-params {:account/numeric-code 12372 :account/name "Numeric Account" :account/type :account-type/asset :account/location "A"} :request-method :post :identity (admin-token)})
|
||||
@@ -138,8 +138,8 @@
|
||||
;; Test passes if sorting parameter is accepted and function returns successfully
|
||||
(is (number? matching-count))))))
|
||||
|
||||
(deftest account-sorting-by-type
|
||||
(testing "Account sorting by type should work"
|
||||
(deftest account-sorting-by-type
|
||||
(testing "Account sorting by type should work"
|
||||
(with-redefs [auto-ap.solr/impl (auto-ap.solr/->InMemSolrClient (atom {}))]
|
||||
;; Create test accounts before sorting
|
||||
(sut/account-save {:form-params {:account/numeric-code 12374 :account/name "Type Test" :account/type :account-type/asset :account/location "A"} :request-method :post :identity (admin-token)})
|
||||
|
||||
@@ -411,7 +411,7 @@
|
||||
:location "HQ"}]}
|
||||
admin-identity (admin-token)]
|
||||
(is (thrown? Exception (sut/import-ledger {:form-params form-params
|
||||
:identity admin-identity})))))
|
||||
:identity admin-identity})))))
|
||||
|
||||
(testing "Should produce form-errors for invalid account entries"
|
||||
(let [_ (setup-test-data [(test-client :db/id "err-client-1"
|
||||
@@ -430,7 +430,7 @@
|
||||
:location "HQ"}]}
|
||||
admin-identity (admin-token)]
|
||||
(is (thrown? Exception (sut/import-ledger {:form-params form-params
|
||||
:identity admin-identity}))))))
|
||||
:identity admin-identity}))))))
|
||||
|
||||
(deftest import-ledger-with-warnings-test
|
||||
(testing "Should ignore entries with only warnings"
|
||||
|
||||
@@ -15,14 +15,14 @@
|
||||
[datomic.api :as dc]))
|
||||
|
||||
#_(t/use-fixtures :each (fn [f]
|
||||
(dc/transact conn [{:db/id "vendor-id"
|
||||
:vendor/name "Test Vendor"
|
||||
:vendor/default-account {:db/id "account-id"}}
|
||||
{:db/id "client-id"
|
||||
:client/code "TEST"
|
||||
:client/locations ["Z" "E"]
|
||||
:client/bank-accounts ["bank-account-id"]}])
|
||||
(f)))
|
||||
(dc/transact conn [{:db/id "vendor-id"
|
||||
:vendor/name "Test Vendor"
|
||||
:vendor/default-account {:db/id "account-id"}}
|
||||
{:db/id "client-id"
|
||||
:client/code "TEST"
|
||||
:client/locations ["Z" "E"]
|
||||
:client/bank-accounts ["bank-account-id"]}])
|
||||
(f)))
|
||||
(t/use-fixtures :each wrap-setup)
|
||||
|
||||
(t/deftest get-vendor-test
|
||||
@@ -39,11 +39,11 @@
|
||||
(t/deftest clientize-vendor-test
|
||||
(t/testing "Should transform vendor data for a specific client"
|
||||
(let [vendor {:db/id "vendor-id"
|
||||
:vendor/name "Test Vendor"
|
||||
:vendor/default-account {:db/id "account-id"}
|
||||
:vendor/terms-overrides [{:vendor-terms-override/client {:db/id "client-id"}
|
||||
:vendor/name "Test Vendor"
|
||||
:vendor/default-account {:db/id "account-id"}
|
||||
:vendor/terms-overrides [{:vendor-terms-override/client {:db/id "client-id"}
|
||||
:vendor-terms-override/terms "New Terms"}]
|
||||
:vendor/account-overrides [{:vendor-account-override/client {:db/id "client-id"}
|
||||
:vendor/account-overrides [{:vendor-account-override/client {:db/id "client-id"}
|
||||
:vendor-account-override/account {:db/id "client-specific-account-id"}}]}
|
||||
clientized-vendor (clientize-vendor vendor "client-id")]
|
||||
(t/is (= "New Terms" (:vendor/terms clientized-vendor)))
|
||||
|
||||
@@ -53,59 +53,59 @@
|
||||
|
||||
(defn seed-test-data [conn]
|
||||
(let [tx-result @(dc/transact conn
|
||||
[(assoc (test-client :db/id "client-id"
|
||||
:client/code "TEST"
|
||||
:client/locations ["DT"])
|
||||
:client/bank-accounts [(test-bank-account :db/id "bank-account-id")])
|
||||
{:db/id "account-id"
|
||||
:account/name "Test Account"
|
||||
:account/type :account-type/expense
|
||||
:account/numeric-code 50000
|
||||
:account/applicability :account-applicability/global
|
||||
:account/default-allowance {:db/ident :allowance/allowed}}
|
||||
{:db/id "account-id-2"
|
||||
:account/name "Second Account"
|
||||
:account/type :account-type/expense
|
||||
:account/numeric-code 50001
|
||||
:account/applicability :account-applicability/global
|
||||
:account/default-allowance {:db/ident :allowance/allowed}}
|
||||
{:db/id "account-id-fixed-loc"
|
||||
:account/name "Fixed Location Account"
|
||||
:account/type :account-type/expense
|
||||
:account/numeric-code 50002
|
||||
:account/applicability :account-applicability/global
|
||||
:account/location "DT"
|
||||
:account/default-allowance {:db/ident :allowance/allowed}}
|
||||
{:db/id "ap-account-id"
|
||||
:account/name "Accounts Payable"
|
||||
:db/ident :account/accounts-payable
|
||||
:account/numeric-code 21000
|
||||
:account/account-set "default"
|
||||
:account/applicability :account-applicability/global
|
||||
:account/default-allowance {:db/ident :allowance/allowed}}
|
||||
{:db/id "vendor-id"
|
||||
:vendor/name "Test Vendor"
|
||||
:vendor/default-account "account-id"}
|
||||
(test-transaction :db/id "transaction-id"
|
||||
:transaction/client "client-id"
|
||||
:transaction/bank-account "bank-account-id"
|
||||
:transaction/amount 100.0
|
||||
:transaction/description-original "Test transaction"
|
||||
:transaction/approval-status :transaction-approval-status/unapproved)
|
||||
(test-transaction :db/id "transaction-id-2"
|
||||
:transaction/client "client-id"
|
||||
:transaction/bank-account "bank-account-id"
|
||||
:transaction/amount 200.0
|
||||
:transaction/description-original "Second transaction"
|
||||
:transaction/approval-status :transaction-approval-status/unapproved)
|
||||
(test-transaction :db/id "transaction-id-3"
|
||||
:transaction/client "client-id"
|
||||
:transaction/bank-account "bank-account-id"
|
||||
:transaction/amount 300.0
|
||||
:transaction/description-original "Third transaction"
|
||||
:transaction/approval-status :transaction-approval-status/unapproved)])
|
||||
tempids (:tempids tx-result)
|
||||
tx-entity-id (get tempids "transaction-id")]
|
||||
[(assoc (test-client :db/id "client-id"
|
||||
:client/code "TEST"
|
||||
:client/locations ["DT"])
|
||||
:client/bank-accounts [(test-bank-account :db/id "bank-account-id")])
|
||||
{:db/id "account-id"
|
||||
:account/name "Test Account"
|
||||
:account/type :account-type/expense
|
||||
:account/numeric-code 50000
|
||||
:account/applicability :account-applicability/global
|
||||
:account/default-allowance {:db/ident :allowance/allowed}}
|
||||
{:db/id "account-id-2"
|
||||
:account/name "Second Account"
|
||||
:account/type :account-type/expense
|
||||
:account/numeric-code 50001
|
||||
:account/applicability :account-applicability/global
|
||||
:account/default-allowance {:db/ident :allowance/allowed}}
|
||||
{:db/id "account-id-fixed-loc"
|
||||
:account/name "Fixed Location Account"
|
||||
:account/type :account-type/expense
|
||||
:account/numeric-code 50002
|
||||
:account/applicability :account-applicability/global
|
||||
:account/location "DT"
|
||||
:account/default-allowance {:db/ident :allowance/allowed}}
|
||||
{:db/id "ap-account-id"
|
||||
:account/name "Accounts Payable"
|
||||
:db/ident :account/accounts-payable
|
||||
:account/numeric-code 21000
|
||||
:account/account-set "default"
|
||||
:account/applicability :account-applicability/global
|
||||
:account/default-allowance {:db/ident :allowance/allowed}}
|
||||
{:db/id "vendor-id"
|
||||
:vendor/name "Test Vendor"
|
||||
:vendor/default-account "account-id"}
|
||||
(test-transaction :db/id "transaction-id"
|
||||
:transaction/client "client-id"
|
||||
:transaction/bank-account "bank-account-id"
|
||||
:transaction/amount 100.0
|
||||
:transaction/description-original "Test transaction"
|
||||
:transaction/approval-status :transaction-approval-status/unapproved)
|
||||
(test-transaction :db/id "transaction-id-2"
|
||||
:transaction/client "client-id"
|
||||
:transaction/bank-account "bank-account-id"
|
||||
:transaction/amount 200.0
|
||||
:transaction/description-original "Second transaction"
|
||||
:transaction/approval-status :transaction-approval-status/unapproved)
|
||||
(test-transaction :db/id "transaction-id-3"
|
||||
:transaction/client "client-id"
|
||||
:transaction/bank-account "bank-account-id"
|
||||
:transaction/amount 300.0
|
||||
:transaction/description-original "Third transaction"
|
||||
:transaction/approval-status :transaction-approval-status/unapproved)])
|
||||
tempids (:tempids tx-result)
|
||||
tx-entity-id (get tempids "transaction-id")]
|
||||
(println "Test transaction entity ID:" tx-entity-id)
|
||||
(reset! test-account-ids
|
||||
{:test-account (get tempids "account-id")
|
||||
|
||||
@@ -23,64 +23,61 @@
|
||||
:journal-entry-line/dirty
|
||||
:journal-entry-line/debit]}])
|
||||
|
||||
|
||||
(deftest upsert-invoice
|
||||
(testing "Importing should create a journal entry"
|
||||
(let [{:strs [invoice-id
|
||||
test-client-id
|
||||
test-vendor-id
|
||||
]} (setup-test-data
|
||||
[(test-invoice :db/id "invoice-id"
|
||||
:invoice/import-status :import-status/pending
|
||||
:invoice/total 200.0
|
||||
)])]
|
||||
|
||||
test-vendor-id]} (setup-test-data
|
||||
[(test-invoice :db/id "invoice-id"
|
||||
:invoice/import-status :import-status/pending
|
||||
:invoice/total 200.0)])]
|
||||
|
||||
(is (nil? (:db/id (dc/pull (dc/db conn) journal-pull
|
||||
[:journal-entry/original-entity invoice-id]))))
|
||||
(let [db-after (apply-tx (sut-i/upsert-invoice
|
||||
(dc/db conn)
|
||||
{:db/id invoice-id
|
||||
:invoice/import-status :import-status/imported}))]
|
||||
|
||||
(dc/db conn)
|
||||
{:db/id invoice-id
|
||||
:invoice/import-status :import-status/imported}))]
|
||||
|
||||
(is (= #:journal-entry{:date #inst "2022-01-01T00:00:00.000-00:00",
|
||||
:original-entity #:db{:id invoice-id},
|
||||
:client #:db{:id test-client-id},
|
||||
:line-items
|
||||
[#:journal-entry-line{:account
|
||||
#:account{:name
|
||||
"Accounts Payable"},
|
||||
:credit 200.0,
|
||||
:location "A",
|
||||
:dirty true}
|
||||
#:journal-entry-line{:account
|
||||
#:account{:name "Account"},
|
||||
:location "DT",
|
||||
:dirty true,
|
||||
:debit 100.0}],
|
||||
:source "invoice",
|
||||
:cleared false,
|
||||
:amount 200.0,
|
||||
:vendor #:db{:id test-vendor-id}}
|
||||
:original-entity #:db{:id invoice-id},
|
||||
:client #:db{:id test-client-id},
|
||||
:line-items
|
||||
[#:journal-entry-line{:account
|
||||
#:account{:name
|
||||
"Accounts Payable"},
|
||||
:credit 200.0,
|
||||
:location "A",
|
||||
:dirty true}
|
||||
#:journal-entry-line{:account
|
||||
#:account{:name "Account"},
|
||||
:location "DT",
|
||||
:dirty true,
|
||||
:debit 100.0}],
|
||||
:source "invoice",
|
||||
:cleared false,
|
||||
:amount 200.0,
|
||||
:vendor #:db{:id test-vendor-id}}
|
||||
(dc/pull db-after journal-pull
|
||||
[:journal-entry/original-entity invoice-id])))
|
||||
|
||||
(testing "voiding an invoice should remove the journal entry"
|
||||
(let [db-after (apply-tx (sut-i/upsert-invoice
|
||||
(dc/db conn)
|
||||
{:db/id invoice-id
|
||||
:invoice/status :invoice-status/voided}))]
|
||||
|
||||
(is (= nil
|
||||
(dc/db conn)
|
||||
{:db/id invoice-id
|
||||
:invoice/status :invoice-status/voided}))]
|
||||
|
||||
(is (= nil
|
||||
(dc/pull db-after journal-pull
|
||||
[:journal-entry/original-entity invoice-id])))))
|
||||
(testing "invoice should remove the journal entry"
|
||||
(let [db-after (apply-tx (sut-i/upsert-invoice
|
||||
(dc/db conn)
|
||||
{:db/id invoice-id
|
||||
:invoice/status :invoice-status/unpaid
|
||||
:invoice/import-status :import-status/pending}))]
|
||||
|
||||
(is (= nil
|
||||
(dc/db conn)
|
||||
{:db/id invoice-id
|
||||
:invoice/status :invoice-status/unpaid
|
||||
:invoice/import-status :import-status/pending}))]
|
||||
|
||||
(is (= nil
|
||||
(dc/pull db-after journal-pull
|
||||
[:journal-entry/original-entity invoice-id])))))))))
|
||||
|
||||
@@ -91,31 +88,28 @@
|
||||
test-account-id
|
||||
test-vendor-id
|
||||
test-transaction-id
|
||||
test-import-batch-id
|
||||
]} (setup-test-data
|
||||
[(test-transaction :db/id "test-transaction-id"
|
||||
)
|
||||
{:db/id "test-import-batch-id"
|
||||
:import-batch/date #inst "2022-01-01"}])
|
||||
test-import-batch-id]} (setup-test-data
|
||||
[(test-transaction :db/id "test-transaction-id")
|
||||
{:db/id "test-import-batch-id"
|
||||
:import-batch/date #inst "2022-01-01"}])
|
||||
update (sut-t/upsert-transaction (dc/db conn) {:db/id test-transaction-id
|
||||
:transaction/id "hello"
|
||||
:transaction/bank-account test-bank-account-id
|
||||
:transaction/amount 500.00
|
||||
:transaction/client test-client-id
|
||||
:transaction/date #inst "2022-01-01"
|
||||
:transaction/vendor test-vendor-id
|
||||
:transaction/approval-status :transaction-approval-status/approved
|
||||
:transaction/accounts [
|
||||
{:db/id "account"
|
||||
:transaction-account/account test-account-id
|
||||
:transaction-account/location "A"
|
||||
:transaction-account/amount 500.00}]})]
|
||||
|
||||
:transaction/id "hello"
|
||||
:transaction/bank-account test-bank-account-id
|
||||
:transaction/amount 500.00
|
||||
:transaction/client test-client-id
|
||||
:transaction/date #inst "2022-01-01"
|
||||
:transaction/vendor test-vendor-id
|
||||
:transaction/approval-status :transaction-approval-status/approved
|
||||
:transaction/accounts [{:db/id "account"
|
||||
:transaction-account/account test-account-id
|
||||
:transaction-account/location "A"
|
||||
:transaction-account/amount 500.00}]})]
|
||||
|
||||
(is (nil? (:db/id (dc/pull (dc/db conn) journal-pull
|
||||
[:journal-entry/original-entity test-transaction-id]))))
|
||||
(let [db-after (apply-tx update)]
|
||||
(testing "should create journal entry"
|
||||
(is (= #:journal-entry{:date #inst "2022-01-01T00:00:00.000-00:00",
|
||||
(is (= #:journal-entry{:date #inst "2022-01-01T00:00:00.000-00:00",
|
||||
:original-entity #:db{:id test-transaction-id},
|
||||
:client #:db{:id test-client-id},
|
||||
:source "transaction",
|
||||
@@ -130,8 +124,6 @@
|
||||
#:account{:name "Account"},
|
||||
:location "A",
|
||||
:credit 500.0,
|
||||
:dirty true}]}
|
||||
:dirty true}]}
|
||||
(dc/pull db-after journal-pull
|
||||
[:journal-entry/original-entity test-transaction-id])))))
|
||||
|
||||
)))
|
||||
[:journal-entry/original-entity test-transaction-id]))))))))
|
||||
|
||||
Reference in New Issue
Block a user