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:
2026-05-21 14:45:19 -07:00
parent 8bd0cee1b1
commit ba87805d4c
210 changed files with 8694 additions and 9627 deletions

View File

@@ -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)))