From d5c3a73befec37ea7e667a1a5351a77bd1e43106 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Tue, 14 May 2019 21:18:59 -0700 Subject: [PATCH] Supports testing yodlee import --- test/clj/auto_ap/yodlee/import.clj | 103 +++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 test/clj/auto_ap/yodlee/import.clj diff --git a/test/clj/auto_ap/yodlee/import.clj b/test/clj/auto_ap/yodlee/import.clj new file mode 100644 index 00000000..d91c8afd --- /dev/null +++ b/test/clj/auto_ap/yodlee/import.clj @@ -0,0 +1,103 @@ +(ns test.auto-ap.yodlee.import + (:require [auto-ap.yodlee.import :as sut] + [auto-ap.yodlee.core :as c] + [datomic.api :as d] + [auto-ap.datomic :refer [uri]] + [auto-ap.datomic.migrate :as m] + [clojure.test :as t])) + +(defn wrap-setup + [f] + (d/create-database uri) + (m/-main false) + (f) + (d/release (d/connect uri)) + (d/delete-database uri)) + +(t/use-fixtures :each wrap-setup) + +(t/deftest do-import + (let [base-transaction {:postDate "2014-01-04" + :accountId 1234 + :date "2014-01-02" + :id 1 + :amount {:amount 12.0} + :description {:original "original-description" + :simple "simple-description"} + :merchant {:id "123" + :name "456"} + :baseType "DEBIT" + :status "PENDING" + + :client-id 123 + :bank-account-id 456}] + (t/testing "Should import single transaction" + (let [result (sut/transactions->txs [base-transaction] + :client-id + :bank-account-id)] + (t/is (= [#:transaction {:amount -12.0 + :date #inst "2014-01-02T08:00:00.000-00:00" + :bank-account 456 + :client 123 + :post-date #inst "2014-01-04T08:00:00.000-00:00" + :account-id 1234 + :description-original "original-description" + :yodlee-merchant #:yodlee-merchant {:yodlee-id "123" + :name "456"} + :status "PENDING" + :id "6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b" + :exclude-from-ledger false + :description-simple "simple-description"}] + result)))) + + (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)] + (t/is (= [] result)))) + + (t/testing "Should match an uncleared check" + (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)] + + + (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)] + + (t/is (= {:db/id payment-id + :payment/status :payment-status/cleared} + (:transaction/payment result)))) + + (t/testing "Should not match an already matched check" + @(d/transact (d/connect uri) [{:db/id payment-id :payment/status :payment-status/cleared}]) + (let [[result] (sut/transactions->txs [(assoc base-transaction + :description {:original "CHECK 10001" + :simple ""} + :amount {:amount 30.0} + :id 789 + :client-id client-id + :bank-account-id bank-account-id)] + :client-id + :bank-account-id)] + + (t/is (= nil + (:transaction/payment result)))))))))