diff --git a/src/clj/auto_ap/ssr/transaction/import.clj b/src/clj/auto_ap/ssr/transaction/import.clj index bfd1acd5..7580af6a 100644 --- a/src/clj/auto_ap/ssr/transaction/import.clj +++ b/src/clj/auto_ap/ssr/transaction/import.clj @@ -9,7 +9,9 @@ [auto-ap.graphql.utils :refer [assert-admin]] [auto-ap.import.manual :as manual] [auto-ap.import.transactions :as t] + [auto-ap.permissions :refer [wrap-must]] [auto-ap.routes.transactions :as route] + [auto-ap.routes.utils :refer [wrap-client-redirect-unauthenticated]] [auto-ap.ssr-routes :as ssr-routes] [auto-ap.ssr.components :as com] [auto-ap.ssr.form-cursor :as fc] @@ -17,16 +19,13 @@ [auto-ap.ssr.nested-form-params :refer [wrap-nested-form-params]] [auto-ap.ssr.ui :refer [base-page]] [auto-ap.ssr.utils - :refer [apply-middleware-to-all-handlers html-response strip + :refer [apply-middleware-to-all-handlers html-response wrap-form-4xx-2 wrap-schema-decode wrap-schema-enforce]] - [auto-ap.permissions :refer [wrap-must]] - [auto-ap.routes.utils :refer [wrap-client-redirect-unauthenticated]] [bidi.bidi :as bidi] [clojure.data.csv :as csv] [clojure.java.io :as io] [clojure.string :as str] [datomic.api :as dc] - [digest :as di] [malli.core :as mc] [slingshot.slingshot :refer [throw+]])) diff --git a/test/clj/auto_ap/ssr/transaction/import_test.clj b/test/clj/auto_ap/ssr/transaction/import_test.clj index 27842d05..1c8df1b7 100644 --- a/test/clj/auto_ap/ssr/transaction/import_test.clj +++ b/test/clj/auto_ap/ssr/transaction/import_test.clj @@ -72,11 +72,18 @@ (is has-errors?) (is (some (fn [[m _]] (re-find #"bank account" m)) (get-in form-errors [:table 0]))))) - (testing "Unknown client (via bank-account code) is a hard error" + (testing "Unknown client fires independently when the bank account exists but is linked to no client" + @(dc/transact conn [{:db/id "orphan-ba" + :bank-account/code "ORPHAN-CHK" + :bank-account/type :bank-account-type/check}]) (let [{:keys [form-errors has-errors?]} - (sut/classify-table [{:raw-date "01/15/2024" :amount "1.00" :bank-account-code "NOPE"}])] + (sut/classify-table [{:raw-date "01/15/2024" :amount "1.00" :bank-account-code "ORPHAN-CHK"}]) + msgs (map first (get-in form-errors [:table 0]))] (is has-errors?) - (is (some (fn [[m _]] (re-find #"client" m)) (get-in form-errors [:table 0]))))) + (is (some #(re-find #"Cannot find client" %) msgs) + "client-not-found error fires") + (is (not (some #(re-find #"bank account by code" %) msgs)) + "bank-account-not-found error does not fire because the bank account exists"))) (testing "Invalid date is a hard error" (let [{:keys [form-errors has-errors?]}