diff --git a/test/clj/auto_ap/integration/graphql/checks.clj b/test/clj/auto_ap/integration/graphql/checks.clj index ca5797c9..f49bdafe 100644 --- a/test/clj/auto_ap/integration/graphql/checks.clj +++ b/test/clj/auto_ap/integration/graphql/checks.clj @@ -1,11 +1,15 @@ (ns auto-ap.integration.graphql.checks (:require - [auto-ap.time-reader] - [auto-ap.datomic :refer [conn uri]] + [auto-ap.datomic :refer [conn]] [auto-ap.graphql.checks :as sut] - [auto-ap.integration.util :refer [admin-token user-token wrap-setup]] + [auto-ap.integration.util + :refer [admin-token + setup-test-data + test-payment + test-transaction + 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) @@ -297,3 +301,48 @@ first :payment :s3_url)))))))) + + +(deftest get-potential-payments + (testing "should match payments for a transaction" + (let [{:strs [transaction-id + payment-id]} (setup-test-data [(test-payment + :db/id "payment-id" + :payment/status :payment-status/pending + :payment/amount 100.0 + :payment/date #inst "2021-05-25") + (test-transaction + :db/id "transaction-id" + :transaction/amount -100.0 + :transaction/date #inst "2021-06-01")])] + (is (= [payment-id] (->> (sut/get-potential-payments {:id (admin-token)} + {:transaction_id transaction-id} + nil) + (map :id)))))) + (testing "Should always order most recent payments first" + (let [{:strs [transaction-id + older-payment-id + newer-payment-id]} (setup-test-data [(test-payment + :db/id "newer-payment-id" + :payment/status :payment-status/pending + :payment/amount 100.0 + :payment/date #inst "2021-05-25") + (test-payment + :db/id "older-payment-id" + :payment/status :payment-status/pending + :payment/amount 100.0 + :payment/date #inst "2021-05-20") + (test-payment + :db/id "payment-too-old-id" + :payment/status :payment-status/pending + :payment/amount 100.0 + :payment/date #inst "2021-01-01") + (test-transaction + :db/id "transaction-id" + :transaction/amount -100.0 + :transaction/date #inst "2021-06-01")])] + (is (= [newer-payment-id + older-payment-id] (->> (sut/get-potential-payments {:id (admin-token)} + {:transaction_id transaction-id} + nil) + (map :id))))))) diff --git a/test/clj/auto_ap/integration/graphql/transaction_rules.clj b/test/clj/auto_ap/integration/graphql/transaction_rules.clj new file mode 100644 index 00000000..02a66eaf --- /dev/null +++ b/test/clj/auto_ap/integration/graphql/transaction_rules.clj @@ -0,0 +1,22 @@ +(ns auto-ap.integration.graphql.transaction-rules + (:require + [auto-ap.graphql.transaction-rules :as sut2] + [auto-ap.integration.util + :refer [setup-test-data test-transaction test-transaction-rule wrap-setup admin-token]] + [clojure.test :as t :refer [deftest testing use-fixtures is]])) + +(use-fixtures :each wrap-setup) + +(deftest get-transaction-rule-matches + (testing "Should find a single rule that matches a transaction" + (let [{:strs [transaction-id + transaction-rule-id]} (setup-test-data [(test-transaction + :db/id "transaction-id" + :transaction/description-original "Disneyland") + (test-transaction-rule + :db/id "transaction-rule-id" + :transaction-rule/description ".*")])] + (is (= [transaction-rule-id] (->> (sut2/get-transaction-rule-matches {:id (admin-token)} + {:transaction_id transaction-id} + nil) + (map :id))))))) diff --git a/test/clj/auto_ap/integration/util.clj b/test/clj/auto_ap/integration/util.clj index 03b01977..a351ec68 100644 --- a/test/clj/auto_ap/integration/util.clj +++ b/test/clj/auto_ap/integration/util.clj @@ -92,6 +92,7 @@ (defn test-transaction-rule [& kwargs] (apply assoc {:db/id "test-transaction-rule-id" :transaction-rule/client "test-client-id" + :transaction-rule/transaction-approval-status :transaction-approval-status/approved :transaction-rule/note "Test"} kwargs))