making tests pass again

This commit is contained in:
Bryce Covert
2021-12-25 07:07:41 -08:00
parent 1f19357c1b
commit f7bec7a86c
5 changed files with 99 additions and 130 deletions

View File

@@ -39,11 +39,13 @@
(defn new-transaction [args]
(merge {:transaction/amount 100.0
:transaction/date #inst "2021-01-01"
:transaction/id (.toString (java.util.UUID/randomUUID))}
args))
(defn new-invoice [args]
(merge {:invoice/total 100.0
:invoice/date #inst "2021-01-01"
:invoice/invoice-number (.toString (java.util.UUID/randomUUID))}
args))
@@ -88,7 +90,7 @@
(deftest ledger-page
(testing "ledger"
(testing "it should find ledger entries"
(let [result (:ledger-page (:data (sut/query (admin-token) "{ ledger_page(client_id: null) { count, start, journal_entries { id } }}")))]
(let [result (:ledger-page (:data (sut/query (admin-token) "{ ledger_page(filters: {client_id: null}) { count, start, journal_entries { id } }}")))]
(is (int? (:count result)))
(is (int? (:start result)))
(is (seqable? (:journal-entries result)))))))
@@ -97,7 +99,7 @@
(deftest vendors
(testing "vendors"
(testing "it should find vendors"
(let [result (:ledger-page (:data (sut/query (admin-token) "{ ledger_page(client_id: null) { count, start, journal_entries { id } }}")))]
(let [result (:ledger-page (:data (sut/query (admin-token) "{ ledger_page(filters: {client_id: null}) { count, start, journal_entries { id } }}")))]
(is (int? (:count result)))
(is (int? (:start result)))
(is (seqable? (:journal-entries result)))))))
@@ -128,7 +130,7 @@
:venia/queries [{:query/data (sut/->graphql [:upsert-transaction-rule
{:transaction-rule {:accounts [{:account-id account-id
:percentage "0.25"
:location "B"}]}}
:location "Shared"}]}}
[:id ]])}]})]
(is (thrown? clojure.lang.ExceptionInfo (sut/query (admin-token) q)))))
@@ -139,7 +141,7 @@
:venia/queries [{:query/data (sut/->graphql [:upsert-transaction-rule
{:transaction-rule {:accounts [{:account-id account-id
:percentage "1.0"
:location "B"}]}}
:location "Shared"}]}}
[:id ]])}]})]
(is (thrown? clojure.lang.ExceptionInfo (sut/query (admin-token) q)))))
(testing "it should add rules"
@@ -152,10 +154,10 @@
:transaction-approval-status :approved
:accounts [{:account-id account-id
:percentage "0.5"
:location "B"}
:location "Shared"}
{:account-id account-id
:percentage "0.5"
:location "A"}]}}
:location "Shared"}]}}
[:id :description
:transaction-approval-status
[:vendor [:name]]
@@ -182,7 +184,7 @@
:accounts [{:id (-> result :accounts (get 0) :id)
:account-id account-id
:percentage "1.0"
:location "B"}]}}
:location "Shared"}]}}
[[:vendor [:name]]]])}]})
result (-> (sut/query (admin-token) q)
:data
@@ -200,7 +202,7 @@
:accounts [{:id (-> result :accounts (get 0) :id)
:account-id account-id
:percentage "1.0"
:location "B"}]}}
:location "Shared"}]}}
[[:accounts [:id :percentage [:account [:name]]]]]])}]})
result (-> (sut/query (admin-token) q)
:data
@@ -208,22 +210,6 @@
(is (= 1 (count (:accounts result))))))))))
(deftest test-get-yodlee-merchants
(testing "it should find yodlee merchants"
@(d/transact (d/connect uri)
[{:yodlee-merchant/name "Merchant 1"
:yodlee-merchant/yodlee-id "123"}
{:yodlee-merchant/name "Merchant 2"
:yodlee-merchant/yodlee-id "456"}])
(is (= [{:name "Merchant 1" :yodlee-id "123"} {:name "Merchant 2" :yodlee-id "456"}]
(-> (sut/query (admin-token) (v/graphql-query {:venia/operation {:operation/type :query
:operation/name "GetYodleeMerchants"}
:venia/queries [{:query/data (sut/->graphql [:yodlee-merchants
[:yodlee-id :name]])}]}))
:data
:yodlee-merchants)))))
(deftest test-transaction-rule
(testing "it should match rules"
@@ -236,7 +222,8 @@
:bank-account/name "1"}
:transaction/amount 1.00
:transaction/id "2019-01-05 matching-desc 1"}
:transaction/id "2019-01-05 matching-desc 1"
:db/id "a"}
{:transaction/description-original "nonmatching-desc"
:transaction/client {:client/name "2"
@@ -245,8 +232,11 @@
:bank-account/name "2"}
:transaction/date #inst "2019-01-15T23:23:00.000-08:00"
: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])
:transaction/id "2019-01-15 nonmatching-desc 2"
:db/id "b"}])
{:strs [a b client-1 client-2 bank-account-1 bank-account-2]} (get-in matching-transaction [:tempids])
a (str a)
b (str b)
rule-test (fn [rule]
(-> (sut/query (admin-token) (v/graphql-query {:venia/operation {:operation/type :query
@@ -257,27 +247,27 @@
: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 (= (set [{:id "2019-01-05 matching-desc 1"} {:id "2019-01-15 nonmatching-desc 2"}]) (set (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}))))
(is (= [{:id b}] (rule-test {:dom-gte 14 :dom-lte 16})))
(is (= [{:id b}] (rule-test {:dom-gte 14})))
(is (= (set [{:id a} {:id b}]) (set (rule-test {:dom-lte 15}))))
(is (= [{:id b}] (rule-test {:dom-gte 15})))
(is (= [{:id b}] (rule-test {:dom-gte 15 :dom-lte 15}))))
(testing "based on description"
(is (= [{:id "2019-01-05 matching-desc 1"}] (rule-test {:description "^match"}))))
(is (= [{:id a}] (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 (= (set [{:id "2019-01-05 matching-desc 1"} {:id "2019-01-15 nonmatching-desc 2"}]) (set (rule-test {:amount-gte 1.0 }))) )
(is (= (set [{:id "2019-01-05 matching-desc 1"} {:id "2019-01-15 nonmatching-desc 2"}]) (set (rule-test {:amount-lte 2.0 }))) ))
(is (= [{:id a}] (rule-test {:amount-gte 1.0 :amount-lte 1.0})))
(is (= (set [{:id a} {:id b}]) (set (rule-test {:amount-gte 1.0 }))) )
(is (= (set [{:id a} {:id b}]) (set (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}))))
(is (= [{:id a}] (rule-test {:client-id (str client-1)})))
(is (= [{:id b}] (rule-test {:client-id (str 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})))))))
(is (= [{:id a}] (rule-test {:bank-account-id (str bank-account-1)})))
(is (= [{:id b}] (rule-test {:bank-account-id (str bank-account-2)})))))))
(deftest test-match-transaction-rule
(testing "it should apply a rules"