supports adding conclusions.

This commit is contained in:
Bryce Covert
2019-05-12 09:04:26 -07:00
parent 067fff8588
commit 2146073df8
5 changed files with 192 additions and 76 deletions

View File

@@ -14,85 +14,124 @@
(d/delete-database uri))
(use-fixtures :each wrap-setup)
(deftest query
(deftest ledger-page
(testing "ledger"
(testing "it should find ledger entries"
(let [result (:ledger-page (:data (sut/query nil "{ ledger_page(client_id: null) { count, start, journal_entries { id } }}")))]
(is (int? (:count result)))
(is (int? (:start result)))
(is (seqable? (:journal-entries result))))))
(is (seqable? (:journal-entries result)))))))
(testing "transaction-rules"
(testing "it should find rules"
(let [result (-> (sut/query nil "{ transaction_rule_page(client_id: null) { count, start, transaction_rules { id } }}")
:data
:transaction-rule-page)]
(is (int? (:count result)))
(is (int? (:start result)))
(is (seqable? (:transaction-rules result)))))
(deftest transaction-rule-page
(testing "it should find rules"
(let [result (-> (sut/query nil "{ transaction_rule_page(client_id: null) { count, start, transaction_rules { id } }}")
:data
:transaction-rule-page)]
(is (int? (:count result)))
(is (int? (:start result)))
(is (seqable? (:transaction-rules result))))))
(testing "it should add rules"
(let [q (v/graphql-query {:venia/operation {:operation/type :mutation
:operation/name "UpsertTransactionRule"}
:venia/queries [{:query/data (sut/->graphql [:upsert-transaction-rule
{:transaction-rule {:description "123"}}
[:id :description]])}]})
result (-> (sut/query nil q)
:data
:upsert-transaction-rule)]
(is (= "123" (:description result)))
(is (:id result))))
(deftest upsert-transaction-rule
(testing "it should add rules"
(let [{:strs [vendor-id account-id]} (-> (d/connect uri)
(d/transact
[{:vendor/name "Bryce's Meat Co"
:db/id "vendor-id"}
{:account/name "hello"
:db/id "account-id"}])
deref
:tempids)
q (v/graphql-query {:venia/operation {:operation/type :mutation
:operation/name "UpsertTransactionRule"}
:venia/queries [{:query/data (sut/->graphql [:upsert-transaction-rule
{:transaction-rule {:description "123"
:vendor-id vendor-id
:accounts [{:account-id account-id
:percentage "0.5"
:location "B"}
{:account-id account-id
:percentage "0.5"
:location "A"}]}}
[:id :description
[:vendor [:name]]
[:accounts [:id :percentage [:account [:name]]]]]])}]})
result (-> (sut/query nil q)
:data
:upsert-transaction-rule)]
(is (= "123" (:description result)))
(is (= "Bryce's Meat Co" (-> result :vendor :name)))
(is (= "hello" (-> result :accounts (get 0) :account :name )))
(is (:id result))
(testing "it should delete removed rules"
(let [q (v/graphql-query {:venia/operation {:operation/type :mutation
:operation/name "UpsertTransactionRule"}
:venia/queries [{:query/data (sut/->graphql [:upsert-transaction-rule
{:transaction-rule {:id (:id result)
:description "123"
:vendor-id vendor-id
:accounts [{:id (-> result :accounts (get 0) :id)
:account-id account-id
:percentage "1.0"
:location "B"}]}}
[[:accounts [:id :percentage [:account [:name]]]]]])}]})
result (-> (sut/query nil q)
:data
:upsert-transaction-rule)]
(testing "it should match rules based on description regex"
(let [matching-transaction @(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"}
(is (= 1 (count (:accounts result)))))))))
:transaction/amount 1.00
:transaction/id "2019-01-05 matching-desc 1"}
(deftest test-transaction-rule
(testing "it should match rules"
(let [matching-transaction @(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/description-original "nonmatching-desc"
:transaction/client {:client/name "2"
:db/id "client-2"}
:transaction/bank-account {:db/id "bank-account-2"
:bank-account/name "2"}
:transaction/date #inst "2019-01-15T23:23:00.000-08:00"
:transaction/amount 2.00
:transaction/id "2019-01-15 nonmatching-desc 2"}])
{:strs [client-1 client-2 bank-account-1 bank-account-2]} (get-in matching-transaction [:tempids])
:transaction/amount 1.00
:transaction/id "2019-01-05 matching-desc 1"}
rule-test (fn [rule]
(-> (sut/query nil (v/graphql-query {:venia/operation {:operation/type :query
:operation/name "TestTransactionRule"}
:venia/queries [{:query/data (sut/->graphql [:test-transaction-rule
{:transaction-rule rule}
[:id]])}]}))
:data
:test-transaction-rule))]
(testing "based on date "
(is (= [{:id "2019-01-15 nonmatching-desc 2"}] (rule-test {:dom-gte 14 :dom-lte 16})))
(is (= [{:id "2019-01-15 nonmatching-desc 2"}] (rule-test {:dom-gte 14})))
(is (= [{:id "2019-01-05 matching-desc 1"} {:id "2019-01-15 nonmatching-desc 2"}] (rule-test {:dom-lte 15})))
(is (= [{:id "2019-01-15 nonmatching-desc 2"}] (rule-test {:dom-gte 15})))
(is (= [{:id "2019-01-15 nonmatching-desc 2"}] (rule-test {:dom-gte 15 :dom-lte 15}))))
{:transaction/description-original "nonmatching-desc"
:transaction/client {:client/name "2"
:db/id "client-2"}
:transaction/bank-account {:db/id "bank-account-2"
:bank-account/name "2"}
:transaction/date #inst "2019-01-15T23:23:00.000-08:00"
:transaction/amount 2.00
:transaction/id "2019-01-15 nonmatching-desc 2"}])
{:strs [client-1 client-2 bank-account-1 bank-account-2]} (get-in matching-transaction [:tempids])
(testing "based on description"
(is (= [{:id "2019-01-05 matching-desc 1"}] (rule-test {:description "^match"}))))
rule-test (fn [rule]
(-> (sut/query nil (v/graphql-query {:venia/operation {:operation/type :query
:operation/name "TestTransactionRule"}
:venia/queries [{:query/data (sut/->graphql [:test-transaction-rule
{:transaction-rule rule}
[:id]])}]}))
:data
:test-transaction-rule))]
(testing "based on date "
(is (= [{:id "2019-01-15 nonmatching-desc 2"}] (rule-test {:dom-gte 14 :dom-lte 16})))
(is (= [{:id "2019-01-15 nonmatching-desc 2"}] (rule-test {:dom-gte 14})))
(is (= [{:id "2019-01-05 matching-desc 1"} {:id "2019-01-15 nonmatching-desc 2"}] (rule-test {:dom-lte 15})))
(is (= [{:id "2019-01-15 nonmatching-desc 2"}] (rule-test {:dom-gte 15})))
(is (= [{:id "2019-01-15 nonmatching-desc 2"}] (rule-test {:dom-gte 15 :dom-lte 15}))))
(testing "based on amount"
(is (= [{:id "2019-01-05 matching-desc 1"}] (rule-test {:amount-gte 1.0 :amount-lte 1.0})))
(is (= [{:id "2019-01-05 matching-desc 1"} {:id "2019-01-15 nonmatching-desc 2"}] (rule-test {:amount-gte 1.0 })) )
(is (= [{:id "2019-01-05 matching-desc 1"} {:id "2019-01-15 nonmatching-desc 2"}] (rule-test {:amount-lte 2.0 })) ))
(testing "based on description"
(is (= [{:id "2019-01-05 matching-desc 1"}] (rule-test {:description "^match"}))))
(testing "based on client"
(is (= [{:id "2019-01-05 matching-desc 1"}] (rule-test {:client-id client-1})))
(is (= [{:id "2019-01-15 nonmatching-desc 2"}] (rule-test {:client-id client-2}))))
(testing "based on amount"
(is (= [{:id "2019-01-05 matching-desc 1"}] (rule-test {:amount-gte 1.0 :amount-lte 1.0})))
(is (= [{:id "2019-01-05 matching-desc 1"} {:id "2019-01-15 nonmatching-desc 2"}] (rule-test {:amount-gte 1.0 })) )
(is (= [{:id "2019-01-05 matching-desc 1"} {:id "2019-01-15 nonmatching-desc 2"}] (rule-test {:amount-lte 2.0 })) ))
(testing "based on bank account"
(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}))))))))
(testing "based on client"
(is (= [{:id "2019-01-05 matching-desc 1"}] (rule-test {:client-id client-1})))
(is (= [{:id "2019-01-15 nonmatching-desc 2"}] (rule-test {:client-id client-2}))))
(testing "based on bank account"
(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})))))))