Replacing when matching.
This commit is contained in:
@@ -3,8 +3,11 @@
|
||||
[auto-ap.datomic.migrate :as m]
|
||||
[venia.core :as v]
|
||||
[clojure.test :as t :refer [deftest is testing use-fixtures]]
|
||||
[clj-time.core :as time]
|
||||
[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
|
||||
[f]
|
||||
(with-redefs [auto-ap.datomic/uri "datomic:mem://datomic-transactor:4334/invoice"]
|
||||
@@ -14,6 +17,12 @@
|
||||
(d/release (d/connect 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)
|
||||
(deftest ledger-page
|
||||
(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-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