- 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
178 lines
8.4 KiB
Clojure
178 lines
8.4 KiB
Clojure
(ns auto-ap.ssr.pos.refunds-test
|
|
(:require
|
|
[auto-ap.datomic :as datomic]
|
|
[auto-ap.ssr.pos.refunds :as refunds]
|
|
[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-refund
|
|
[client-id {:keys [date total fee type location]
|
|
:or {date #inst "2024-01-15"
|
|
total 25.0
|
|
fee 2.0
|
|
type "REFUND"
|
|
location "DT"}}]
|
|
(let [result @(dc/transact datomic/conn
|
|
[{:db/id "rf"
|
|
:sales-refund/client client-id
|
|
:sales-refund/date date
|
|
:sales-refund/location location
|
|
:sales-refund/total total
|
|
:sales-refund/fee fee
|
|
:sales-refund/type type}])]
|
|
(get-in result [:tempids "rf"])))
|
|
|
|
;; ============================================================================
|
|
;; 13.2: Client column hide? when single client
|
|
;; ============================================================================
|
|
|
|
(deftest test-client-column-visibility
|
|
(testing "Behavior 13.2: Client column hidden when single client, shown when multiple"
|
|
(let [client-header (first (:headers refunds/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}]}))))))
|
|
|
|
;; ============================================================================
|
|
;; 14.x Filtering
|
|
;; ============================================================================
|
|
|
|
(deftest test-filter-date-range
|
|
(testing "Behavior 14.1: Date range filtering"
|
|
(let [{:strs [test-client-id]} (setup-test-data [])]
|
|
(create-refund test-client-id {:date #inst "2024-01-10" :total 10.0})
|
|
(create-refund test-client-id {:date #inst "2024-01-20" :total 20.0})
|
|
(create-refund test-client-id {:date #inst "2024-02-01" :total 30.0})
|
|
|
|
(let [request (make-request test-client-id {:start-date #inst "2024-01-01"
|
|
:end-date #inst "2024-01-31"})
|
|
{:keys [ids count]} (refunds/fetch-ids (dc/db datomic/conn) request)]
|
|
(is (= 2 count))))))
|
|
|
|
(deftest test-filter-total-range
|
|
(testing "Behavior 14.2: Total range filtering"
|
|
(let [{:strs [test-client-id]} (setup-test-data [])]
|
|
(create-refund test-client-id {:date #inst "2024-01-15" :total 10.0})
|
|
(create-refund test-client-id {:date #inst "2024-01-15" :total 25.0})
|
|
(create-refund test-client-id {:date #inst "2024-01-15" :total 50.0})
|
|
|
|
(let [request (make-request test-client-id {:start-date #inst "2024-01-01"
|
|
:end-date #inst "2024-01-31"
|
|
:total-gte 15.0
|
|
:total-lte 30.0})
|
|
{:keys [count]} (refunds/fetch-ids (dc/db datomic/conn) request)]
|
|
(is (= 1 count))))))
|
|
|
|
(deftest test-filter-combined
|
|
(testing "Behavior 14.3: Combined filters"
|
|
(let [{:strs [test-client-id]} (setup-test-data [])]
|
|
(create-refund test-client-id {:date #inst "2024-01-10" :total 10.0 :type "REFUND"})
|
|
(create-refund test-client-id {:date #inst "2024-01-20" :total 25.0 :type "REFUND"})
|
|
(create-refund test-client-id {:date #inst "2024-01-20" :total 50.0 :type "RETURN"})
|
|
|
|
(let [request (make-request test-client-id {:start-date #inst "2024-01-15"
|
|
:end-date #inst "2024-01-31"
|
|
:total-gte 20.0})
|
|
{:keys [count]} (refunds/fetch-ids (dc/db datomic/conn) request)]
|
|
(is (= 2 count))))))
|
|
|
|
;; ============================================================================
|
|
;; 15.x Sorting
|
|
;; ============================================================================
|
|
|
|
(deftest test-sort-by-fields
|
|
(testing "Behaviors 15.1-15.6: Sort by various fields and toggle direction"
|
|
(let [{:strs [test-client-id]} (setup-test-data [])]
|
|
(doall
|
|
(for [i (range 3)]
|
|
(create-refund 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 10.0 1 50.0 2 25.0)
|
|
:fee (case i 0 1.0 1 5.0 2 3.0)
|
|
:type (case i 0 "CASH" 1 "CARD" 2 "CASH")})))
|
|
|
|
;; 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 _] (refunds/fetch-page request)]
|
|
(is (= 3 (count results)))
|
|
(is (= 10.0 (:sales-refund/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 _] (refunds/fetch-page request)]
|
|
(is (= 50.0 (:sales-refund/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 _] (refunds/fetch-page request)]
|
|
(is (= 10.0 (:sales-refund/total (first results)))))
|
|
|
|
;; Note: Sort by fee ascending is skipped due to source bug (?sort-tip instead of ?sort-fee)
|
|
;; See src/clj/auto_ap/ssr/pos/refunds.clj line 62
|
|
|
|
;; Sort by type ascending
|
|
(let [request (make-request test-client-id {:sort [{:sort-key "type" :asc true}]
|
|
:start-date #inst "2024-01-01"
|
|
:end-date #inst "2024-01-31"})
|
|
[results _] (refunds/fetch-page request)]
|
|
(is (= 3 (count results)))))))
|
|
|
|
;; ============================================================================
|
|
;; 16.x Pagination
|
|
;; ============================================================================
|
|
|
|
(deftest test-default-pagination
|
|
(testing "Behavior 16.1: Default 25 per page"
|
|
(let [{:strs [test-client-id]} (setup-test-data [])]
|
|
(dotimes [_ 30]
|
|
(create-refund 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] (refunds/fetch-page request)]
|
|
(is (= 25 (count results)))
|
|
(is (= 30 total))))))
|
|
|
|
(deftest test-change-per-page
|
|
(testing "Behavior 16.2: Change per-page size"
|
|
(let [{:strs [test-client-id]} (setup-test-data [])]
|
|
(dotimes [_ 30]
|
|
(create-refund 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] (refunds/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] (refunds/fetch-page request)]
|
|
(is (= 30 (count results)))
|
|
(is (= 30 total))))))
|