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