basic ability to test.
This commit is contained in:
@@ -300,6 +300,10 @@
|
||||
:args {:client_id {:type :id}}
|
||||
: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)
|
||||
:args {:client_id {:type :id}}
|
||||
:resolve :get-invoice-stats}
|
||||
@@ -760,6 +764,7 @@
|
||||
:mutation/edit-invoice gq-invoices/edit-invoice
|
||||
: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
|
||||
:mutation/match-transaction gq-transactions/match-transaction
|
||||
:mutation/edit-client gq-clients/edit-client
|
||||
:mutation/upsert-vendor gq-vendors/upsert-vendor
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
(ns auto-ap.graphql.transaction-rules
|
||||
(:require [auto-ap.datomic.transaction-rules :as tr]
|
||||
[auto-ap.datomic.transactions :as t]
|
||||
[datomic.api :as d]
|
||||
[auto-ap.datomic :refer [remove-nils uri]]
|
||||
[auto-ap.graphql.utils :refer [->graphql <-graphql limited-clients assert-admin result->page]]))
|
||||
[auto-ap.datomic :refer [remove-nils uri merge-query]]
|
||||
[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]
|
||||
(let [args (assoc args :id (:id context))
|
||||
[journal-entries journal-entries-count] (tr/get-graphql (<-graphql 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]
|
||||
(let [transaction [(remove-nils #:transaction-rule {:db/id (if id
|
||||
id
|
||||
@@ -21,8 +24,41 @@
|
||||
:amount-gte amount_gte})]
|
||||
_ (println 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"))
|
||||
id))
|
||||
(->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]
|
||||
(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]
|
||||
(-> db
|
||||
(assoc-in [::forms id :status] nil)
|
||||
@@ -116,9 +121,7 @@
|
||||
(.preventDefault e))
|
||||
(when can-submit
|
||||
(re-frame/dispatch-sync (vec (conj submit-event params)))))}
|
||||
[:h1.title.is-2 title]
|
||||
|
||||
]
|
||||
[:h1.title.is-2 title]]
|
||||
children)))
|
||||
:raw-field (fn [control]
|
||||
(let [{:keys [data]} @(re-frame/subscribe [::form id])]
|
||||
@@ -144,3 +147,4 @@
|
||||
"disabled")
|
||||
:class (str @(re-frame/subscribe [::loading-class id])
|
||||
(when error " animated shake"))} child]))})
|
||||
|
||||
|
||||
@@ -37,7 +37,6 @@
|
||||
(re-frame/reg-event-db
|
||||
::edit-completed
|
||||
(fn [db [_ edit-transaction-rule]]
|
||||
(println edit-transaction-rule)
|
||||
(-> db
|
||||
(update-in [::page :transaction-rules]
|
||||
replace-by :id
|
||||
@@ -107,4 +106,5 @@
|
||||
[side-bar-layout {:side-bar [admin-side-bar {}]
|
||||
:main [rules-content]
|
||||
: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.forms :as forms]
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.views.components.modal :refer [modal]]
|
||||
[auto-ap.utils :refer [dollars=]]
|
||||
[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]]
|
||||
@@ -41,6 +42,33 @@
|
||||
(assoc :bank-account-id (:id (:bank-account data))))}
|
||||
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
|
||||
|
||||
(re-frame/reg-event-db
|
||||
@@ -84,6 +112,16 @@
|
||||
:on-success [::succeeded params]
|
||||
: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
|
||||
::succeeded
|
||||
[(forms/triggers-stop ::form)]
|
||||
@@ -91,6 +129,15 @@
|
||||
{:db (forms/start-form db ::form {:client @(re-frame/subscribe [::subs/client])})
|
||||
: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
|
||||
@@ -159,4 +206,30 @@
|
||||
|
||||
[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