kind of applies rules.
This commit is contained in:
@@ -34,7 +34,8 @@
|
||||
(t/testing "Should import single transaction"
|
||||
(let [result (sut/transactions->txs [base-transaction]
|
||||
:client-id
|
||||
:bank-account-id)]
|
||||
:bank-account-id
|
||||
identity)]
|
||||
(t/is (= [#:transaction {:amount -12.0
|
||||
:date #inst "2014-01-02T08:00:00.000-00:00"
|
||||
:bank-account 456
|
||||
@@ -53,7 +54,8 @@
|
||||
(t/testing "Should skip transaction if no client is found"
|
||||
(let [result (sut/transactions->txs [(assoc base-transaction :client-id nil)]
|
||||
:client-id
|
||||
:bank-account-id)]
|
||||
:bank-account-id
|
||||
identity)]
|
||||
(t/is (= [] result))))
|
||||
|
||||
(t/testing "Should match an uncleared check"
|
||||
@@ -81,7 +83,8 @@
|
||||
:client-id client-id
|
||||
:bank-account-id bank-account-id)]
|
||||
:client-id
|
||||
:bank-account-id)]
|
||||
:bank-account-id
|
||||
identity)]
|
||||
|
||||
(t/is (= {:db/id payment-id
|
||||
:payment/status :payment-status/cleared}
|
||||
@@ -97,7 +100,62 @@
|
||||
:client-id client-id
|
||||
:bank-account-id bank-account-id)]
|
||||
:client-id
|
||||
:bank-account-id)]
|
||||
:bank-account-id
|
||||
identity)]
|
||||
|
||||
(t/is (= nil
|
||||
(:transaction/payment result)))))))))
|
||||
(:transaction/payment result)))))))
|
||||
|
||||
|
||||
(t/testing "Rules"
|
||||
(t/testing "Should apply rules to imported transaction"
|
||||
(let [{:strs [bank-account-id client-id payment-id]} (->> [#:payment {:status :payment-status/pending
|
||||
:date #inst "2019-01-01"
|
||||
:bank-account "bank-account-id"
|
||||
:client "client-id"
|
||||
:check-number 10001
|
||||
:amount 30.0
|
||||
:db/id "payment-id"}
|
||||
#:bank-account {:name "Bank account"
|
||||
:db/id "bank-account-id"}
|
||||
#:client {:name "Client"
|
||||
:db/id "client-id"
|
||||
:bank-accounts ["bank-account-id"]}]
|
||||
(d/transact (d/connect uri))
|
||||
deref
|
||||
:tempids)
|
||||
[result] (sut/transactions->txs [(assoc base-transaction
|
||||
:description {:original "Hello XXX039"
|
||||
:simple ""}
|
||||
:amount {:amount 30.0}
|
||||
:id 789
|
||||
:client-id client-id
|
||||
:bank-account-id bank-account-id)]
|
||||
:client-id
|
||||
:bank-account-id
|
||||
(sut/rule-applying-fn [{:transaction-rule/description "XXX039"
|
||||
:transaction-rule/transaction-approval-status :transaction-approval-status/approved}]))]
|
||||
|
||||
(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"
|
||||
:transaction-rule/transaction-approval-status :transaction-approval-status/approved
|
||||
:transaction-rule/vendor {:db/id 123}}
|
||||
{: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/approval-status :transaction-approval-status/approved}
|
||||
|
||||
(-> {:transaction/description-original "Hello XXX039"}
|
||||
apply-rules)))
|
||||
(t/is (= {:transaction/description-original "OtherMatch",
|
||||
:transaction/approval-status :transaction-approval-status/requires-feedback}
|
||||
(-> {:transaction/description-original "OtherMatch"}
|
||||
apply-rules)))
|
||||
(t/is (= {:transaction/description-original "Hello Not match"}
|
||||
(-> {:transaction/description-original "Hello Not match"}
|
||||
apply-rules
|
||||
))))))))
|
||||
|
||||
Reference in New Issue
Block a user