more api testing

This commit is contained in:
Bryce Covert
2019-05-11 10:54:21 -07:00
parent 11bac9d025
commit 8ecfd4c6ad
2 changed files with 69 additions and 3 deletions

View File

@@ -137,7 +137,7 @@
}]
(println "Conforming database...")
(println (c/ensure-conforms conn norms-map))
(c/ensure-conforms conn norms-map)
(when (not (seq args))
(d/release conn))
(println "Done")))

View File

@@ -1,8 +1,19 @@
(ns test.auto-ap.graphql
(:require [auto-ap.graphql :as sut]
[auto-ap.datomic.migrate :as m]
[venia.core :as v]
[clojure.test :as t :refer [deftest is testing]]))
[clojure.test :as t :refer [deftest is testing use-fixtures]]
[datomic.api :as d]
[auto-ap.datomic :refer [uri]]))
(defn wrap-setup
[f]
(d/create-database uri)
(m/-main false)
(f)
(d/release (d/connect uri))
(d/delete-database uri))
(use-fixtures :each wrap-setup)
(deftest query
(testing "ledger"
(testing "it should find ledger entries"
@@ -30,5 +41,60 @@
:data
:upsert-transaction-rule)]
(is (= "123" (:description result)))
(is (:id result))))))
(is (:id result))))
(testing "it should match rules based on description regex"
(let [matching-transaction @(d/transact (d/connect uri)
[{:transaction/description-original "matching-desc"
:transaction/date #inst "2019-01-05"
:transaction/client {:client/name "1"
:db/id "client-1"}
:transaction/bank-account {:db/id "bank-account-1"
:bank-account/name "1"}
:transaction/amount 1.00
:transaction/id "2019-01-05 matching-desc 1"}
{:transaction/description-original "nonmatching-desc"
:transaction/client {:client/name "2"
:db/id "client-2"}
:transaction/bank-account {:db/id "bank-account-2"
:bank-account/name "2"}
:transaction/date #inst "2019-01-15"
:transaction/amount 2.00
:transaction/id "2019-01-15 nonmatching-desc 2"}])
{:strs [client-1 client-2 bank-account-1 bank-account-2]} (get-in matching-transaction [:tempids])
rule-test (fn [rule]
(-> (sut/query nil (v/graphql-query {:venia/operation {:operation/type :query
:operation/name "TestTransactionRule"}
:venia/queries [{:query/data (sut/->graphql [:test-transaction-rule
{:transaction-rule rule}
[:id]])}]}))
:data
:test-transaction-rule))]
(testing "based on date "
(is (= [{:id "2019-01-15 nonmatching-desc 2"}] (rule-test {:dom-gte 14 :dom-lte 16})))
(is (= [{:id "2019-01-15 nonmatching-desc 2"}] (rule-test {:dom-gte 14})))
(is (= [{:id "2019-01-05 matching-desc 1"} {:id "2019-01-15 nonmatching-desc 2"}] (rule-test {:dom-lte 15})))
#_(is (= [{:id "2019-01-15 nonmatching-desc 2"}] (rule-test {:dom-gte 15})))
#_(is (= [{:id "2019-01-15 nonmatching-desc 2"}] (rule-test {:dom-gte 15 :dom-lte 15}))))
(testing "based on description"
(is (= [{:id "2019-01-05 matching-desc 1"}] (rule-test {:description "^match"}))))
(testing "based on amount"
(is (= [{:id "2019-01-05 matching-desc 1"}] (rule-test {:amount-gte 1.0 :amount-lte 1.0})))
(is (= [{:id "2019-01-05 matching-desc 1"} {:id "2019-01-15 nonmatching-desc 2"}] (rule-test {:amount-gte 1.0 })) )
(is (= [{:id "2019-01-05 matching-desc 1"} {:id "2019-01-15 nonmatching-desc 2"}] (rule-test {:amount-lte 2.0 })) ))
(testing "based on client"
(is (= [{:id "2019-01-05 matching-desc 1"}] (rule-test {:client-id client-1})))
(is (= [{:id "2019-01-15 nonmatching-desc 2"}] (rule-test {:client-id client-2}))))
(testing "based on bank account"
(is (= [{:id "2019-01-05 matching-desc 1"}] (rule-test {:bank-account-id bank-account-1})))
(is (= [{:id "2019-01-15 nonmatching-desc 2"}] (rule-test {:bank-account-id bank-account-2}))))))
))