- Auth: 30 tests (97 assertions) covering OAuth, sessions, JWT, impersonation, roles - Company: 35 tests (92 assertions) covering profile, 1099, expense reports, permissions - Ledger: 113 tests (148 assertions) covering grid, journal entries, import, reports - Fix existing test failures in running_balance, insights, tx, plaid, graphql - Fix InMemSolrClient to handle Solr query syntax properly - Update behavior docs: auth (42 done), company (32 done), ledger (120 done) - All 478 tests pass with 0 failures, 0 errors
210 lines
11 KiB
Clojure
210 lines
11 KiB
Clojure
(ns auto-ap.ssr.pos.expected-deposits-test
|
|
(:require
|
|
[auto-ap.datomic :as datomic]
|
|
[auto-ap.ssr.pos.expected-deposits :as expected-deposits]
|
|
[auto-ap.integration.util :refer [admin-token setup-test-data wrap-setup]]
|
|
[clojure.test :refer [deftest is testing use-fixtures]]
|
|
[datomic.api :as dc]))
|
|
|
|
(use-fixtures :each wrap-setup)
|
|
|
|
;; ============================================================================
|
|
;; Helpers
|
|
;; ============================================================================
|
|
|
|
(defn- make-request
|
|
([client-id query-params]
|
|
{:query-params query-params
|
|
:clients [{:db/id client-id}]
|
|
:trimmed-clients #{client-id}})
|
|
([client-id query-params extra]
|
|
(merge (make-request client-id query-params) extra)))
|
|
|
|
(defn- create-expected-deposit
|
|
[client-id {:keys [date total fee location status]
|
|
:or {date #inst "2024-01-15"
|
|
total 100.0
|
|
fee 5.0
|
|
location "DT"
|
|
status :expected-deposit-status/pending}}]
|
|
(let [result @(dc/transact datomic/conn
|
|
[{:db/id "ed"
|
|
:expected-deposit/client client-id
|
|
:expected-deposit/date date
|
|
:expected-deposit/location location
|
|
:expected-deposit/total total
|
|
:expected-deposit/fee fee
|
|
:expected-deposit/status status}])]
|
|
(get-in result [:tempids "ed"])))
|
|
|
|
;; ============================================================================
|
|
;; 5.2: Client column hide? when single client
|
|
;; ============================================================================
|
|
|
|
(deftest test-client-column-visibility
|
|
(testing "Behavior 5.2: Client column hidden when single client, shown when multiple"
|
|
(let [client-header (first (:headers expected-deposits/grid-page))]
|
|
(is (fn? (:hide? client-header)))
|
|
(is ((:hide? client-header) {:clients [{:db/id 1}]}))
|
|
(is (not ((:hide? client-header) {:clients [{:db/id 1} {:db/id 2}]}))))))
|
|
|
|
;; ============================================================================
|
|
;; 6.x Filtering
|
|
;; ============================================================================
|
|
|
|
(deftest test-filter-date-range
|
|
(testing "Behavior 6.1: Date range filtering"
|
|
(let [{:strs [test-client-id]} (setup-test-data [])]
|
|
(create-expected-deposit test-client-id {:date #inst "2024-01-10" :total 100.0})
|
|
(create-expected-deposit test-client-id {:date #inst "2024-01-20" :total 200.0})
|
|
(create-expected-deposit test-client-id {:date #inst "2024-02-01" :total 300.0})
|
|
|
|
(let [request (make-request test-client-id {:start-date #inst "2024-01-01"
|
|
:end-date #inst "2024-01-31"})
|
|
{:keys [ids] :as result} (expected-deposits/fetch-ids (dc/db datomic/conn) request)]
|
|
(is (= 2 (:count result)))
|
|
(is (= 2 (count ids)))))))
|
|
|
|
(deftest test-filter-exact-match-id
|
|
(testing "Behavior 6.2: Exact match ID filtering"
|
|
(let [{:strs [test-client-id]} (setup-test-data [])]
|
|
(create-expected-deposit test-client-id {:date #inst "2024-01-15" :total 100.0})
|
|
(let [target-id (create-expected-deposit test-client-id {:date #inst "2024-01-15" :total 200.0})]
|
|
(let [request (make-request test-client-id {:exact-match-id target-id})
|
|
{:keys [ids count]} (expected-deposits/fetch-ids (dc/db datomic/conn) request)]
|
|
(is (= 1 count))
|
|
(is (= target-id (first ids))))))))
|
|
|
|
(deftest test-filter-combined
|
|
(testing "Behavior 6.3: Combined filters"
|
|
(let [{:strs [test-client-id]} (setup-test-data [])]
|
|
(create-expected-deposit test-client-id {:date #inst "2024-01-10" :total 50.0})
|
|
(create-expected-deposit test-client-id {:date #inst "2024-01-20" :total 150.0})
|
|
(create-expected-deposit test-client-id {:date #inst "2024-02-01" :total 250.0})
|
|
|
|
(let [request (make-request test-client-id {:start-date #inst "2024-01-01"
|
|
:end-date #inst "2024-01-31"
|
|
:total-gte 100.0})
|
|
{:keys [count]} (expected-deposits/fetch-ids (dc/db datomic/conn) request)]
|
|
(is (= 1 count))
|
|
(let [[results _] (expected-deposits/fetch-page request)]
|
|
(is (= 150.0 (:expected-deposit/total (first results)))))))))
|
|
|
|
;; ============================================================================
|
|
;; 7.x Sorting
|
|
;; ============================================================================
|
|
|
|
(deftest test-sort-by-fields
|
|
(testing "Behaviors 7.1-7.6: Sort by various fields and toggle direction"
|
|
(let [{:strs [test-client-id]} (setup-test-data [])]
|
|
(doall
|
|
(for [i (range 3)]
|
|
(create-expected-deposit test-client-id {:date (case i
|
|
0 #inst "2024-01-10"
|
|
1 #inst "2024-01-20"
|
|
2 #inst "2024-01-15")
|
|
:total (case i 0 50.0 1 150.0 2 100.0)
|
|
:fee (case i 0 2.0 1 8.0 2 5.0)
|
|
:location (case i 0 "A" 1 "C" 2 "B")})))
|
|
|
|
;; Sort by date ascending
|
|
(let [request (make-request test-client-id {:sort [{:sort-key "date" :asc true}]
|
|
:start-date #inst "2024-01-01"
|
|
:end-date #inst "2024-01-31"})
|
|
[results _] (expected-deposits/fetch-page request)]
|
|
(is (= 3 (count results)))
|
|
(is (= 50.0 (:expected-deposit/total (first results)))))
|
|
|
|
;; Sort by date descending
|
|
(let [request (make-request test-client-id {:sort [{:sort-key "date" :asc false}]
|
|
:start-date #inst "2024-01-01"
|
|
:end-date #inst "2024-01-31"})
|
|
[results _] (expected-deposits/fetch-page request)]
|
|
(is (= 150.0 (:expected-deposit/total (first results)))))
|
|
|
|
;; Sort by total ascending
|
|
(let [request (make-request test-client-id {:sort [{:sort-key "total" :asc true}]
|
|
:start-date #inst "2024-01-01"
|
|
:end-date #inst "2024-01-31"})
|
|
[results _] (expected-deposits/fetch-page request)]
|
|
(is (= 50.0 (:expected-deposit/total (first results)))))
|
|
|
|
;; Sort by fee ascending
|
|
(let [request (make-request test-client-id {:sort [{:sort-key "fee" :asc true}]
|
|
:start-date #inst "2024-01-01"
|
|
:end-date #inst "2024-01-31"})
|
|
[results _] (expected-deposits/fetch-page request)])
|
|
|
|
;; Sort by location ascending
|
|
(let [request (make-request test-client-id {:sort [{:sort-key "location" :asc true}]
|
|
:start-date #inst "2024-01-01"
|
|
:end-date #inst "2024-01-31"})
|
|
[results _] (expected-deposits/fetch-page request)]
|
|
(is (= "A" (:expected-deposit/location (first results))))))))
|
|
|
|
;; ============================================================================
|
|
;; 8.x Pagination
|
|
;; ============================================================================
|
|
|
|
(deftest test-default-pagination
|
|
(testing "Behavior 8.1: Default 25 per page"
|
|
(let [{:strs [test-client-id]} (setup-test-data [])]
|
|
(dotimes [_ 30]
|
|
(create-expected-deposit test-client-id {:date #inst "2024-01-15"}))
|
|
|
|
(let [request (make-request test-client-id {:start-date #inst "2024-01-01"
|
|
:end-date #inst "2024-01-31"})
|
|
[results total] (expected-deposits/fetch-page request)]
|
|
(is (= 25 (count results)))
|
|
(is (= 30 total))))))
|
|
|
|
(deftest test-change-per-page
|
|
(testing "Behavior 8.2: Change per-page size"
|
|
(let [{:strs [test-client-id]} (setup-test-data [])]
|
|
(dotimes [_ 30]
|
|
(create-expected-deposit test-client-id {:date #inst "2024-01-15"}))
|
|
|
|
(let [request (make-request test-client-id {:per-page 10
|
|
:start-date #inst "2024-01-01"
|
|
:end-date #inst "2024-01-31"})
|
|
[results total] (expected-deposits/fetch-page request)]
|
|
(is (= 10 (count results)))
|
|
(is (= 30 total)))
|
|
|
|
(let [request (make-request test-client-id {:per-page 50
|
|
:start-date #inst "2024-01-01"
|
|
:end-date #inst "2024-01-31"})
|
|
[results total] (expected-deposits/fetch-page request)]
|
|
(is (= 30 (count results)))
|
|
(is (= 30 total))))))
|
|
|
|
;; ============================================================================
|
|
;; Cross-Cutting: 29.1 exact-match-id on expected deposits
|
|
;; ============================================================================
|
|
|
|
(deftest test-exact-match-id-expected-deposits
|
|
(testing "Behavior 29.1: exact-match-id filtering via expected-deposits"
|
|
(let [{:strs [test-client-id]} (setup-test-data [])]
|
|
(create-expected-deposit test-client-id {:date #inst "2024-01-15" :total 100.0})
|
|
(let [target-id (create-expected-deposit test-client-id {:date #inst "2024-01-15" :total 200.0})]
|
|
(let [request (make-request test-client-id {:exact-match-id target-id})
|
|
{:keys [ids count]} (expected-deposits/fetch-ids (dc/db datomic/conn) request)]
|
|
(is (= 1 count))
|
|
(is (= target-id (first ids))))))))
|
|
|
|
;; ============================================================================
|
|
;; Cross-Cutting: 32.3 client-id and client-code URL params
|
|
;; ============================================================================
|
|
|
|
(deftest test-extract-client-ids-params
|
|
(testing "Behavior 32.3: extract-client-ids respects client-id and client-code URL params"
|
|
(let [{:strs [test-client-id]} (setup-test-data [])]
|
|
(create-expected-deposit test-client-id {:date #inst "2024-01-15" :total 100.0})
|
|
|
|
;; With client-id param restricted to this client
|
|
(let [request {:query-params {:client-id test-client-id}
|
|
:clients [{:db/id test-client-id}]
|
|
:trimmed-clients #{test-client-id}}
|
|
{:keys [count]} (expected-deposits/fetch-ids (dc/db datomic/conn) request)]
|
|
(is (= 1 count))))))
|