testing.
This commit is contained in:
@@ -44,9 +44,9 @@
|
|||||||
:db/id id
|
:db/id id
|
||||||
:account account_id
|
:account account_id
|
||||||
:location location}))
|
:location location}))
|
||||||
;; TODO ASSERT ADMIN
|
|
||||||
(defn upsert-transaction-rule [context {{:keys [id description yodlee_merchant_id note client_id bank_account_id amount_lte amount_gte vendor_id accounts transaction_approval_status dom_gte dom_lte]} :transaction_rule :as z} value]
|
(defn upsert-transaction-rule [context {{:keys [id description yodlee_merchant_id note client_id bank_account_id amount_lte amount_gte vendor_id accounts transaction_approval_status dom_gte dom_lte]} :transaction_rule :as z} value]
|
||||||
#_(assert-admin (:id context))
|
(assert-admin (:id context))
|
||||||
(let [existing-transaction (tr/get-by-id id)
|
(let [existing-transaction (tr/get-by-id id)
|
||||||
deleted (deleted-accounts existing-transaction accounts)
|
deleted (deleted-accounts existing-transaction accounts)
|
||||||
account-total (reduce + 0 (map (fn [x] (:percentage x)) accounts))
|
account-total (reduce + 0 (map (fn [x] (:percentage x)) accounts))
|
||||||
@@ -93,6 +93,7 @@
|
|||||||
(re-find (re-pattern z) x))
|
(re-find (re-pattern z) x))
|
||||||
|
|
||||||
(defn test-transaction-rule [{:keys [id]} {{:keys [description note client_id bank_account_id amount_lte amount_gte dom_lte dom_gte yodlee_merchant_id]} :transaction_rule :as z} value]
|
(defn test-transaction-rule [{:keys [id]} {{:keys [description note client_id bank_account_id amount_lte amount_gte dom_lte dom_gte yodlee_merchant_id]} :transaction_rule :as z} value]
|
||||||
|
(assert-admin id)
|
||||||
(->>
|
(->>
|
||||||
(d/query
|
(d/query
|
||||||
(cond-> {:query {:find ['(pull ?e [* {:transaction/client [:client/name]
|
(cond-> {:query {:find ['(pull ?e [* {:transaction/client [:client/name]
|
||||||
|
|||||||
@@ -27,14 +27,14 @@
|
|||||||
(deftest ledger-page
|
(deftest ledger-page
|
||||||
(testing "ledger"
|
(testing "ledger"
|
||||||
(testing "it should find ledger entries"
|
(testing "it should find ledger entries"
|
||||||
(let [result (:ledger-page (:data (sut/query nil "{ ledger_page(client_id: null) { count, start, journal_entries { id } }}")))]
|
(let [result (:ledger-page (:data (sut/query (admin-token) "{ ledger_page(client_id: null) { count, start, journal_entries { id } }}")))]
|
||||||
(is (int? (:count result)))
|
(is (int? (:count result)))
|
||||||
(is (int? (:start result)))
|
(is (int? (:start result)))
|
||||||
(is (seqable? (:journal-entries result)))))))
|
(is (seqable? (:journal-entries result)))))))
|
||||||
|
|
||||||
(deftest transaction-rule-page
|
(deftest transaction-rule-page
|
||||||
(testing "it should find rules"
|
(testing "it should find rules"
|
||||||
(let [result (-> (sut/query nil "{ transaction_rule_page(client_id: null) { count, start, transaction_rules { id } }}")
|
(let [result (-> (sut/query (admin-token) "{ transaction_rule_page(client_id: null) { count, start, transaction_rules { id } }}")
|
||||||
:data
|
:data
|
||||||
:transaction-rule-page)]
|
:transaction-rule-page)]
|
||||||
(is (int? (:count result)))
|
(is (int? (:count result)))
|
||||||
@@ -60,7 +60,7 @@
|
|||||||
:percentage "0.25"
|
:percentage "0.25"
|
||||||
:location "B"}]}}
|
:location "B"}]}}
|
||||||
[:id ]])}]})]
|
[:id ]])}]})]
|
||||||
(is (thrown? clojure.lang.ExceptionInfo (sut/query nil q)))))
|
(is (thrown? clojure.lang.ExceptionInfo (sut/query (admin-token) q)))))
|
||||||
|
|
||||||
|
|
||||||
(testing "It should reject rules that are missing both description and merchant"
|
(testing "It should reject rules that are missing both description and merchant"
|
||||||
@@ -71,7 +71,7 @@
|
|||||||
:percentage "1.0"
|
:percentage "1.0"
|
||||||
:location "B"}]}}
|
:location "B"}]}}
|
||||||
[:id ]])}]})]
|
[:id ]])}]})]
|
||||||
(is (thrown? clojure.lang.ExceptionInfo (sut/query nil q)))))
|
(is (thrown? clojure.lang.ExceptionInfo (sut/query (admin-token) q)))))
|
||||||
(testing "it should add rules"
|
(testing "it should add rules"
|
||||||
(let [q (v/graphql-query {:venia/operation {:operation/type :mutation
|
(let [q (v/graphql-query {:venia/operation {:operation/type :mutation
|
||||||
:operation/name "UpsertTransactionRule"}
|
:operation/name "UpsertTransactionRule"}
|
||||||
@@ -91,7 +91,7 @@
|
|||||||
[:vendor [:name]]
|
[:vendor [:name]]
|
||||||
[:yodlee-merchant [:name]]
|
[:yodlee-merchant [:name]]
|
||||||
[:accounts [:id :percentage [:account [:name]]]]]])}]})
|
[:accounts [:id :percentage [:account [:name]]]]]])}]})
|
||||||
result (-> (sut/query nil q)
|
result (-> (sut/query (admin-token) q)
|
||||||
:data
|
:data
|
||||||
:upsert-transaction-rule)]
|
:upsert-transaction-rule)]
|
||||||
|
|
||||||
@@ -114,7 +114,7 @@
|
|||||||
:percentage "1.0"
|
:percentage "1.0"
|
||||||
:location "B"}]}}
|
:location "B"}]}}
|
||||||
[[:vendor [:name]]]])}]})
|
[[:vendor [:name]]]])}]})
|
||||||
result (-> (sut/query nil q)
|
result (-> (sut/query (admin-token) q)
|
||||||
:data
|
:data
|
||||||
:upsert-transaction-rule)]
|
:upsert-transaction-rule)]
|
||||||
|
|
||||||
@@ -132,7 +132,7 @@
|
|||||||
:percentage "1.0"
|
:percentage "1.0"
|
||||||
:location "B"}]}}
|
:location "B"}]}}
|
||||||
[[:accounts [:id :percentage [:account [:name]]]]]])}]})
|
[[:accounts [:id :percentage [:account [:name]]]]]])}]})
|
||||||
result (-> (sut/query nil q)
|
result (-> (sut/query (admin-token) q)
|
||||||
:data
|
:data
|
||||||
:upsert-transaction-rule)]
|
:upsert-transaction-rule)]
|
||||||
|
|
||||||
@@ -147,7 +147,7 @@
|
|||||||
:yodlee-merchant/yodlee-id "456"}])
|
:yodlee-merchant/yodlee-id "456"}])
|
||||||
|
|
||||||
(is (= [{:name "Merchant 1" :yodlee-id "123"} {:name "Merchant 2" :yodlee-id "456"}]
|
(is (= [{:name "Merchant 1" :yodlee-id "123"} {:name "Merchant 2" :yodlee-id "456"}]
|
||||||
(-> (sut/query nil (v/graphql-query {:venia/operation {:operation/type :query
|
(-> (sut/query (admin-token) (v/graphql-query {:venia/operation {:operation/type :query
|
||||||
:operation/name "GetYodleeMerchants"}
|
:operation/name "GetYodleeMerchants"}
|
||||||
:venia/queries [{:query/data (sut/->graphql [:yodlee-merchants
|
:venia/queries [{:query/data (sut/->graphql [:yodlee-merchants
|
||||||
[:yodlee-id :name]])}]}))
|
[:yodlee-id :name]])}]}))
|
||||||
@@ -179,7 +179,7 @@
|
|||||||
{:strs [client-1 client-2 bank-account-1 bank-account-2]} (get-in matching-transaction [:tempids])
|
{:strs [client-1 client-2 bank-account-1 bank-account-2]} (get-in matching-transaction [:tempids])
|
||||||
|
|
||||||
rule-test (fn [rule]
|
rule-test (fn [rule]
|
||||||
(-> (sut/query nil (v/graphql-query {:venia/operation {:operation/type :query
|
(-> (sut/query (admin-token) (v/graphql-query {:venia/operation {:operation/type :query
|
||||||
:operation/name "TestTransactionRule"}
|
:operation/name "TestTransactionRule"}
|
||||||
:venia/queries [{:query/data (sut/->graphql [:test-transaction-rule
|
:venia/queries [{:query/data (sut/->graphql [:test-transaction-rule
|
||||||
{:transaction-rule rule}
|
{:transaction-rule rule}
|
||||||
|
|||||||
Reference in New Issue
Block a user