transaction rules are testable not whilst editing.
This commit is contained in:
@@ -324,6 +324,10 @@
|
|||||||
:args {:transaction_rule {:type :edit_transaction_rule}}
|
:args {:transaction_rule {:type :edit_transaction_rule}}
|
||||||
:resolve :test-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)
|
:invoice_stats {:type '(list :invoice_stat)
|
||||||
:args {:client_id {:type :id}}
|
:args {:client_id {:type :id}}
|
||||||
:resolve :get-invoice-stats}
|
:resolve :get-invoice-stats}
|
||||||
@@ -817,6 +821,7 @@
|
|||||||
:mutation/edit-transaction gq-transactions/edit-transaction
|
:mutation/edit-transaction gq-transactions/edit-transaction
|
||||||
:mutation/upsert-transaction-rule gq-transaction-rules/upsert-transaction-rule
|
:mutation/upsert-transaction-rule gq-transaction-rules/upsert-transaction-rule
|
||||||
:test-transaction-rule gq-transaction-rules/test-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 gq-transactions/match-transaction
|
||||||
:mutation/match-transaction-rule gq-transactions/match-transaction-rule
|
:mutation/match-transaction-rule gq-transactions/match-transaction-rule
|
||||||
:mutation/edit-client gq-clients/edit-client
|
:mutation/edit-client gq-clients/edit-client
|
||||||
|
|||||||
@@ -92,8 +92,7 @@
|
|||||||
(defn tr [z x]
|
(defn tr [z x]
|
||||||
(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 [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]}]
|
||||||
(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]
|
||||||
@@ -108,10 +107,10 @@
|
|||||||
:where ['[?e :transaction/client ?xx]]}
|
:where ['[?e :transaction/client ?xx]]}
|
||||||
:args [(set (map :db/id (limited-clients id)))]})
|
:args [(set (map :db/id (limited-clients id)))]})
|
||||||
|
|
||||||
bank_account_id
|
bank-account
|
||||||
(merge-query {:query {:in ['?bank-account-id]
|
(merge-query {:query {:in ['?bank-account-id]
|
||||||
:where ['[?e :transaction/bank-account ?bank-account-id]]}
|
:where ['[?e :transaction/bank-account ?bank-account-id]]}
|
||||||
:args [bank_account_id]})
|
:args [(:db/id bank-account)]})
|
||||||
|
|
||||||
description
|
description
|
||||||
(merge-query {:query {:in ['?description-regex]
|
(merge-query {:query {:in ['?description-regex]
|
||||||
@@ -119,45 +118,45 @@
|
|||||||
'[(re-find ?description-regex ?do)]]}
|
'[(re-find ?description-regex ?do)]]}
|
||||||
:args [(re-pattern description)]})
|
:args [(re-pattern description)]})
|
||||||
|
|
||||||
yodlee_merchant_id
|
yodlee-merchant
|
||||||
(merge-query {:query {:in ['?yodlee-merchant-id]
|
(merge-query {:query {:in ['?yodlee-merchant-id]
|
||||||
:where ['[?e :transaction/yodlee-merchant ?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]
|
(merge-query {:query {:in ['?amount-gte]
|
||||||
:where ['[?e :transaction/amount ?ta]
|
:where ['[?e :transaction/amount ?ta]
|
||||||
'[(>= ?ta ?amount-gte)]]}
|
'[(>= ?ta ?amount-gte)]]}
|
||||||
:args [amount_gte]})
|
:args [amount-gte]})
|
||||||
|
|
||||||
amount_lte
|
amount-lte
|
||||||
(merge-query {:query {:in ['?amount-lte]
|
(merge-query {:query {:in ['?amount-lte]
|
||||||
:where ['[?e :transaction/amount ?ta]
|
:where ['[?e :transaction/amount ?ta]
|
||||||
'[(<= ?ta ?amount-lte)]]}
|
'[(<= ?ta ?amount-lte)]]}
|
||||||
:args [amount_lte]})
|
:args [amount-lte]})
|
||||||
|
|
||||||
dom_lte
|
dom-lte
|
||||||
(merge-query {:query {:in ['?dom-lte]
|
(merge-query {:query {:in ['?dom-lte]
|
||||||
:where ['[?e :transaction/date ?transaction-date]
|
:where ['[?e :transaction/date ?transaction-date]
|
||||||
'[(.toInstant ^java.util.Date ?transaction-date ) ?transaction-instant]
|
'[(.toInstant ^java.util.Date ?transaction-date ) ?transaction-instant]
|
||||||
'[(.atZone ^java.time.Instant ?transaction-instant (java.time.ZoneId/of "US/Pacific")) ?transaction-local]
|
'[(.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]
|
'[(.get ?transaction-local java.time.temporal.ChronoField/DAY_OF_MONTH) ?dom]
|
||||||
'[(<= ?dom ?dom-lte)]]}
|
'[(<= ?dom ?dom-lte)]]}
|
||||||
:args [dom_lte]})
|
:args [dom-lte]})
|
||||||
|
|
||||||
dom_gte
|
dom-gte
|
||||||
(merge-query {:query {:in ['?dom-gte]
|
(merge-query {:query {:in ['?dom-gte]
|
||||||
:where ['[?e :transaction/date ?transaction-date]
|
:where ['[?e :transaction/date ?transaction-date]
|
||||||
'[(.toInstant ^java.util.Date ?transaction-date ) ?transaction-instant]
|
'[(.toInstant ^java.util.Date ?transaction-date ) ?transaction-instant]
|
||||||
'[(.atZone ^java.time.Instant ?transaction-instant (java.time.ZoneId/of "US/Pacific")) ?transaction-local]
|
'[(.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]
|
'[(.get ?transaction-local java.time.temporal.ChronoField/DAY_OF_MONTH) ?dom]
|
||||||
'[(>= ?dom ?dom-gte)]]}
|
'[(>= ?dom ?dom-gte)]]}
|
||||||
:args [dom_gte]})
|
:args [dom-gte]})
|
||||||
|
|
||||||
client_id
|
client
|
||||||
(merge-query {:query {:in ['?client-id]
|
(merge-query {:query {:in ['?client-id]
|
||||||
:where ['[?e :transaction/client ?client-id]]}
|
:where ['[?e :transaction/client ?client-id]]}
|
||||||
:args [client_id]})
|
:args [(:db/id client)]})
|
||||||
true
|
true
|
||||||
(merge-query {:query {:where ['[?e :transaction/id]]}})))
|
(merge-query {:query {:where ['[?e :transaction/id]]}})))
|
||||||
|
|
||||||
@@ -168,3 +167,19 @@
|
|||||||
(update x :transaction/date c/from-date)))
|
(update x :transaction/date c/from-date)))
|
||||||
(map ->graphql))
|
(map ->graphql))
|
||||||
conj [])))
|
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)))
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
[auto-ap.views.components.admin.side-bar :refer [admin-side-bar]]
|
[auto-ap.views.components.admin.side-bar :refer [admin-side-bar]]
|
||||||
[auto-ap.views.components.layouts :refer [appearing-side-bar side-bar-layout]]
|
[auto-ap.views.components.layouts :refer [appearing-side-bar side-bar-layout]]
|
||||||
[auto-ap.views.pages.admin.rules.table :as table]
|
[auto-ap.views.pages.admin.rules.table :as table]
|
||||||
|
[auto-ap.views.pages.admin.rules.results-modal :as results-modal]
|
||||||
[auto-ap.views.pages.admin.rules.form :as form]
|
[auto-ap.views.pages.admin.rules.form :as form]
|
||||||
[auto-ap.views.pages.admin.rules.common :refer [default-read]]
|
[auto-ap.views.pages.admin.rules.common :refer [default-read]]
|
||||||
[auto-ap.views.utils :refer [dispatch-event with-user]]
|
[auto-ap.views.utils :refer [dispatch-event with-user]]
|
||||||
@@ -109,4 +110,4 @@
|
|||||||
:main [rules-content]
|
:main [rules-content]
|
||||||
:right-side-bar [appearing-side-bar {:visible? active?}
|
:right-side-bar [appearing-side-bar {:visible? active?}
|
||||||
[form/form {:rule-saved [::edit-completed]}]]
|
[form/form {:rule-saved [::edit-completed]}]]
|
||||||
:bottom [form/test-results-modal]}]))
|
:bottom [results-modal/test-results-modal]}]))
|
||||||
|
|||||||
@@ -11,11 +11,13 @@
|
|||||||
[auto-ap.views.components.layouts :as layouts]
|
[auto-ap.views.components.layouts :as layouts]
|
||||||
[auto-ap.views.components.typeahead :refer [typeahead-entity]]
|
[auto-ap.views.components.typeahead :refer [typeahead-entity]]
|
||||||
[auto-ap.views.pages.admin.rules.common :refer [default-read]]
|
[auto-ap.views.pages.admin.rules.common :refer [default-read]]
|
||||||
|
[auto-ap.views.pages.admin.rules.results-modal :as results-modal]
|
||||||
[auto-ap.views.utils :refer [date->str date-picker dispatch-event standard with-user]]
|
[auto-ap.views.utils :refer [date->str date-picker dispatch-event standard with-user]]
|
||||||
[cljs-time.core :as c]
|
[cljs-time.core :as c]
|
||||||
[clojure.spec.alpha :as s]
|
[clojure.spec.alpha :as s]
|
||||||
[clojure.string :as str]
|
[clojure.string :as str]
|
||||||
[re-frame.core :as re-frame]))
|
[re-frame.core :as re-frame]
|
||||||
|
[auto-ap.views.pages.admin.rules.results-modal :as results-modal]))
|
||||||
|
|
||||||
;; SUBS
|
;; SUBS
|
||||||
|
|
||||||
@@ -83,10 +85,7 @@
|
|||||||
[:bank-account [:name]]
|
[:bank-account [:name]]
|
||||||
:description-original]]}]}))
|
:description-original]]}]}))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
|
||||||
::test-results
|
|
||||||
(fn [db]
|
|
||||||
(::test-results db)))
|
|
||||||
|
|
||||||
;; EVENTS
|
;; EVENTS
|
||||||
|
|
||||||
@@ -179,9 +178,7 @@
|
|||||||
[(forms/triggers-stop-loading ::form)]
|
[(forms/triggers-stop-loading ::form)]
|
||||||
(fn [{:keys [db]} [_ result]]
|
(fn [{:keys [db]} [_ result]]
|
||||||
|
|
||||||
(println result)
|
{:dispatch [::results-modal/opening (:test-transaction-rule result) false]}))
|
||||||
{:db (assoc db ::test-results (:test-transaction-rule result))
|
|
||||||
:dispatch [::events/modal-status ::test-results {:visible? true}]}))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -311,24 +308,3 @@
|
|||||||
[:a.button.is-medium.is-fullwidth.is-outlined {:on-click (dispatch-event [::test-clicked])} "Test Rule"]]
|
[:a.button.is-medium.is-fullwidth.is-outlined {:on-click (dispatch-event [::test-clicked])} "Test Rule"]]
|
||||||
[:div.column
|
[:div.column
|
||||||
[submit-button "Save"]]]])])
|
[submit-button "Save"]]]])])
|
||||||
|
|
||||||
(defn test-results-modal []
|
|
||||||
(when (:visible? @(re-frame/subscribe [::subs/modal-state ::test-results]))
|
|
||||||
[modal {:title "Rule results"
|
|
||||||
:hide-event [::events/modal-status ::test-results {:visible? false}]}
|
|
||||||
[:table.table.is-fullwidth.compact
|
|
||||||
[:tr
|
|
||||||
[:th "Client"]
|
|
||||||
[:th "Bank Account"]
|
|
||||||
[:th "Description"]
|
|
||||||
[:th "Date"]
|
|
||||||
[:th "Amount"]]
|
|
||||||
(for [{:keys [id client bank-account description-original date amount]} @(re-frame/subscribe [::test-results])]
|
|
||||||
|
|
||||||
^{:key id}
|
|
||||||
[:tr
|
|
||||||
[:td (:name client)]
|
|
||||||
[:td (:name bank-account)]
|
|
||||||
[:td description-original]
|
|
||||||
[:td (when date (date->str date))]
|
|
||||||
[:td amount]])]]))
|
|
||||||
|
|||||||
54
src/cljs/auto_ap/views/pages/admin/rules/results_modal.cljs
Normal file
54
src/cljs/auto_ap/views/pages/admin/rules/results_modal.cljs
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
(ns auto-ap.views.pages.admin.rules.results-modal
|
||||||
|
(:require [auto-ap.events :as events]
|
||||||
|
[auto-ap.subs :as subs]
|
||||||
|
[auto-ap.views.components.modal :refer [modal]]
|
||||||
|
[auto-ap.views.utils :refer [date->str]]
|
||||||
|
[re-frame.core :as re-frame]))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
(re-frame/reg-sub
|
||||||
|
::test-results
|
||||||
|
(fn [db]
|
||||||
|
(::test-results db)))
|
||||||
|
|
||||||
|
(re-frame/reg-sub
|
||||||
|
::runnable?
|
||||||
|
(fn [db]
|
||||||
|
(::runnable? db)))
|
||||||
|
|
||||||
|
(re-frame/reg-event-fx
|
||||||
|
::opening
|
||||||
|
(fn [{:keys [db]} [_ results runnable?]]
|
||||||
|
{:db (-> db
|
||||||
|
(assoc ::test-results results)
|
||||||
|
(assoc ::runnable? runnable?))
|
||||||
|
:dispatch [::events/modal-status ::test-results {:visible? true}]}))
|
||||||
|
|
||||||
|
|
||||||
|
(defn test-results-modal []
|
||||||
|
(let [runnable @(re-frame/subscribe [::runnable?])]
|
||||||
|
(when (:visible? @(re-frame/subscribe [::subs/modal-state ::test-results]))
|
||||||
|
[modal {:title "Rule results"
|
||||||
|
:hide-event [::events/modal-status ::test-results {:visible? false}]}
|
||||||
|
[:table.table.is-fullwidth.compact
|
||||||
|
[:tr
|
||||||
|
(when runnable
|
||||||
|
[:th {:style {:width "2em"}}])
|
||||||
|
[:th "Client"]
|
||||||
|
[:th "Bank Account"]
|
||||||
|
[:th "Description"]
|
||||||
|
[:th "Date"]
|
||||||
|
[:th "Amount"]]
|
||||||
|
(for [{:keys [id client bank-account description-original date amount]} @(re-frame/subscribe [::test-results])]
|
||||||
|
|
||||||
|
^{:key id}
|
||||||
|
[:tr
|
||||||
|
(when runnable
|
||||||
|
[:td
|
||||||
|
[:input.checkbox {:type "checkbox"}]])
|
||||||
|
[:td (:name client)]
|
||||||
|
[:td (:name bank-account)]
|
||||||
|
[:td description-original]
|
||||||
|
[:td (when date (date->str date))]
|
||||||
|
[:td amount]])]])))
|
||||||
@@ -1,11 +1,37 @@
|
|||||||
(ns auto-ap.views.pages.admin.rules.table
|
(ns auto-ap.views.pages.admin.rules.table
|
||||||
(:require [auto-ap.subs :as subs]
|
(:require [auto-ap.subs :as subs]
|
||||||
[auto-ap.views.utils :refer [dispatch-event ->$]]
|
[auto-ap.views.utils :refer [dispatch-event ->$ with-user]]
|
||||||
[auto-ap.views.pages.admin.rules.form :as form]
|
[auto-ap.views.pages.admin.rules.form :as form]
|
||||||
[auto-ap.views.components.paginator :refer [paginator]]
|
[auto-ap.views.components.paginator :refer [paginator]]
|
||||||
|
[auto-ap.views.pages.admin.rules.results-modal :as results-modal]
|
||||||
[auto-ap.views.components.sorter :refer [sorted-column]]
|
[auto-ap.views.components.sorter :refer [sorted-column]]
|
||||||
[re-frame.core :as re-frame]))
|
[re-frame.core :as re-frame]))
|
||||||
|
|
||||||
|
(re-frame/reg-event-fx
|
||||||
|
::run-clicked
|
||||||
|
[with-user]
|
||||||
|
(fn [{:keys [user db]} [_ which]]
|
||||||
|
{:graphql
|
||||||
|
{:token user
|
||||||
|
:query-obj {:venia/operation {:operation/type :query
|
||||||
|
:operation/name "RunTransactionRule"}
|
||||||
|
:venia/queries [{:query/data [:run-transaction-rule
|
||||||
|
{:transaction-rule-id (:id which)}
|
||||||
|
[:id
|
||||||
|
:date
|
||||||
|
:amount
|
||||||
|
[:client [:name]]
|
||||||
|
[:bank-account [:name]]
|
||||||
|
:description-original]]}]}
|
||||||
|
:on-success [::succeeded-run]
|
||||||
|
#_#_:on-error [:forms/save-error ::form]}}))
|
||||||
|
|
||||||
|
|
||||||
|
(re-frame/reg-event-fx
|
||||||
|
::succeeded-run
|
||||||
|
(fn [{:keys [db]} [_ result]]
|
||||||
|
{:dispatch [::results-modal/opening (:run-transaction-rule result) true]}))
|
||||||
|
|
||||||
(defn table [{:keys [id rule-page on-params-change params status]}]
|
(defn table [{:keys [id rule-page on-params-change params status]}]
|
||||||
(let [opc (fn [p]
|
(let [opc (fn [p]
|
||||||
(on-params-change (merge @params p )))]
|
(on-params-change (merge @params p )))]
|
||||||
@@ -42,7 +68,7 @@
|
|||||||
"Description"]
|
"Description"]
|
||||||
|
|
||||||
#_[sorted-column {:on-sort opc
|
#_[sorted-column {:on-sort opc
|
||||||
:style {:width "8em" :cursor "pointer"}
|
:style {:width "8em" :cukjsor "pointer"}
|
||||||
:class "has-text-right"
|
:class "has-text-right"
|
||||||
:sort-key "amount-gte"
|
:sort-key "amount-gte"
|
||||||
:sort-by sort-by
|
:sort-by sort-by
|
||||||
@@ -63,7 +89,7 @@
|
|||||||
:sort-by sort-by
|
:sort-by sort-by
|
||||||
:asc asc}
|
:asc asc}
|
||||||
"Note"]
|
"Note"]
|
||||||
[:th {:style {:width "6em"}}
|
[:th {:style {:width "9em"}}
|
||||||
]]]
|
]]]
|
||||||
[:tbody
|
[:tbody
|
||||||
(if (:loading @status)
|
(if (:loading @status)
|
||||||
@@ -90,4 +116,6 @@
|
|||||||
"")]
|
"")]
|
||||||
[:td note]
|
[:td note]
|
||||||
[:td
|
[:td
|
||||||
[:a.button {:on-click (dispatch-event [::form/editing r])} [:span.icon [:i.fa.fa-pencil]]]]]))]]]))))
|
[:div.buttons
|
||||||
|
[:a.button {:on-click (dispatch-event [::run-clicked r])} [:span.icon [:i.fa.fa-play]]]
|
||||||
|
[:a.button {:on-click (dispatch-event [::form/editing r])} [:span.icon [:i.fa.fa-pencil]]]]]]))]]]))))
|
||||||
|
|||||||
Reference in New Issue
Block a user