fixes vendor selection bug
This commit is contained in:
@@ -5,12 +5,13 @@
|
||||
[auto-ap.solr]
|
||||
[auto-ap.ssr.components.multi-modal :as mm]
|
||||
[auto-ap.ssr.form-cursor :as fc]
|
||||
[auto-ap.ssr.transaction.edit :refer [clientize-vendor
|
||||
edit-vendor-changed-handler
|
||||
edit-wizard-toggle-mode-handler
|
||||
location-select*
|
||||
manual-coding-section*
|
||||
vendor-default-account]]
|
||||
[auto-ap.ssr.transaction.edit
|
||||
:refer [clientize-vendor
|
||||
edit-vendor-changed-handler
|
||||
edit-wizard-toggle-mode-handler
|
||||
location-select*
|
||||
manual-coding-section*
|
||||
vendor-default-account]]
|
||||
[clojure.test :refer [deftest is testing use-fixtures]]
|
||||
[datomic.api :as dc]
|
||||
[hiccup.core :as hiccup]))
|
||||
@@ -52,7 +53,7 @@
|
||||
(testing "AC3: multi-account (2+) transaction opens in advanced mode"
|
||||
(is (= :advanced (manual-mode-initial {:db/id 123
|
||||
:transaction/accounts [{:transaction-account/account 1}
|
||||
{:transaction-account/account 2}]})))
|
||||
{:transaction-account/account 2}]})))
|
||||
(is (= :advanced (manual-mode-initial {:db/id 123
|
||||
:transaction/accounts [{} {} {}]})))))
|
||||
|
||||
@@ -163,18 +164,18 @@
|
||||
(deftest save-manual-round-trip-test
|
||||
(testing "AC6: save in simple mode persists vendor/account/location — re-opening shows same values"
|
||||
(let [result @(dc/transact conn [{:db/id "vendor-id"
|
||||
:vendor/name "Save Vendor"}
|
||||
{:db/id "account-id"
|
||||
:account/name "Save Account"
|
||||
:account/type :account-type/expense}
|
||||
{:db/id "client-id"
|
||||
:client/code "SAVECL"
|
||||
:client/locations ["DT"]}
|
||||
{:db/id "transaction-id"
|
||||
:transaction/amount 100.0
|
||||
:transaction/date #inst "2023-01-01"
|
||||
:transaction/id (str (java.util.UUID/randomUUID))
|
||||
:transaction/client "client-id"}])
|
||||
:vendor/name "Save Vendor"}
|
||||
{:db/id "account-id"
|
||||
:account/name "Save Account"
|
||||
:account/type :account-type/expense}
|
||||
{:db/id "client-id"
|
||||
:client/code "SAVECL"
|
||||
:client/locations ["DT"]}
|
||||
{:db/id "transaction-id"
|
||||
:transaction/amount 100.0
|
||||
:transaction/date #inst "2023-01-01"
|
||||
:transaction/id (str (java.util.UUID/randomUUID))
|
||||
:transaction/client "client-id"}])
|
||||
tx-id (tempid->id result "transaction-id")
|
||||
vendor-id (tempid->id result "vendor-id")
|
||||
account-id (tempid->id result "account-id")
|
||||
@@ -934,3 +935,64 @@
|
||||
;; Should NOT show 'Switch to simple mode'
|
||||
(is (not (re-find #"Switch to simple mode" html))
|
||||
"AC20: Simple mode should NOT show 'Switch to simple mode' link"))))
|
||||
|
||||
;;; ---------------------------------------------------------------------------
|
||||
;;; Bug: vendor selection gets erased on vendor-changed HTMX response
|
||||
;;; ---------------------------------------------------------------------------
|
||||
|
||||
(deftest vendor-selection-preserved-in-htmx-response-test
|
||||
(testing "BUG: vendor selection should be preserved when HTMX re-renders the edit form"
|
||||
(let [result @(dc/transact conn [{:db/id "vendor-id"
|
||||
:vendor/name "Test Vendor"}
|
||||
{:db/id "account-id"
|
||||
:account/name "Existing Account"
|
||||
:account/type :account-type/expense}
|
||||
{:db/id "client-id"
|
||||
:client/code "VENDORCL"
|
||||
:client/locations ["DT"]}
|
||||
{:db/id "transaction-id"
|
||||
:transaction/amount 100.0
|
||||
:transaction/date #inst "2023-01-01"
|
||||
:transaction/id (str (java.util.UUID/randomUUID))
|
||||
:transaction/client "client-id"}])
|
||||
tx-id (tempid->id result "transaction-id")
|
||||
vendor-id (tempid->id result "vendor-id")
|
||||
account-id (tempid->id result "account-id")
|
||||
client-id (tempid->id result "client-id")
|
||||
;; Simulate the request after middleware decoding.
|
||||
;; In production, form values arrive as strings. The middleware decodes
|
||||
;; step-params with keyword keys but leaves values as strings.
|
||||
existing-accounts [{:db/id "row-1"
|
||||
:transaction-account/account account-id
|
||||
:transaction-account/location "DT"
|
||||
:transaction-account/amount 100.0}]
|
||||
request {:multi-form-state (mm/->MultiStepFormState
|
||||
{:db/id tx-id
|
||||
:transaction/client client-id
|
||||
:transaction/accounts existing-accounts}
|
||||
[]
|
||||
{:mode "simple"
|
||||
;; This is how the vendor ID arrives from the form:
|
||||
;; as a string, not a long.
|
||||
:transaction/vendor (str vendor-id)
|
||||
:transaction/accounts existing-accounts})
|
||||
:entity {:db/id tx-id
|
||||
:transaction/client {:db/id client-id}
|
||||
:transaction/amount 100.0}}
|
||||
;; The handler should return a successful response with the vendor
|
||||
;; preserved. Currently it crashes because the string vendor-id is
|
||||
;; not converted to a long before being passed to Datomic.
|
||||
response (try
|
||||
(edit-vendor-changed-handler request)
|
||||
(catch Exception e
|
||||
{:error e}))]
|
||||
(is (not (:error response))
|
||||
(str "BUG: String vendor-id from form submission should be converted to long. "
|
||||
"Server crashes with: " (some-> response :error ex-message)))
|
||||
(when-not (:error response)
|
||||
(is (= 200 (:status response))
|
||||
"Response should be successful")
|
||||
(is (re-find #"Test Vendor" (:body response))
|
||||
"Vendor name should appear in the HTMX response")
|
||||
(is (re-find (re-pattern (str vendor-id)) (:body response))
|
||||
"Vendor ID should be preserved in the response HTML")))))
|
||||
|
||||
Reference in New Issue
Block a user