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