Replacing when matching.
This commit is contained in:
@@ -130,12 +130,15 @@
|
|||||||
(throw (ex-info "Transaction already associated with a payment" {:validation-error "Transaction already associated with a payment"})))
|
(throw (ex-info "Transaction already associated with a payment" {:validation-error "Transaction already associated with a payment"})))
|
||||||
|
|
||||||
@(d/transact (d/connect uri)
|
@(d/transact (d/connect uri)
|
||||||
[(rm/apply-rule {:db/id (:db/id transaction)
|
(into
|
||||||
:transaction/amount (:transaction/amount transaction)}
|
[(remove-nils (rm/apply-rule {:db/id (:db/id transaction)
|
||||||
transaction-rule
|
:transaction/amount (:transaction/amount transaction)}
|
||||||
|
transaction-rule
|
||||||
|
|
||||||
;; TODO use bank account locations as well
|
;; TODO use bank account locations as well
|
||||||
(-> transaction :transaction/client :client/locations))]))
|
(-> transaction :transaction/client :client/locations)))]
|
||||||
|
(map (fn [x] [:db/retractEntity (:db/id x)] )
|
||||||
|
(:transaction/accounts transaction)))))
|
||||||
(-> (d-transactions/get-by-id transaction_id)
|
(-> (d-transactions/get-by-id transaction_id)
|
||||||
approval-status->graphql
|
approval-status->graphql
|
||||||
->graphql))
|
->graphql))
|
||||||
|
|||||||
@@ -3,8 +3,11 @@
|
|||||||
[auto-ap.datomic.migrate :as m]
|
[auto-ap.datomic.migrate :as m]
|
||||||
[venia.core :as v]
|
[venia.core :as v]
|
||||||
[clojure.test :as t :refer [deftest is testing use-fixtures]]
|
[clojure.test :as t :refer [deftest is testing use-fixtures]]
|
||||||
|
[clj-time.core :as time]
|
||||||
[datomic.api :as d]
|
[datomic.api :as d]
|
||||||
[auto-ap.datomic :refer [uri]]))
|
[auto-ap.datomic :refer [uri]]
|
||||||
|
[buddy.sign.jwt :as jwt]
|
||||||
|
[config.core :refer [env]]))
|
||||||
(defn wrap-setup
|
(defn wrap-setup
|
||||||
[f]
|
[f]
|
||||||
(with-redefs [auto-ap.datomic/uri "datomic:mem://datomic-transactor:4334/invoice"]
|
(with-redefs [auto-ap.datomic/uri "datomic:mem://datomic-transactor:4334/invoice"]
|
||||||
@@ -14,6 +17,12 @@
|
|||||||
(d/release (d/connect uri))
|
(d/release (d/connect uri))
|
||||||
(d/delete-database uri)))
|
(d/delete-database uri)))
|
||||||
|
|
||||||
|
(defn admin-token []
|
||||||
|
{:user "TEST ADMIN"
|
||||||
|
:exp (time/plus (time/now) (time/days 1))
|
||||||
|
:user/role "admin"
|
||||||
|
:user/name "TEST ADMIN"})
|
||||||
|
|
||||||
(use-fixtures :each wrap-setup)
|
(use-fixtures :each wrap-setup)
|
||||||
(deftest ledger-page
|
(deftest ledger-page
|
||||||
(testing "ledger"
|
(testing "ledger"
|
||||||
@@ -200,3 +209,46 @@
|
|||||||
(is (= [{:id "2019-01-05 matching-desc 1"}] (rule-test {:bank-account-id bank-account-1})))
|
(is (= [{:id "2019-01-05 matching-desc 1"}] (rule-test {:bank-account-id bank-account-1})))
|
||||||
(is (= [{:id "2019-01-15 nonmatching-desc 2"}] (rule-test {:bank-account-id bank-account-2})))))))
|
(is (= [{:id "2019-01-15 nonmatching-desc 2"}] (rule-test {:bank-account-id bank-account-2})))))))
|
||||||
|
|
||||||
|
(deftest test-match-transaction-rule
|
||||||
|
(testing "it should apply a rules"
|
||||||
|
(let [{:strs [transaction-id transaction-rule-id]} (-> @(d/transact (d/connect uri)
|
||||||
|
[{:transaction/description-original "matching-desc"
|
||||||
|
:transaction/date #inst "2019-01-05T00:00:00.000-08:00"
|
||||||
|
:transaction/client {:client/name "1"
|
||||||
|
:db/id "client-1"}
|
||||||
|
:transaction/bank-account {:db/id "bank-account-1"
|
||||||
|
:bank-account/name "1"}
|
||||||
|
:transaction/amount 1.00
|
||||||
|
:db/id "transaction-id"}
|
||||||
|
|
||||||
|
{:db/id "transaction-rule-id"
|
||||||
|
:transaction-rule/note "transaction rule note"
|
||||||
|
:transaction-rule/description "matching-desc"
|
||||||
|
:transaction-rule/accounts [{:transaction-rule-account/location "A"
|
||||||
|
:transaction-rule-account/account {:account/numeric-code 123 :db/id "123"}
|
||||||
|
:transaction-rule-account/percentage 1.0}]}])
|
||||||
|
:tempids)
|
||||||
|
rule-test (-> (sut/query (admin-token) (v/graphql-query {:venia/operation {:operation/type :mutation
|
||||||
|
:operation/name "MatchTransactionRule"}
|
||||||
|
:venia/queries [{:query/data (sut/->graphql [:match-transaction-rule
|
||||||
|
{:transaction-rule-id transaction-rule-id
|
||||||
|
:transaction-id transaction-id}
|
||||||
|
[[:matched-rule [:id :note]] [:accounts [:id]] ]])}]}))
|
||||||
|
:data
|
||||||
|
:match-transaction-rule)]
|
||||||
|
|
||||||
|
(is (= "transaction rule note" (-> rule-test :matched-rule :note)))
|
||||||
|
(is (= 1 (-> rule-test :accounts count)))
|
||||||
|
|
||||||
|
(testing "Should replace accounts when matching a second time"
|
||||||
|
(let [rule-test (-> (sut/query (admin-token) (v/graphql-query {:venia/operation {:operation/type :mutation
|
||||||
|
:operation/name "MatchTransactionRule"}
|
||||||
|
:venia/queries [{:query/data (sut/->graphql [:match-transaction-rule
|
||||||
|
{:transaction-rule-id transaction-rule-id
|
||||||
|
:transaction-id transaction-id}
|
||||||
|
[[:matched-rule [:id :note]] [:accounts [:id]] ]])}]}))
|
||||||
|
:data
|
||||||
|
:match-transaction-rule)]
|
||||||
|
(is (= 1 (-> rule-test :accounts count))))))))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user