prioritizes rules.
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
(m/-main false)
|
||||
(f)
|
||||
(d/release (d/connect uri))
|
||||
(d/delete-database uri))
|
||||
(d/delete-database uri))
|
||||
|
||||
(t/use-fixtures :each wrap-setup)
|
||||
|
||||
@@ -77,14 +77,14 @@
|
||||
|
||||
|
||||
(let [[result] (sut/transactions->txs [(assoc base-transaction
|
||||
:description {:original "CHECK 10001"
|
||||
:simple ""}
|
||||
:amount {:amount 30.0}
|
||||
:client-id client-id
|
||||
:bank-account-id bank-account-id)]
|
||||
:client-id
|
||||
:bank-account-id
|
||||
identity)]
|
||||
:description {:original "CHECK 10001"
|
||||
:simple ""}
|
||||
:amount {:amount 30.0}
|
||||
:client-id client-id
|
||||
:bank-account-id bank-account-id)]
|
||||
:client-id
|
||||
:bank-account-id
|
||||
identity)]
|
||||
|
||||
(t/is (= {:db/id payment-id
|
||||
:payment/status :payment-status/cleared}
|
||||
@@ -139,25 +139,146 @@
|
||||
(t/is (= :transaction-approval-status/approved
|
||||
(:transaction/approval-status result)))))
|
||||
|
||||
(t/testing "Should match if description matches"
|
||||
(let [apply-rules (sut/rule-applying-fn [{:transaction-rule/description "XXX039"
|
||||
(t/testing "Should apply vendor and approval status"
|
||||
(let [apply-rules (sut/rule-applying-fn [{:db/id 1
|
||||
:transaction-rule/description "XXX039"
|
||||
:transaction-rule/transaction-approval-status :transaction-approval-status/approved
|
||||
:transaction-rule/vendor {:db/id 123}}
|
||||
{:transaction-rule/description "OtherMatch"
|
||||
{:db/id 2
|
||||
:transaction-rule/description "OtherMatch"
|
||||
:transaction-rule/transaction-approval-status :transaction-approval-status/requires-feedback
|
||||
:transaction-rule/vendor {:db/id 456}}])]
|
||||
(t/is (= {:transaction/description-original "Hello XXX039",
|
||||
:transaction/vendor 123
|
||||
:transaction/approval-status :transaction-approval-status/approved}
|
||||
(-> {:transaction/description-original "Hello XXX039"}
|
||||
apply-rules)))
|
||||
:transaction/approval-status :transaction-approval-status/approved
|
||||
:transaction/matched-rule 1}
|
||||
(-> {:transaction/description-original "Hello XXX039"}
|
||||
apply-rules)))
|
||||
|
||||
(t/is (= {:transaction/description-original "OtherMatch",
|
||||
:transaction/approval-status :transaction-approval-status/requires-feedback
|
||||
:transaction/vendor 456}
|
||||
:transaction/vendor 456
|
||||
:transaction/matched-rule 2}
|
||||
(-> {:transaction/description-original "OtherMatch"}
|
||||
apply-rules)))
|
||||
|
||||
(t/is (= {:transaction/description-original "Hello Not match"}
|
||||
(-> {:transaction/description-original "Hello Not match"}
|
||||
apply-rules))))))))
|
||||
(-> {:transaction/description-original "Hello Not match"}
|
||||
apply-rules)))))
|
||||
|
||||
(t/testing "Should match if day of month matches"
|
||||
(let [apply-rules (sut/rule-applying-fn [{:db/id 123
|
||||
:transaction-rule/dom-gte 3
|
||||
:transaction-rule/dom-lte 9
|
||||
:transaction-rule/transaction-approval-status :transaction-approval-status/approved
|
||||
:transaction-rule/vendor {:db/id 123}}])]
|
||||
(t/is (= 123
|
||||
(-> {:transaction/date #inst "2019-01-04T00:00:00.000-08:00"}
|
||||
apply-rules
|
||||
:transaction/matched-rule)))
|
||||
(t/is (= 123
|
||||
(-> {:transaction/date #inst "2019-01-03T00:00:00.000-08:00"}
|
||||
apply-rules
|
||||
:transaction/matched-rule)))
|
||||
(t/is (= 123
|
||||
(-> {:transaction/date #inst "2019-01-09T00:00:00.000-08:00"}
|
||||
apply-rules
|
||||
:transaction/matched-rule)))
|
||||
(t/is (nil?
|
||||
(-> {:transaction/date #inst "2019-01-01T00:00:00.000-08:00"}
|
||||
apply-rules
|
||||
:transaction/matched-rule)))
|
||||
(t/is (nil?
|
||||
(-> {:transaction/date #inst "2019-01-10T00:00:00.000-08:00"}
|
||||
apply-rules
|
||||
:transaction/matched-rule)))))
|
||||
|
||||
(t/testing "Should match if amount matches"
|
||||
(let [apply-rules (sut/rule-applying-fn [{:db/id 123
|
||||
:transaction-rule/amount-gte 3.0
|
||||
:transaction-rule/amount-lte 9.0
|
||||
:transaction-rule/transaction-approval-status :transaction-approval-status/approved
|
||||
:transaction-rule/vendor {:db/id 123}}])]
|
||||
(t/is (= 123
|
||||
(-> {:transaction/amount 4.0}
|
||||
apply-rules
|
||||
:transaction/matched-rule)))
|
||||
(t/is (= 123
|
||||
(-> {:transaction/amount 3.0}
|
||||
apply-rules
|
||||
:transaction/matched-rule)))
|
||||
(t/is (= 123
|
||||
(-> {:transaction/amount 9.0}
|
||||
apply-rules
|
||||
:transaction/matched-rule)))
|
||||
(t/is (nil?
|
||||
(-> {:transaction/amount 9.01}
|
||||
apply-rules
|
||||
:transaction/matched-rule)))
|
||||
(t/is (nil?
|
||||
(-> {:transaction/amount 2.99}
|
||||
apply-rules
|
||||
:transaction/matched-rule)))))
|
||||
|
||||
(t/testing "Should match if client matches"
|
||||
(let [apply-rules (sut/rule-applying-fn [{:db/id 123
|
||||
:transaction-rule/client {:db/id 456}}])]
|
||||
(t/is (= 123
|
||||
(-> {:transaction/client 456}
|
||||
apply-rules
|
||||
:transaction/matched-rule)))
|
||||
(t/is (nil?
|
||||
(-> {:transaction/client 89}
|
||||
apply-rules
|
||||
:transaction/matched-rule)))))
|
||||
(t/testing "Should match if bank-account matches"
|
||||
(let [apply-rules (sut/rule-applying-fn [{:db/id 123
|
||||
:transaction-rule/bank-account {:db/id 456}}])]
|
||||
(t/is (= 123
|
||||
(-> {:transaction/bank-account 456}
|
||||
apply-rules
|
||||
:transaction/matched-rule)))
|
||||
(t/is (nil?
|
||||
(-> {:transaction/bank-account 89}
|
||||
apply-rules
|
||||
:transaction/matched-rule)))))
|
||||
|
||||
(t/testing "Should prioritize rules"
|
||||
(let [apply-rules (sut/rule-applying-fn (shuffle [{:db/id 2
|
||||
:transaction-rule/description "Hello"
|
||||
:transaction-rule/amount-gte 5.0}
|
||||
{:db/id 1
|
||||
:transaction-rule/description "Hello"}
|
||||
{:db/id 3
|
||||
:transaction-rule/description "Hello"
|
||||
:transaction-rule/client {:db/id 789}}
|
||||
{:db/id 4
|
||||
:transaction-rule/description "Hello"
|
||||
:transaction-rule/client {:db/id 789}
|
||||
:transaction-rule/bank-account {:db/id 456}}]))]
|
||||
|
||||
(t/is (= 4
|
||||
(-> {:transaction/bank-account 456
|
||||
:transaction/client 789
|
||||
:transaction/description-original "Hello"
|
||||
:transaction/amount 6.0}
|
||||
apply-rules
|
||||
:transaction/matched-rule)))
|
||||
(t/is (= 3
|
||||
(-> {:transaction/bank-account 457
|
||||
:transaction/client 789
|
||||
:transaction/amount 6.0
|
||||
:transaction/description-original "Hello"}
|
||||
apply-rules
|
||||
:transaction/matched-rule)))
|
||||
(t/is (= 3
|
||||
(-> {:transaction/bank-account 457
|
||||
:transaction/client 789
|
||||
:transaction/amount 6.0
|
||||
:transaction/description-original "Hello"}
|
||||
apply-rules
|
||||
:transaction/matched-rule)))
|
||||
#_(t/is (nil?
|
||||
(-> {:transaction/bank-account 89}
|
||||
apply-rules
|
||||
:transaction/matched-rule))))))))
|
||||
|
||||
Reference in New Issue
Block a user