This commit is contained in:
2023-03-27 07:51:53 -07:00
3 changed files with 76 additions and 3 deletions

View File

@@ -1,9 +1,14 @@
(ns auto-ap.integration.graphql.checks (ns auto-ap.integration.graphql.checks
(:require (:require
[auto-ap.time-reader] [auto-ap.datomic :refer [conn]]
[auto-ap.datomic :refer [conn uri]]
[auto-ap.graphql.checks :as sut] [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]] [clojure.test :as t :refer [deftest is testing use-fixtures]]
[com.brunobonacci.mulog :as mu] [com.brunobonacci.mulog :as mu]
[datomic.client.api :as d])) [datomic.client.api :as d]))
@@ -297,3 +302,48 @@
first first
:payment :payment
:s3_url)))))))) :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)))))))

View File

@@ -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)))))))

View File

@@ -90,6 +90,7 @@
(defn test-transaction-rule [& kwargs] (defn test-transaction-rule [& kwargs]
(apply assoc {:db/id "test-transaction-rule-id" (apply assoc {:db/id "test-transaction-rule-id"
:transaction-rule/client "test-client-id" :transaction-rule/client "test-client-id"
:transaction-rule/transaction-approval-status :transaction-approval-status/approved
:transaction-rule/note "Test"} :transaction-rule/note "Test"}
kwargs)) kwargs))