transaction rules are testable not whilst editing.

This commit is contained in:
Bryce Covert
2019-06-05 19:33:41 -07:00
parent 7ac17c9cbc
commit 197397649c
6 changed files with 129 additions and 50 deletions

View File

@@ -324,6 +324,10 @@
:args {:transaction_rule {:type :edit_transaction_rule}}
:resolve :test-transaction-rule}
:run_transaction_rule {:type '(list :transaction)
:args {:transaction_rule_id {:type :id}}
:resolve :run-transaction-rule}
:invoice_stats {:type '(list :invoice_stat)
:args {:client_id {:type :id}}
:resolve :get-invoice-stats}
@@ -817,6 +821,7 @@
:mutation/edit-transaction gq-transactions/edit-transaction
:mutation/upsert-transaction-rule gq-transaction-rules/upsert-transaction-rule
:test-transaction-rule gq-transaction-rules/test-transaction-rule
:run-transaction-rule gq-transaction-rules/run-transaction-rule
:mutation/match-transaction gq-transactions/match-transaction
:mutation/match-transaction-rule gq-transactions/match-transaction-rule
:mutation/edit-client gq-clients/edit-client

View File

@@ -92,8 +92,7 @@
(defn tr [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]
(assert-admin id)
(defn -test-transaction-rule [id {:keys [:transaction-rule/description :transaction-rule/note :transaction-rule/client :transaction-rule/bank-account :transaction-rule/amount-lte :transaction-rule/amount-gte :transaction-rule/dom-lte :transaction-rule/dom-gte :transaction-rule/yodlee-merchant]}]
(->>
(d/query
(cond-> {:query {:find ['(pull ?e [* {:transaction/client [:client/name]
@@ -108,10 +107,10 @@
:where ['[?e :transaction/client ?xx]]}
:args [(set (map :db/id (limited-clients id)))]})
bank_account_id
bank-account
(merge-query {:query {:in ['?bank-account-id]
:where ['[?e :transaction/bank-account ?bank-account-id]]}
:args [bank_account_id]})
:args [(:db/id bank-account)]})
description
(merge-query {:query {:in ['?description-regex]
@@ -119,45 +118,45 @@
'[(re-find ?description-regex ?do)]]}
:args [(re-pattern description)]})
yodlee_merchant_id
yodlee-merchant
(merge-query {:query {:in ['?yodlee-merchant-id]
:where ['[?e :transaction/yodlee-merchant ?yodlee-merchant-id]]}
:args [yodlee_merchant_id]})
:args [(:db/id yodlee-merchant)]})
amount_gte
amount-gte
(merge-query {:query {:in ['?amount-gte]
:where ['[?e :transaction/amount ?ta]
'[(>= ?ta ?amount-gte)]]}
:args [amount_gte]})
:args [amount-gte]})
amount_lte
amount-lte
(merge-query {:query {:in ['?amount-lte]
:where ['[?e :transaction/amount ?ta]
'[(<= ?ta ?amount-lte)]]}
:args [amount_lte]})
:args [amount-lte]})
dom_lte
dom-lte
(merge-query {:query {:in ['?dom-lte]
:where ['[?e :transaction/date ?transaction-date]
'[(.toInstant ^java.util.Date ?transaction-date ) ?transaction-instant]
'[(.atZone ^java.time.Instant ?transaction-instant (java.time.ZoneId/of "US/Pacific")) ?transaction-local]
'[(.get ?transaction-local java.time.temporal.ChronoField/DAY_OF_MONTH) ?dom]
'[(<= ?dom ?dom-lte)]]}
:args [dom_lte]})
:args [dom-lte]})
dom_gte
dom-gte
(merge-query {:query {:in ['?dom-gte]
:where ['[?e :transaction/date ?transaction-date]
'[(.toInstant ^java.util.Date ?transaction-date ) ?transaction-instant]
'[(.atZone ^java.time.Instant ?transaction-instant (java.time.ZoneId/of "US/Pacific")) ?transaction-local]
'[(.get ?transaction-local java.time.temporal.ChronoField/DAY_OF_MONTH) ?dom]
'[(>= ?dom ?dom-gte)]]}
:args [dom_gte]})
:args [dom-gte]})
client_id
client
(merge-query {:query {:in ['?client-id]
:where ['[?e :transaction/client ?client-id]]}
:args [client_id]})
:args [(:db/id client)]})
true
(merge-query {:query {:where ['[?e :transaction/id]]}})))
@@ -168,3 +167,19 @@
(update x :transaction/date c/from-date)))
(map ->graphql))
conj [])))
(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)
(-test-transaction-rule id #:transaction-rule {:description description
:client (when client_id {:db/id client_id})
:bank-account (when bank_account_id {:db/id bank_account_id})
:amount-lte amount_lte
:amount-gte amount_gte
:dom-lte dom_lte
:dom-gte dom_gte
:yodlee-merchant (when yodlee_merchant_id {:db/id yodlee_merchant_id})}))
(defn run-transaction-rule [{:keys [id]} {:keys [transaction_rule_id]} value]
(assert-admin id)
(-test-transaction-rule id (tr/get-by-id transaction_rule_id)))