progress on making check tests work.

This commit is contained in:
2023-03-24 16:11:18 -07:00
parent 21f4dee7b2
commit 8508fbe70c
2 changed files with 87 additions and 1 deletions

View File

@@ -491,7 +491,8 @@
(defn void-payment [context {id :payment_id} _] (defn void-payment [context {id :payment_id} _]
(let [check (d-checks/get-by-id id)] (let [check (d-checks/get-by-id id)]
(assert (or (= :payment-status/pending (:payment/status check)) (assert (or (= :payment-status/pending (:payment/status check))
(#{:payment-type/cash :payment-type/debit :payment-type/balance-credit} (:payment/type check)))) (#{:payment-type/cash :payment-type/debit :payment-type/balance-credit} (:payment/type check)))
(pr-str check))
(assert-can-see-client (:id context) (:db/id (:payment/client check))) (assert-can-see-client (:id context) (:db/id (:payment/client check)))
(assert-not-locked (:db/id (:payment/client check)) (:payment/date check)) (assert-not-locked (:db/id (:payment/client check)) (:payment/date check))
(let [removing-payments (mapcat (fn [x] (let [removing-payments (mapcat (fn [x]

View File

@@ -0,0 +1,85 @@
(ns auto-ap.integration.graphql.checks
(:require
[auto-ap.time-reader]
[auto-ap.datomic :refer [conn uri]]
[auto-ap.graphql.checks :as sut]
[auto-ap.integration.util :refer [admin-token user-token wrap-setup]]
[clojure.test :as t :refer [deftest is testing use-fixtures]]
[com.brunobonacci.mulog :as mu]
[datomic.api :as d]))
(use-fixtures :each wrap-setup)
(deftest get-payment-page
(testing "Should list payments"
(let [{{:strs [bank-id check-id client-id]} :tempids} @(d/transact conn [{:bank-account/code "bank"
:db/id "bank-id"}
{:client/code "client"
:db/id "client-id"}
{:db/id "check-id"
:payment/check-number 1000
:payment/bank-account "bank-id"
:payment/client "client-id"
:payment/type :payment-type/check
:payment/amount 123.50
:payment/paid-to "Someone"
:payment/status :payment-status/pending
:payment/date #inst "2022-01-01"}])]
(is (= [ {:amount 123.5,
:type :check,
:bank_account {:id bank-id, :code "bank"},
:client {:id client-id, :code "client"},
:status :pending,
:id check-id,
:paid_to "Someone",
:_payment [],
:check_number 1000}],
(map #(dissoc % :date) (:payments (first (sut/get-payment-page {:id (admin-token)} {} nil))))))
(testing "Should omit clients that can't be seen"
(is (not (seq (:payments (first (sut/get-payment-page {:id (user-token -1)} {} nil))))))
(is (not (seq (:payments (first (sut/get-payment-page {:id (user-token -1)} {:filters {:client_id client-id}} nil)))))))
(testing "Should include clients that can be seen"
(is (-> (sut/get-payment-page {:id (user-token client-id)} {} nil)
first
:payments
seq)))
(testing "Should filter to date ranges"
(is (-> (sut/get-payment-page {:id (user-token client-id)} {:filters {:date_range {:start #inst "2000-01-01"}}} nil)
first
:payments
seq))
(is (-> (sut/get-payment-page {:id (user-token client-id)} {:filters {:date_range {:start #inst "2022-01-01"}}} nil)
first
:payments
seq))
(is (not (-> (sut/get-payment-page {:id (user-token client-id)} {:filters {:date_range {:start #inst "2022-01-02"}}} nil)
first
:payments
seq)))
(is (-> (sut/get-payment-page {:id (user-token client-id)} {:filters {:date_range {:end #inst "2022-01-02"}}} nil)
first
:payments
seq))))
)
(testing "Should void payments"
(let [{{:strs [bank-id check-id client-id]} :tempids} @(d/transact conn [{:bank-account/code "bank"
:db/id "bank-id"}
{:client/code "client"
:db/id "client-id"}
{:db/id "check-id"
:payment/check-number 1000
:payment/bank-account "bank-id"
:payment/client "client-id"
:payment/type :payment-type/check
:payment/amount 123.50
:payment/paid-to "Someone"
:payment/status :payment-status/pending
:payment/date #inst "2022-01-01"}])]
(sut/void-payment {:id (admin-token)} {:payment_id check-id} nil)
(is (= :payment-status/voided (-> (d/pull (d/db conn) [{:payment/status [:db/ident ]}] check-id)
:payment/status
:db/ident))))))