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:
@@ -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))))))))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user