86 lines
5.3 KiB
Clojure
86 lines
5.3 KiB
Clojure
(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))))))
|