This commit is contained in:
Bryce Covert
2019-05-17 15:58:37 -07:00
parent e876dc7b6d
commit c56e5372e4
2 changed files with 12 additions and 11 deletions

View File

@@ -44,9 +44,9 @@
:db/id id
:account account_id
: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]
#_(assert-admin (:id context))
(assert-admin (:id context))
(let [existing-transaction (tr/get-by-id id)
deleted (deleted-accounts existing-transaction accounts)
account-total (reduce + 0 (map (fn [x] (:percentage x)) accounts))
@@ -93,6 +93,7 @@
(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]
(assert-admin id)
(->>
(d/query
(cond-> {:query {:find ['(pull ?e [* {:transaction/client [:client/name]

View File

@@ -27,14 +27,14 @@
(deftest ledger-page
(testing "ledger"
(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? (:start result)))
(is (seqable? (:journal-entries result)))))))
(deftest transaction-rule-page
(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
:transaction-rule-page)]
(is (int? (:count result)))
@@ -60,7 +60,7 @@
:percentage "0.25"
:location "B"}]}}
[: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"
@@ -71,7 +71,7 @@
:percentage "1.0"
:location "B"}]}}
[: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"
(let [q (v/graphql-query {:venia/operation {:operation/type :mutation
:operation/name "UpsertTransactionRule"}
@@ -91,7 +91,7 @@
[:vendor [:name]]
[:yodlee-merchant [:name]]
[:accounts [:id :percentage [:account [:name]]]]]])}]})
result (-> (sut/query nil q)
result (-> (sut/query (admin-token) q)
:data
:upsert-transaction-rule)]
@@ -114,7 +114,7 @@
:percentage "1.0"
:location "B"}]}}
[[:vendor [:name]]]])}]})
result (-> (sut/query nil q)
result (-> (sut/query (admin-token) q)
:data
:upsert-transaction-rule)]
@@ -132,7 +132,7 @@
:percentage "1.0"
:location "B"}]}}
[[:accounts [:id :percentage [:account [:name]]]]]])}]})
result (-> (sut/query nil q)
result (-> (sut/query (admin-token) q)
:data
:upsert-transaction-rule)]
@@ -147,7 +147,7 @@
:yodlee-merchant/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"}
:venia/queries [{:query/data (sut/->graphql [:yodlee-merchants
[:yodlee-id :name]])}]}))
@@ -179,7 +179,7 @@
{: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
(-> (sut/query (admin-token) (v/graphql-query {:venia/operation {:operation/type :query
:operation/name "TestTransactionRule"}
:venia/queries [{:query/data (sut/->graphql [:test-transaction-rule
{:transaction-rule rule}