Fix bulk code vendor pre-population for single vs multi-client contexts
- vendor-default-account now uses raw vendor default account (not client-specific override) - Account name is clientized via d-accounts/clientize only for single-client contexts - Added single-client-id helper that returns client ID only when user has exactly one client - Added multi-client e2e test verifying no pre-population across multiple clients - Updated test server to support multi-client mode switching via /test-set-client-mode - Test server now seeds a second client for multi-client scenarios
This commit is contained in:
@@ -25,12 +25,26 @@
|
||||
[cheshire.core]
|
||||
[config.core :refer [env]]))
|
||||
|
||||
(def test-identity-mode (atom :single-client))
|
||||
(def test-transaction-id (atom nil))
|
||||
(def test-account-ids (atom {}))
|
||||
(def test-client-ids (atom {}))
|
||||
|
||||
(defn admin-identity []
|
||||
{:user "TEST ADMIN"
|
||||
:user/role "admin"
|
||||
:user/name "TEST ADMIN"
|
||||
:exp (time/plus (time/now) (time/days 1))
|
||||
:user/clients [{:db/id "client-id" :client/code "TEST" :client/locations ["DT"]}]})
|
||||
(case @test-identity-mode
|
||||
:multi-client
|
||||
{:user "TEST ADMIN"
|
||||
:user/role "admin"
|
||||
:user/name "TEST ADMIN"
|
||||
:exp (time/plus (time/now) (time/days 1))
|
||||
:user/clients [{:db/id (:test @test-client-ids) :client/code "TEST" :client/locations ["DT"]}
|
||||
{:db/id (:test2 @test-client-ids) :client/code "TEST2" :client/locations ["NY"]}]}
|
||||
;; default single-client
|
||||
{:user "TEST ADMIN"
|
||||
:user/role "admin"
|
||||
:user/name "TEST ADMIN"
|
||||
:exp (time/plus (time/now) (time/days 1))
|
||||
:user/clients [{:db/id (:test @test-client-ids) :client/code "TEST" :client/locations ["DT"]}]}))
|
||||
|
||||
(defn wrap-test-auth [handler]
|
||||
(fn [request]
|
||||
@@ -48,15 +62,15 @@
|
||||
(install-functions)
|
||||
test-conn)))
|
||||
|
||||
(def test-transaction-id (atom nil))
|
||||
(def test-account-ids (atom {}))
|
||||
|
||||
(defn seed-test-data [conn]
|
||||
(let [tx-result @(dc/transact conn
|
||||
[(assoc (test-client :db/id "client-id"
|
||||
:client/code "TEST"
|
||||
:client/locations ["DT"])
|
||||
:client/bank-accounts [(test-bank-account :db/id "bank-account-id")])
|
||||
(test-client :db/id "client-id-2"
|
||||
:client/code "TEST2"
|
||||
:client/locations ["NY"])
|
||||
{:db/id "account-id"
|
||||
:account/name "Test Account"
|
||||
:account/type :account-type/expense
|
||||
@@ -113,19 +127,41 @@
|
||||
:fixed-location-account (get tempids "account-id-fixed-loc")
|
||||
:ap-account (get tempids "ap-account-id")
|
||||
:vendor (get tempids "vendor-id")})
|
||||
(reset! test-client-ids
|
||||
{:test (get tempids "client-id")
|
||||
:test2 (get tempids "client-id-2")})
|
||||
tx-entity-id))
|
||||
|
||||
(defn test-info-handler [_request]
|
||||
(defn test-info-handler [request]
|
||||
{:status 200
|
||||
:headers {"Content-Type" "application/json"}
|
||||
:body (cheshire.core/generate-string
|
||||
{:transactionId @test-transaction-id
|
||||
:accounts @test-account-ids})})
|
||||
:accounts @test-account-ids
|
||||
:clientMode @test-identity-mode
|
||||
:clients (mapv :client/code (:clients request))})})
|
||||
|
||||
(defn test-set-client-mode-handler [request]
|
||||
(let [query-string (get request :query-string "")
|
||||
params (when (seq query-string)
|
||||
(into {} (for [param (clojure.string/split query-string #"&")]
|
||||
(let [[k v] (clojure.string/split param #"=")]
|
||||
[(keyword k) (java.net.URLDecoder/decode v "UTF-8")]))))
|
||||
mode (keyword (:mode params))]
|
||||
(reset! test-identity-mode mode)
|
||||
{:status 200
|
||||
:headers {"Content-Type" "application/json"}
|
||||
:body (cheshire.core/generate-string
|
||||
{:mode mode})}))
|
||||
|
||||
(defn wrap-test-info [handler]
|
||||
(fn [request]
|
||||
(if (= "/test-info" (:uri request))
|
||||
(cond
|
||||
(= "/test-info" (:uri request))
|
||||
(test-info-handler request)
|
||||
(= "/test-set-client-mode" (:uri request))
|
||||
(test-set-client-mode-handler request)
|
||||
:else
|
||||
(handler request))))
|
||||
|
||||
(defn test-app []
|
||||
|
||||
Reference in New Issue
Block a user