(ns auto-ap.import.yodlee-test
  (:require [auto-ap.import.yodlee2 :as sut]
            [clojure.test :as t]))


(def 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 "POSTED"})

(t/deftest yodlee->transaction
  (t/testing "Should parse dates"
    (t/is (= #inst "2021-01-01T00:00:00-08:00" (:transaction/date (sut/yodlee->transaction (assoc base-transaction :date "2021-01-01") false))))
    (t/is (= #inst "2021-06-01T00:00:00-07:00" (:transaction/date (sut/yodlee->transaction (assoc base-transaction :date "2021-06-01") false)))))

  (t/testing "Should invert amount for debits"
    (t/is (= -12.0 (:transaction/amount (sut/yodlee->transaction (assoc base-transaction
                                                                        :amount {:amount 12.0}
                                                                        :baseType "DEBIT")
                                                                 false))))
    (t/is (= 12.0 (:transaction/amount (sut/yodlee->transaction (assoc base-transaction
                                                                        :amount {:amount 12.0}
                                                                        :baseType "CREDIT")
                                                                false))))))
