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:
@@ -8,9 +8,8 @@
|
||||
:amount 123.45
|
||||
:date "2023-01-01"})
|
||||
|
||||
(t/deftest plaid->transaction
|
||||
(t/deftest plaid->transaction
|
||||
|
||||
|
||||
(t/testing "Should assign a plaid merchant if a merchant is found"
|
||||
(t/is (= "Home Depot" (-> (sut/plaid->transaction (assoc base-transaction
|
||||
:merchant_name "Home Depot")
|
||||
@@ -19,6 +18,6 @@
|
||||
:plaid-merchant/name))))
|
||||
(t/testing "Should assign a default vendor if a merchant is found, with a matching vendor lookup"
|
||||
(t/is (= 12354 (-> (sut/plaid->transaction (assoc base-transaction
|
||||
:merchant_name "Home Depot")
|
||||
{"Home Depot" 12354})
|
||||
:transaction/default-vendor)))))
|
||||
:merchant_name "Home Depot")
|
||||
{"Home Depot" 12354})
|
||||
:transaction/default-vendor)))))
|
||||
|
||||
@@ -71,7 +71,6 @@
|
||||
bank-account
|
||||
{}))))))
|
||||
|
||||
|
||||
(t/deftest transaction->txs
|
||||
(t/testing "Should import and code transactions"
|
||||
(t/testing "Should import one transaction"
|
||||
@@ -83,8 +82,8 @@
|
||||
:client/locations ["Z" "E"]
|
||||
:client/bank-accounts ["bank-account-id"]}]))
|
||||
result (sut/transaction->txs base-transaction
|
||||
(dc/pull (dc/db conn) sut/bank-account-pull bank-account-id)
|
||||
noop-rule)]
|
||||
(dc/pull (dc/db conn) sut/bank-account-pull bank-account-id)
|
||||
noop-rule)]
|
||||
(t/is (= (assoc base-transaction
|
||||
:transaction/approval-status :transaction-approval-status/unapproved
|
||||
:transaction/bank-account bank-account-id
|
||||
@@ -92,11 +91,11 @@
|
||||
result))))
|
||||
|
||||
(t/testing "Should apply a default vendor"
|
||||
(let [ {:strs [test-client-id test-bank-account-id test-vendor-id]} (setup-test-data [])
|
||||
(let [{:strs [test-client-id test-bank-account-id test-vendor-id]} (setup-test-data [])
|
||||
result (sut/transaction->txs (assoc base-transaction
|
||||
:transaction/default-vendor test-vendor-id)
|
||||
(dc/pull (dc/db conn) sut/bank-account-pull test-bank-account-id)
|
||||
noop-rule)]
|
||||
(dc/pull (dc/db conn) sut/bank-account-pull test-bank-account-id)
|
||||
noop-rule)]
|
||||
(t/is (= (assoc base-transaction
|
||||
:transaction/approval-status :transaction-approval-status/unapproved
|
||||
:transaction/bank-account test-bank-account-id
|
||||
@@ -125,21 +124,20 @@
|
||||
:transaction/description-original "CHECK 10001"
|
||||
:transaction/check-number 10001
|
||||
:transaction/amount -30.0)
|
||||
(dc/pull (dc/db conn ) sut/bank-account-pull bank-account-id)
|
||||
(dc/pull (dc/db conn) sut/bank-account-pull bank-account-id)
|
||||
noop-rule)]
|
||||
|
||||
|
||||
(t/is (= {:db/id payment-id
|
||||
:payment/status :payment-status/cleared}
|
||||
(:transaction/payment transaction-result))))
|
||||
|
||||
|
||||
(t/testing "Should match a check that matches on amount if check number does not match"
|
||||
(let [transaction-result (sut/transaction->txs (assoc base-transaction
|
||||
:transaction/description-original "CHECK 12301"
|
||||
:transaction/amount -30.0)
|
||||
(dc/pull (dc/db conn ) sut/bank-account-pull bank-account-id)
|
||||
(dc/pull (dc/db conn) sut/bank-account-pull bank-account-id)
|
||||
noop-rule)]
|
||||
|
||||
|
||||
(t/is (= {:db/id payment-id
|
||||
:payment/status :payment-status/cleared}
|
||||
(:transaction/payment transaction-result)))))
|
||||
@@ -151,11 +149,10 @@
|
||||
:transaction/amount -30.0)
|
||||
(dc/pull (dc/db conn) sut/bank-account-pull bank-account-id)
|
||||
noop-rule)]
|
||||
|
||||
|
||||
(t/is (= nil
|
||||
(:transaction/payment result)))))))
|
||||
|
||||
|
||||
(t/testing "Should match expected-deposits"
|
||||
(let [{:strs [bank-account-id client-id expected-deposit-id]} (->> [#:expected-deposit {:client "client-id"
|
||||
:date #inst "2021-07-01T00:00:00-08:00"
|
||||
@@ -174,7 +171,6 @@
|
||||
deref
|
||||
:tempids)]
|
||||
|
||||
|
||||
(t/testing "Should match within 10 days"
|
||||
(let [transaction-result (sut/transaction->txs (assoc base-transaction
|
||||
:transaction/date #inst "2021-07-03T00:00:00-08:00"
|
||||
@@ -183,7 +179,7 @@
|
||||
noop-rule)]
|
||||
(t/is (= expected-deposit-id
|
||||
(:db/id (sut/find-expected-deposit client-id 100.0 (clj-time.coerce/to-date-time #inst "2021-07-03T00:00:00-08:00")))))
|
||||
|
||||
|
||||
(t/is (= {:db/id expected-deposit-id
|
||||
:expected-deposit/status :expected-deposit-status/cleared}
|
||||
(:transaction/expected-deposit transaction-result)))))
|
||||
@@ -194,7 +190,7 @@
|
||||
(dc/pull (dc/db conn) sut/bank-account-pull bank-account-id)
|
||||
noop-rule)]
|
||||
(t/is (= :vendor/ccp-square
|
||||
(:transaction/vendor transaction-result)))))
|
||||
(:transaction/vendor transaction-result)))))
|
||||
|
||||
(t/testing "Should credit CCP"
|
||||
(let [transaction-result (sut/transaction->txs (assoc base-transaction
|
||||
@@ -262,7 +258,6 @@
|
||||
first
|
||||
:transaction/raw-id)))))
|
||||
|
||||
|
||||
(t/deftest match-transaction-to-single-unfulfilled-payments
|
||||
(t/testing "Auto-pay Invoices"
|
||||
(let [{:strs [vendor1-id vendor2-id]} (->> [#:vendor {:name "Autopay vendor 1"
|
||||
@@ -281,12 +276,11 @@
|
||||
:total 30.0
|
||||
:db/id "invoice-id"}
|
||||
#:client {:name "Client" :db/id "client-id"}]
|
||||
(dc/transact conn)
|
||||
deref
|
||||
:tempids)
|
||||
(dc/transact conn)
|
||||
deref
|
||||
:tempids)
|
||||
invoices-matches (sut/match-transaction-to-single-unfulfilled-autopayments -30.0 client-id)]
|
||||
(t/is (= 1 (count invoices-matches)))
|
||||
))
|
||||
(t/is (= 1 (count invoices-matches)))))
|
||||
|
||||
(t/testing "Should not match paid invoice that isn't a scheduled payment"
|
||||
(let [{:strs [client-id]} (->> [#:invoice{:status :invoice-status/paid
|
||||
@@ -300,13 +294,13 @@
|
||||
deref
|
||||
:tempids)
|
||||
invoices-matches (sut/match-transaction-to-single-unfulfilled-autopayments -30.0 client-id)]
|
||||
|
||||
|
||||
(t/is (= [] invoices-matches))))
|
||||
|
||||
(t/testing "Should not match unpaid invoice"
|
||||
(let [{:strs [client-id]} (->> [#:invoice {:status :invoice-status/unpaid
|
||||
:scheduled-payment #inst "2019-01-04"
|
||||
:vendor vendor1-id
|
||||
:vendor vendor1-id
|
||||
:date #inst "2019-01-01"
|
||||
:client "client-id"
|
||||
:total 30.0
|
||||
@@ -316,7 +310,7 @@
|
||||
deref
|
||||
:tempids)
|
||||
invoices-matches (sut/match-transaction-to-single-unfulfilled-autopayments -30.0 client-id)]
|
||||
|
||||
|
||||
(t/is (= [] invoices-matches))))
|
||||
|
||||
(t/testing "Should not match invoice that already has a payment"
|
||||
@@ -335,7 +329,7 @@
|
||||
deref
|
||||
:tempids)
|
||||
invoices-matches (sut/match-transaction-to-single-unfulfilled-autopayments -30.0
|
||||
client-id)]
|
||||
client-id)]
|
||||
(t/is (= [] invoices-matches))))
|
||||
(t/testing "Should match multiple invoices for same vendor that total to transaction amount"
|
||||
(let [{:strs [client-id]} (->> [#:invoice {:status :invoice-status/paid
|
||||
@@ -436,45 +430,41 @@
|
||||
(t/is (= [] (sut/match-transaction-to-single-unfulfilled-autopayments -31.0 client-id))
|
||||
(str "Expected to not match, because there is invoice-3 is between invoice-1 and invoice-2.")))))))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#_(t/testing "Auto-pay Invoices"
|
||||
(t/testing "Should match paid invoice that doesn't have a payment yet"
|
||||
(let [{:strs [bank-account-id client-id invoice1-id invoice2-id vendor-id]} (->> [#:invoice {:status :invoice-status/paid
|
||||
:vendor "vendor-id"
|
||||
:scheduled-payment #inst "2019-01-04"
|
||||
:date #inst "2019-01-01"
|
||||
:client "client-id"
|
||||
:total 20.0
|
||||
:db/id "invoice1-id"}
|
||||
#:invoice {:status :invoice-status/paid
|
||||
:vendor "vendor-id"
|
||||
:scheduled-payment #inst "2019-01-04"
|
||||
:date #inst "2019-01-01"
|
||||
:client "client-id"
|
||||
:total 10.0
|
||||
:db/id "invoice2-id"}
|
||||
#:vendor {:name "Autopay vendor"
|
||||
:db/id "vendor-id"}
|
||||
#:bank-account {:name "Bank account"
|
||||
:db/id "bank-account-id"}
|
||||
#:client {:name "Client"
|
||||
:db/id "client-id"
|
||||
:bank-accounts ["bank-account-id"]}]
|
||||
(d/transact (d/connect uri))
|
||||
deref
|
||||
:tempids)
|
||||
:vendor "vendor-id"
|
||||
:scheduled-payment #inst "2019-01-04"
|
||||
:date #inst "2019-01-01"
|
||||
:client "client-id"
|
||||
:total 20.0
|
||||
:db/id "invoice1-id"}
|
||||
#:invoice {:status :invoice-status/paid
|
||||
:vendor "vendor-id"
|
||||
:scheduled-payment #inst "2019-01-04"
|
||||
:date #inst "2019-01-01"
|
||||
:client "client-id"
|
||||
:total 10.0
|
||||
:db/id "invoice2-id"}
|
||||
#:vendor {:name "Autopay vendor"
|
||||
:db/id "vendor-id"}
|
||||
#:bank-account {:name "Bank account"
|
||||
:db/id "bank-account-id"}
|
||||
#:client {:name "Client"
|
||||
:db/id "client-id"
|
||||
:bank-accounts ["bank-account-id"]}]
|
||||
(d/transact (d/connect uri))
|
||||
deref
|
||||
:tempids)
|
||||
[[transaction-tx payment-tx invoice-payments1-tx invoice-payments2-tx]] (sut/yodlees->transactions [(assoc base-yodlee-transaction
|
||||
:amount {:amount 30.0}
|
||||
:bank-account {:db/id bank-account-id
|
||||
:client/_bank-accounts {:db/id client-id
|
||||
:client/locations ["A"]}})]
|
||||
:bank-account
|
||||
noop-rule
|
||||
#{})]
|
||||
|
||||
:amount {:amount 30.0}
|
||||
:bank-account {:db/id bank-account-id
|
||||
:client/_bank-accounts {:db/id client-id
|
||||
:client/locations ["A"]}})]
|
||||
:bank-account
|
||||
noop-rule
|
||||
#{})]
|
||||
|
||||
(t/is (= :transaction-approval-status/approved
|
||||
(:transaction/approval-status transaction-tx))
|
||||
(str "Should have approved transaction " transaction-tx))
|
||||
@@ -519,14 +509,14 @@
|
||||
deref
|
||||
:tempids)
|
||||
[[transaction-tx payment-tx]] (sut/yodlees->transactions [(assoc base-yodlee-transaction
|
||||
:amount {:amount 30.0}
|
||||
:bank-account {:db/id bank-account-id
|
||||
:client/_bank-accounts {:db/id client-id
|
||||
:client/locations ["A"]}})]
|
||||
:bank-account
|
||||
noop-rule
|
||||
#{})]
|
||||
|
||||
:amount {:amount 30.0}
|
||||
:bank-account {:db/id bank-account-id
|
||||
:client/_bank-accounts {:db/id client-id
|
||||
:client/locations ["A"]}})]
|
||||
:bank-account
|
||||
noop-rule
|
||||
#{})]
|
||||
|
||||
(t/is (= :transaction-approval-status/unapproved
|
||||
(:transaction/approval-status transaction-tx)))
|
||||
(t/is (nil? (:transaction/payment transaction-tx))))))
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
(:require [auto-ap.import.yodlee2 :as sut]
|
||||
[clojure.test :as t]))
|
||||
|
||||
|
||||
(def base-transaction {:postDate "2014-01-04"
|
||||
:accountId 1234
|
||||
:date "2014-01-02"
|
||||
@@ -26,6 +25,6 @@
|
||||
:baseType "DEBIT")
|
||||
false))))
|
||||
(t/is (= 12.0 (:transaction/amount (sut/yodlee->transaction (assoc base-transaction
|
||||
:amount {:amount 12.0}
|
||||
:baseType "CREDIT")
|
||||
:amount {:amount 12.0}
|
||||
:baseType "CREDIT")
|
||||
false))))))
|
||||
|
||||
Reference in New Issue
Block a user