basic ability to test.
This commit is contained in:
@@ -300,6 +300,10 @@
|
|||||||
:args {:client_id {:type :id}}
|
:args {:client_id {:type :id}}
|
||||||
:resolve :get-expense-account-stats}
|
:resolve :get-expense-account-stats}
|
||||||
|
|
||||||
|
:test_transaction_rule {:type '(list :transaction)
|
||||||
|
:args {:transaction_rule {:type :edit_transaction_rule}}
|
||||||
|
:resolve :test-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}
|
||||||
@@ -760,6 +764,7 @@
|
|||||||
:mutation/edit-invoice gq-invoices/edit-invoice
|
:mutation/edit-invoice gq-invoices/edit-invoice
|
||||||
: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
|
||||||
:mutation/match-transaction gq-transactions/match-transaction
|
:mutation/match-transaction gq-transactions/match-transaction
|
||||||
:mutation/edit-client gq-clients/edit-client
|
:mutation/edit-client gq-clients/edit-client
|
||||||
:mutation/upsert-vendor gq-vendors/upsert-vendor
|
:mutation/upsert-vendor gq-vendors/upsert-vendor
|
||||||
|
|||||||
@@ -1,14 +1,17 @@
|
|||||||
(ns auto-ap.graphql.transaction-rules
|
(ns auto-ap.graphql.transaction-rules
|
||||||
(:require [auto-ap.datomic.transaction-rules :as tr]
|
(:require [auto-ap.datomic.transaction-rules :as tr]
|
||||||
|
[auto-ap.datomic.transactions :as t]
|
||||||
[datomic.api :as d]
|
[datomic.api :as d]
|
||||||
[auto-ap.datomic :refer [remove-nils uri]]
|
[auto-ap.datomic :refer [remove-nils uri merge-query]]
|
||||||
[auto-ap.graphql.utils :refer [->graphql <-graphql limited-clients assert-admin result->page]]))
|
[auto-ap.graphql.utils :refer [->graphql <-graphql limited-clients assert-admin result->page]]
|
||||||
|
[clj-time.coerce :as c]))
|
||||||
|
|
||||||
(defn get-transaction-rule-page [context args value]
|
(defn get-transaction-rule-page [context args value]
|
||||||
(let [args (assoc args :id (:id context))
|
(let [args (assoc args :id (:id context))
|
||||||
[journal-entries journal-entries-count] (tr/get-graphql (<-graphql args))]
|
[journal-entries journal-entries-count] (tr/get-graphql (<-graphql args))]
|
||||||
(result->page journal-entries journal-entries-count :transaction_rules args)))
|
(result->page journal-entries journal-entries-count :transaction_rules args)))
|
||||||
|
|
||||||
|
;; TODO ASSERT ADMIN
|
||||||
(defn upsert-transaction-rule [context {{:keys [id description note client_id bank_account_id amount_lte amount_gte ]} :transaction_rule :as z} value]
|
(defn upsert-transaction-rule [context {{:keys [id description note client_id bank_account_id amount_lte amount_gte ]} :transaction_rule :as z} value]
|
||||||
(let [transaction [(remove-nils #:transaction-rule {:db/id (if id
|
(let [transaction [(remove-nils #:transaction-rule {:db/id (if id
|
||||||
id
|
id
|
||||||
@@ -21,8 +24,41 @@
|
|||||||
:amount-gte amount_gte})]
|
:amount-gte amount_gte})]
|
||||||
_ (println transaction)
|
_ (println transaction)
|
||||||
transaction-result @(d/transact (d/connect uri) transaction)]
|
transaction-result @(d/transact (d/connect uri) transaction)]
|
||||||
(println "HI" (or (-> transaction-result )
|
|
||||||
id))
|
|
||||||
(-> (tr/get-by-id (or (-> transaction-result :tempids (get "transaction-rule"))
|
(-> (tr/get-by-id (or (-> transaction-result :tempids (get "transaction-rule"))
|
||||||
id))
|
id))
|
||||||
(->graphql))))
|
(->graphql))))
|
||||||
|
|
||||||
|
(defn test-transaction-rule [{:keys [id]} {{:keys [description note client_id bank_account_id amount_lte amount_gte ]} :transaction_rule :as z} value]
|
||||||
|
(->>
|
||||||
|
(d/query
|
||||||
|
(cond-> {:query {:find ['(pull ?e [* {:transaction/client [:client/name]
|
||||||
|
:transaction/bank-account [:bank-account/name]}
|
||||||
|
])]
|
||||||
|
:in ['$ ]
|
||||||
|
:where []}
|
||||||
|
:args [(d/db (d/connect uri))]}
|
||||||
|
|
||||||
|
(limited-clients id)
|
||||||
|
(merge-query {:query {:in ['[?xx ...]]
|
||||||
|
:where ['[?e :transaction/client ?xx]]}
|
||||||
|
:args [(set (map :db/id (limited-clients id)))]})
|
||||||
|
|
||||||
|
bank_account_id
|
||||||
|
(merge-query {:query {:in ['?bank-account-id]
|
||||||
|
:where ['[?e :transaction/bank-account ?bank-account-id]]}
|
||||||
|
:args [bank_account_id]})
|
||||||
|
|
||||||
|
client_id
|
||||||
|
(merge-query {:query {:in ['?client-id]
|
||||||
|
:where ['[?e :transaction/client ?client-id]]}
|
||||||
|
:args [client_id]})
|
||||||
|
true
|
||||||
|
(merge-query {:query {:where ['[?e :transaction/id]]}})))
|
||||||
|
(transduce (comp
|
||||||
|
(take 15)
|
||||||
|
(map first)
|
||||||
|
(map (fn [x]
|
||||||
|
(update x :transaction/date c/from-date)))
|
||||||
|
(map ->graphql))
|
||||||
|
conj
|
||||||
|
[])))
|
||||||
|
|||||||
@@ -99,6 +99,11 @@
|
|||||||
(fn [db event]
|
(fn [db event]
|
||||||
(stop-form db form))))
|
(stop-form db form))))
|
||||||
|
|
||||||
|
(defn triggers-stop-loading [form]
|
||||||
|
(re-frame/enrich
|
||||||
|
(fn [db event]
|
||||||
|
(assoc-in db [::forms form :status] nil))))
|
||||||
|
|
||||||
(defn save-succeeded [db id]
|
(defn save-succeeded [db id]
|
||||||
(-> db
|
(-> db
|
||||||
(assoc-in [::forms id :status] nil)
|
(assoc-in [::forms id :status] nil)
|
||||||
@@ -116,9 +121,7 @@
|
|||||||
(.preventDefault e))
|
(.preventDefault e))
|
||||||
(when can-submit
|
(when can-submit
|
||||||
(re-frame/dispatch-sync (vec (conj submit-event params)))))}
|
(re-frame/dispatch-sync (vec (conj submit-event params)))))}
|
||||||
[:h1.title.is-2 title]
|
[:h1.title.is-2 title]]
|
||||||
|
|
||||||
]
|
|
||||||
children)))
|
children)))
|
||||||
:raw-field (fn [control]
|
:raw-field (fn [control]
|
||||||
(let [{:keys [data]} @(re-frame/subscribe [::form id])]
|
(let [{:keys [data]} @(re-frame/subscribe [::form id])]
|
||||||
@@ -144,3 +147,4 @@
|
|||||||
"disabled")
|
"disabled")
|
||||||
:class (str @(re-frame/subscribe [::loading-class id])
|
:class (str @(re-frame/subscribe [::loading-class id])
|
||||||
(when error " animated shake"))} child]))})
|
(when error " animated shake"))} child]))})
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,6 @@
|
|||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-db
|
||||||
::edit-completed
|
::edit-completed
|
||||||
(fn [db [_ edit-transaction-rule]]
|
(fn [db [_ edit-transaction-rule]]
|
||||||
(println edit-transaction-rule)
|
|
||||||
(-> db
|
(-> db
|
||||||
(update-in [::page :transaction-rules]
|
(update-in [::page :transaction-rules]
|
||||||
replace-by :id
|
replace-by :id
|
||||||
@@ -107,4 +106,5 @@
|
|||||||
[side-bar-layout {:side-bar [admin-side-bar {}]
|
[side-bar-layout {:side-bar [admin-side-bar {}]
|
||||||
: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]}]))
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
[auto-ap.events :as events]
|
[auto-ap.events :as events]
|
||||||
[auto-ap.forms :as forms]
|
[auto-ap.forms :as forms]
|
||||||
[auto-ap.subs :as subs]
|
[auto-ap.subs :as subs]
|
||||||
|
[auto-ap.views.components.modal :refer [modal]]
|
||||||
[auto-ap.utils :refer [dollars=]]
|
[auto-ap.utils :refer [dollars=]]
|
||||||
[auto-ap.views.components.dropdown :refer [drop-down]]
|
[auto-ap.views.components.dropdown :refer [drop-down]]
|
||||||
[auto-ap.views.components.expense-accounts-field :as expense-accounts-field :refer [expense-accounts-field recalculate-amounts]]
|
[auto-ap.views.components.expense-accounts-field :as expense-accounts-field :refer [expense-accounts-field recalculate-amounts]]
|
||||||
@@ -41,6 +42,33 @@
|
|||||||
(assoc :bank-account-id (:id (:bank-account data))))}
|
(assoc :bank-account-id (:id (:bank-account data))))}
|
||||||
default-read]}]}))
|
default-read]}]}))
|
||||||
|
|
||||||
|
(re-frame/reg-sub
|
||||||
|
::test-query
|
||||||
|
:<- [::forms/form ::form]
|
||||||
|
(fn [{:keys [data] }]
|
||||||
|
{:venia/operation {:operation/type :query
|
||||||
|
:operation/name "TestTransactionRule"}
|
||||||
|
:venia/queries [{:query/data [:test-transaction-rule
|
||||||
|
{:transaction-rule (-> data
|
||||||
|
(select-keys [:id
|
||||||
|
:description
|
||||||
|
:amount-lte
|
||||||
|
:amount-gte
|
||||||
|
:note])
|
||||||
|
(assoc :client-id (:id (:client data)))
|
||||||
|
(assoc :bank-account-id (:id (:bank-account data))))}
|
||||||
|
[:id
|
||||||
|
:date
|
||||||
|
:amount
|
||||||
|
[:client [:name]]
|
||||||
|
[:bank-account [:name]]
|
||||||
|
:description-original]]}]}))
|
||||||
|
|
||||||
|
(re-frame/reg-sub
|
||||||
|
::test-results
|
||||||
|
(fn [db]
|
||||||
|
(::test-results db)))
|
||||||
|
|
||||||
;; EVENTS
|
;; EVENTS
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-db
|
||||||
@@ -84,6 +112,16 @@
|
|||||||
:on-success [::succeeded params]
|
:on-success [::succeeded params]
|
||||||
:on-error [::forms/save-error ::form]}}))
|
:on-error [::forms/save-error ::form]}}))
|
||||||
|
|
||||||
|
(re-frame/reg-event-fx
|
||||||
|
::test-clicked
|
||||||
|
[with-user (forms/triggers-loading ::form) (forms/in-form ::form)]
|
||||||
|
(fn [{:keys [user] {:keys [data]} :db} [_ params]]
|
||||||
|
{:graphql
|
||||||
|
{:token user
|
||||||
|
:query-obj @(re-frame/subscribe [::test-query])
|
||||||
|
:on-success [::succeeded-test]
|
||||||
|
:on-error [::forms/save-error ::form]}}))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::succeeded
|
::succeeded
|
||||||
[(forms/triggers-stop ::form)]
|
[(forms/triggers-stop ::form)]
|
||||||
@@ -91,6 +129,15 @@
|
|||||||
{:db (forms/start-form db ::form {:client @(re-frame/subscribe [::subs/client])})
|
{:db (forms/start-form db ::form {:client @(re-frame/subscribe [::subs/client])})
|
||||||
:dispatch (conj rule-saved (:upsert-transaction-rule result))}))
|
:dispatch (conj rule-saved (:upsert-transaction-rule result))}))
|
||||||
|
|
||||||
|
(re-frame/reg-event-fx
|
||||||
|
::succeeded-test
|
||||||
|
[(forms/triggers-stop-loading ::form)]
|
||||||
|
(fn [{:keys [db]} [_ result]]
|
||||||
|
|
||||||
|
(println result)
|
||||||
|
{:db (assoc db ::test-results (:test-transaction-rule result))
|
||||||
|
:dispatch [::events/modal-status ::test-results {:visible? true}]}))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
;; VIEWS
|
;; VIEWS
|
||||||
@@ -159,4 +206,30 @@
|
|||||||
|
|
||||||
[error-notification]
|
[error-notification]
|
||||||
|
|
||||||
[submit-button "Save"]])])
|
[:div.columns
|
||||||
|
[:div.column
|
||||||
|
[:a.button.is-medium.is-fullwidth.is-outlined {:on-click (dispatch-event [::test-clicked])} "Test Rule"]]
|
||||||
|
[:div.column
|
||||||
|
[submit-button "Save"]]]])])
|
||||||
|
|
||||||
|
(defn test-results-modal []
|
||||||
|
(when (:visible? @(re-frame/subscribe [::subs/modal-state ::test-results]))
|
||||||
|
(println "TEST" @(re-frame/subscribe [::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]])]]))
|
||||||
|
|||||||
Reference in New Issue
Block a user