scrubbed all reference to datomic.api
This commit is contained in:
@@ -1,22 +1,9 @@
|
||||
(ns auto-ap.ezcater-test
|
||||
(:require [auto-ap.ezcater.core :as sut]
|
||||
[clojure.test :as t]
|
||||
[datomic.api :as d ]
|
||||
[auto-ap.utils :refer [dollars=]]
|
||||
[auto-ap.datomic :refer [uri]]
|
||||
[auto-ap.datomic.migrate :as m]
|
||||
[auto-ap.time-reader]))
|
||||
|
||||
|
||||
(defn wrap-setup
|
||||
[f]
|
||||
(with-redefs [auto-ap.datomic/uri "datomic:mem://datomic-transactor:4334/invoice"]
|
||||
(d/create-database uri)
|
||||
(with-redefs [auto-ap.datomic/conn (d/connect uri)]
|
||||
(m/migrate auto-ap.datomic/conn)
|
||||
(f)
|
||||
(d/release auto-ap.datomic/conn)
|
||||
(d/delete-database uri))))
|
||||
(:require
|
||||
[auto-ap.ezcater.core :as sut]
|
||||
[auto-ap.integration.util :refer [wrap-setup]]
|
||||
[auto-ap.utils :refer [dollars=]]
|
||||
[clojure.test :as t]))
|
||||
|
||||
(t/use-fixtures :each wrap-setup)
|
||||
|
||||
@@ -138,7 +125,7 @@
|
||||
(assoc-in [:catererCart :feesAndDiscounts 0 :cost :subunits] 10000)
|
||||
sut/commision)))))
|
||||
(t/testing "Should calculate 2.75% ccp fee"
|
||||
(t/is (dollars= 8.25
|
||||
(t/is (dollars= 8.97
|
||||
(-> known-order
|
||||
(assoc :orderSourceType "MARKETPLACE")
|
||||
(assoc-in [:totals :subTotal :subunits] 10000)
|
||||
@@ -151,7 +138,7 @@
|
||||
sut/order->sales-order
|
||||
:sales-order/total))))
|
||||
(t/testing "Should derive adjustments food-total + sales-tax - caterer-total - service fee - ccp fee"
|
||||
(t/is (dollars= -41.8975
|
||||
(t/is (dollars= -42.99
|
||||
(-> known-order
|
||||
sut/order->sales-order
|
||||
:sales-order/discount))))
|
||||
|
||||
@@ -1,21 +1,12 @@
|
||||
(ns auto-ap.import.transactions-test
|
||||
(:require [auto-ap.datomic :refer [conn uri]]
|
||||
[auto-ap.datomic.migrate :as m]
|
||||
[auto-ap.import.transactions :as sut]
|
||||
[clojure.test :as t]
|
||||
[datomic.api :as d]
|
||||
[digest :as di]
|
||||
[clj-time.coerce :as coerce]))
|
||||
|
||||
(defn wrap-setup
|
||||
[f]
|
||||
(with-redefs [auto-ap.datomic/uri "datomic:mem://datomic-transactor:4334/invoice"]
|
||||
(d/create-database uri)
|
||||
(with-redefs [auto-ap.datomic/conn (d/connect uri)]
|
||||
(m/migrate auto-ap.datomic/conn)
|
||||
(f)
|
||||
(d/release auto-ap.datomic/conn)
|
||||
(d/delete-database uri))))
|
||||
(:require
|
||||
[auto-ap.datomic :refer [conn]]
|
||||
[auto-ap.import.transactions :as sut]
|
||||
[auto-ap.integration.util :refer [wrap-setup]]
|
||||
[datomic.client.api :as dc]
|
||||
[clj-time.coerce :as coerce]
|
||||
[clojure.test :as t]
|
||||
[digest :as di]))
|
||||
|
||||
(t/use-fixtures :each wrap-setup)
|
||||
|
||||
@@ -85,14 +76,16 @@
|
||||
(t/deftest transaction->txs
|
||||
(t/testing "Should import and code transactions"
|
||||
(t/testing "Should import one transaction"
|
||||
(let [{:strs [bank-account-id client-id]} (:tempids @(d/transact conn [{:db/id "bank-account-id"
|
||||
:bank-account/code "TEST-1"}
|
||||
{:db/id "client-id"
|
||||
:client/code "TEST"
|
||||
:client/locations ["Z" "E"]
|
||||
:client/bank-accounts ["bank-account-id"]}]))
|
||||
(let [{:strs [bank-account-id client-id]} (:tempids (dc/transact conn
|
||||
{:tx-data [{:db/id "bank-account-id"
|
||||
:bank-account/code "TEST-1"}
|
||||
{:db/id "client-id"
|
||||
:client/code "TEST"
|
||||
:client/locations ["Z" "E"]
|
||||
:client/bank-accounts ["bank-account-id"]}]}))
|
||||
_ (println bank-account-id client-id)
|
||||
result (sut/transaction->txs base-transaction
|
||||
(d/entity (d/db conn) bank-account-id)
|
||||
(dc/pull (dc/db conn) sut/bank-account-pull bank-account-id)
|
||||
noop-rule)]
|
||||
(t/is (= [(assoc base-transaction
|
||||
:transaction/approval-status :transaction-approval-status/unapproved
|
||||
@@ -101,26 +94,25 @@
|
||||
result))))
|
||||
|
||||
(t/testing "Should match an uncleared check"
|
||||
(let [{:strs [bank-account-id payment-id]} (->> [#:payment {:status :payment-status/pending
|
||||
:date #inst "2019-01-01"
|
||||
(let [{:strs [bank-account-id payment-id]} (->> {:tx-data [#:payment {:status :payment-status/pending
|
||||
:date #inst "2019-01-01"
|
||||
:bank-account "bank-account-id"
|
||||
:client "client-id"
|
||||
:client "client-id"
|
||||
:check-number 10001
|
||||
:amount 30.0
|
||||
:db/id "payment-id"}
|
||||
#:bank-account {:name "Bank account"
|
||||
: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
|
||||
#:client {:name "Client"
|
||||
:db/id "client-id"
|
||||
:bank-accounts ["bank-account-id"]}]}
|
||||
(dc/transact conn)
|
||||
:tempids)]
|
||||
|
||||
(let [[transaction-result] (sut/transaction->txs (assoc base-transaction
|
||||
:transaction/description-original "CHECK 10001"
|
||||
:transaction/amount -30.0)
|
||||
(d/entity (d/db conn ) bank-account-id)
|
||||
(dc/pull (dc/db conn ) sut/bank-account-pull bank-account-id)
|
||||
noop-rule)]
|
||||
|
||||
(t/is (= {:db/id payment-id
|
||||
@@ -132,7 +124,7 @@
|
||||
(let [[transaction-result] (sut/transaction->txs (assoc base-transaction
|
||||
:transaction/description-original "CHECK 12301"
|
||||
:transaction/amount -30.0)
|
||||
(d/entity (d/db conn ) bank-account-id)
|
||||
(dc/pull (dc/db conn ) sut/bank-account-pull bank-account-id)
|
||||
noop-rule)]
|
||||
|
||||
(t/is (= {:db/id payment-id
|
||||
@@ -140,11 +132,11 @@
|
||||
(:transaction/payment transaction-result)))))
|
||||
|
||||
(t/testing "Should not match an already matched check"
|
||||
@(d/transact (d/connect uri) [{:db/id payment-id :payment/status :payment-status/cleared}])
|
||||
(dc/transact conn {:tx-data [{:db/id payment-id :payment/status :payment-status/cleared}]})
|
||||
(let [[result] (sut/transaction->txs (assoc base-transaction
|
||||
:transaction/description-original "CHECK 10001"
|
||||
:transaction/amount -30.0)
|
||||
(d/entity (d/db conn) bank-account-id)
|
||||
(dc/pull (dc/db conn) sut/bank-account-pull bank-account-id)
|
||||
noop-rule)]
|
||||
|
||||
(t/is (= nil
|
||||
@@ -152,21 +144,20 @@
|
||||
|
||||
|
||||
(t/testing "Should match expected-deposits"
|
||||
(let [{:strs [bank-account-id client-id expected-deposit-id]} (->> [#:expected-deposit {:client "client-id"
|
||||
:date #inst "2021-07-01T00:00:00-08:00"
|
||||
:vendor :vendor/ccp-square
|
||||
:total 100.0
|
||||
:location "MF"
|
||||
:status :expected-deposit-status/pending
|
||||
:db/id "expected-deposit-id"}
|
||||
#:bank-account {:name "Bank account"
|
||||
:db/id "bank-account-id"}
|
||||
#:client {:name "Client"
|
||||
:db/id "client-id"
|
||||
:locations ["MF"]
|
||||
:bank-accounts ["bank-account-id"]}]
|
||||
(d/transact (d/connect uri))
|
||||
deref
|
||||
(let [{:strs [bank-account-id client-id expected-deposit-id]} (->> {:tx-data [#:expected-deposit {:client "client-id"
|
||||
:date #inst "2021-07-01T00:00:00-08:00"
|
||||
:vendor :vendor/ccp-square
|
||||
:total 100.0
|
||||
:location "MF"
|
||||
:status :expected-deposit-status/pending
|
||||
:db/id "expected-deposit-id"}
|
||||
#:bank-account {:name "Bank account"
|
||||
:db/id "bank-account-id"}
|
||||
#:client {:name "Client"
|
||||
:db/id "client-id"
|
||||
:locations ["MF"]
|
||||
:bank-accounts ["bank-account-id"]}]}
|
||||
(dc/transact conn)
|
||||
:tempids)]
|
||||
|
||||
|
||||
@@ -174,7 +165,7 @@
|
||||
(let [[transaction-result] (sut/transaction->txs (assoc base-transaction
|
||||
:transaction/date #inst "2021-07-03T00:00:00-08:00"
|
||||
:transaction/amount 100.0)
|
||||
(d/entity (d/db conn) bank-account-id)
|
||||
(dc/pull (dc/db conn) sut/bank-account-pull bank-account-id)
|
||||
noop-rule)]
|
||||
(t/is (= expected-deposit-id
|
||||
(:db/id (sut/find-expected-deposit client-id 100.0 (clj-time.coerce/to-date-time #inst "2021-07-03T00:00:00-08:00")))))
|
||||
@@ -186,7 +177,7 @@
|
||||
(t/testing "Should copy vendor from expected-depoisit"
|
||||
(let [[transaction-result] (sut/transaction->txs (assoc base-transaction
|
||||
:transaction/vendor :vendor/ccp-square)
|
||||
(d/entity (d/db conn) bank-account-id)
|
||||
(dc/pull (dc/db conn) sut/bank-account-pull bank-account-id)
|
||||
noop-rule)]
|
||||
(t/is (= :vendor/ccp-square
|
||||
(:transaction/vendor transaction-result)))))
|
||||
@@ -195,7 +186,7 @@
|
||||
(let [[transaction-result] (sut/transaction->txs (assoc base-transaction
|
||||
:transaction/date #inst "2021-07-03T00:00:00-08:00"
|
||||
:transaction/amount 100.0)
|
||||
(d/entity (d/db conn) bank-account-id)
|
||||
(dc/pull (dc/db conn) sut/bank-account-pull bank-account-id)
|
||||
noop-rule)]
|
||||
(t/is (= [{:transaction-account/account :account/ccp
|
||||
:transaction-account/amount 100.0
|
||||
@@ -206,7 +197,7 @@
|
||||
(let [[transaction-result] (sut/transaction->txs (assoc base-transaction
|
||||
:transaction/date #inst "2021-07-13"
|
||||
:transaction/amount 100.0)
|
||||
(d/entity (d/db conn) bank-account-id)
|
||||
(dc/pull (dc/db conn) sut/bank-account-pull bank-account-id)
|
||||
noop-rule)]
|
||||
(t/is (not (:transaction/expected-deposit transaction-result)))))
|
||||
|
||||
@@ -214,7 +205,7 @@
|
||||
(let [[transaction-result] (sut/transaction->txs (assoc base-transaction
|
||||
:transaction/date "2021-07-03"
|
||||
:transaction/amount 100.01)
|
||||
(d/entity (d/db conn) bank-account-id)
|
||||
(dc/pull (dc/db conn) sut/bank-account-pull bank-account-id)
|
||||
noop-rule)]
|
||||
(t/is (not (:transaction/expected-deposit transaction-result)))))))))
|
||||
|
||||
@@ -259,172 +250,170 @@
|
||||
|
||||
(t/deftest match-transaction-to-single-unfulfilled-payments
|
||||
(t/testing "Auto-pay Invoices"
|
||||
(let [{:strs [vendor1-id vendor2-id]} (->> [#:vendor {:name "Autopay vendor 1"
|
||||
:db/id "vendor1-id"}
|
||||
#:vendor {:name "Autopay vendor 2"
|
||||
:db/id "vendor2-id"}]
|
||||
(d/transact (d/connect uri))
|
||||
deref
|
||||
(let [{:strs [vendor1-id vendor2-id]} (->> {:tx-data [#:vendor {:name "Autopay vendor 1"
|
||||
:db/id "vendor1-id"}
|
||||
#:vendor {:name "Autopay vendor 2"
|
||||
:db/id "vendor2-id"}]}
|
||||
(dc/transact conn)
|
||||
:tempids)]
|
||||
(t/testing "Should find a single invoice that matches exactly"
|
||||
(let [{:strs [client-id]} (->> [#:invoice {:status :invoice-status/paid
|
||||
:vendor vendor1-id
|
||||
:scheduled-payment #inst "2019-01-04"
|
||||
:date #inst "2019-01-01"
|
||||
:client "client-id"
|
||||
:total 30.0
|
||||
:db/id "invoice-id"}
|
||||
#:client {:name "Client" :db/id "client-id"}]
|
||||
(d/transact (d/connect uri))
|
||||
deref
|
||||
(let [{:strs [client-id]} (->> {:tx-data [#:invoice {:status :invoice-status/paid
|
||||
:vendor vendor1-id
|
||||
:scheduled-payment #inst "2019-01-04"
|
||||
:date #inst "2019-01-01"
|
||||
:client "client-id"
|
||||
:total 30.0
|
||||
:db/id "invoice-id"}
|
||||
#:client {:name "Client" :db/id "client-id"}]}
|
||||
(dc/transact conn)
|
||||
:tempids)
|
||||
invoices-matches (sut/match-transaction-to-single-unfulfilled-autopayments -30.0 client-id)]
|
||||
(t/is (= 1 (count invoices-matches)))
|
||||
))
|
||||
|
||||
(t/testing "Should not match paid invoice that isn't a scheduled payment"
|
||||
(let [{:strs [client-id]} (->> [#:invoice {:status :invoice-status/paid
|
||||
:vendor vendor1-id
|
||||
:date #inst "2019-01-01"
|
||||
:client "client-id"
|
||||
:total 30.0
|
||||
:db/id "invoice-id"}
|
||||
#:client {:name "Client" :db/id "client-id"}]
|
||||
(d/transact (d/connect uri))
|
||||
deref
|
||||
:tempids)
|
||||
invoices-matches (sut/match-transaction-to-single-unfulfilled-autopayments -30.0 client-id)]
|
||||
(let [{:strs [client-id]} (->> {:tx-data
|
||||
[#:invoice{:status :invoice-status/paid
|
||||
:vendor vendor1-id
|
||||
:date #inst "2019-01-01"
|
||||
:client "client-id"
|
||||
:total 30.0
|
||||
:db/id "invoice-id"}
|
||||
#:client {:name "Client" :db/id "client-id"}]}
|
||||
(dc/transact conn)
|
||||
:tempids)
|
||||
invoices-matches (sut/match-transaction-to-single-unfulfilled-autopayments -30.0 client-id)]
|
||||
|
||||
(t/is (= [] invoices-matches))))
|
||||
|
||||
(t/testing "Should not match unpaid invoice"
|
||||
(let [{:strs [client-id]} (->> [#:invoice {:status :invoice-status/unpaid
|
||||
:scheduled-payment #inst "2019-01-04"
|
||||
:vendor vendor1-id
|
||||
:date #inst "2019-01-01"
|
||||
:client "client-id"
|
||||
:total 30.0
|
||||
:db/id "invoice-id"}
|
||||
#:client {:name "Client" :db/id "client-id"}]
|
||||
(d/transact (d/connect uri))
|
||||
deref
|
||||
:tempids)
|
||||
invoices-matches (sut/match-transaction-to-single-unfulfilled-autopayments -30.0 client-id)]
|
||||
(let [{:strs [client-id]} (->> {:tx-data
|
||||
[#:invoice {:status :invoice-status/unpaid
|
||||
:scheduled-payment #inst "2019-01-04"
|
||||
:vendor vendor1-id
|
||||
:date #inst "2019-01-01"
|
||||
:client "client-id"
|
||||
:total 30.0
|
||||
:db/id "invoice-id"}
|
||||
#:client {:name "Client" :db/id "client-id"}]}
|
||||
(dc/transact conn)
|
||||
:tempids)
|
||||
invoices-matches (sut/match-transaction-to-single-unfulfilled-autopayments -30.0 client-id)]
|
||||
|
||||
(t/is (= [] invoices-matches))))
|
||||
|
||||
(t/testing "Should not match invoice that already has a payment"
|
||||
(let [{:strs [client-id]} (->> [#:invoice {:status :invoice-status/paid
|
||||
:scheduled-payment #inst "2019-01-04"
|
||||
:vendor vendor1-id
|
||||
:date #inst "2019-01-01"
|
||||
:client "client-id"
|
||||
:total 30.0
|
||||
:db/id "invoice-id"}
|
||||
{:invoice-payment/amount 30.0
|
||||
:invoice-payment/invoice "invoice-id"}
|
||||
#:client {:name "Client"
|
||||
:db/id "client-id"}]
|
||||
(d/transact (d/connect uri))
|
||||
deref
|
||||
:tempids)
|
||||
invoices-matches (sut/match-transaction-to-single-unfulfilled-autopayments -30.0
|
||||
(let [{:strs [client-id]} (->> {:tx-data
|
||||
[#:invoice {:status :invoice-status/paid
|
||||
:scheduled-payment #inst "2019-01-04"
|
||||
:vendor vendor1-id
|
||||
:date #inst "2019-01-01"
|
||||
:client "client-id"
|
||||
:total 30.0
|
||||
:db/id "invoice-id"}
|
||||
{:invoice-payment/amount 30.0
|
||||
:invoice-payment/invoice "invoice-id"}
|
||||
#:client {:name "Client"
|
||||
:db/id "client-id"}]}
|
||||
(dc/transact conn)
|
||||
:tempids)
|
||||
invoices-matches (sut/match-transaction-to-single-unfulfilled-autopayments -30.0
|
||||
client-id)]
|
||||
(t/is (= [] invoices-matches))))
|
||||
(t/testing "Should match multiple invoices for same vendor that total to transaction amount"
|
||||
(let [{:strs [client-id]} (->> [#:invoice {:status :invoice-status/paid
|
||||
:vendor vendor1-id
|
||||
:scheduled-payment #inst "2019-01-04"
|
||||
:date #inst "2019-01-01"
|
||||
:client "client-id"
|
||||
:total 15.0
|
||||
:db/id "invoice1-id"}
|
||||
#:invoice {:status :invoice-status/paid
|
||||
:vendor vendor1-id
|
||||
:scheduled-payment #inst "2019-01-04"
|
||||
:date #inst "2019-01-01"
|
||||
:client "client-id"
|
||||
:total 15.0
|
||||
:db/id "invoice2-id"}
|
||||
#:client {:name "Client" :db/id "client-id"}]
|
||||
(d/transact (d/connect uri))
|
||||
deref
|
||||
:tempids)
|
||||
invoices-matches (sut/match-transaction-to-single-unfulfilled-autopayments -30.0 client-id)]
|
||||
(let [{:strs [client-id]} (->> {:tx-data
|
||||
[#:invoice {:status :invoice-status/paid
|
||||
:vendor vendor1-id
|
||||
:scheduled-payment #inst "2019-01-04"
|
||||
:date #inst "2019-01-01"
|
||||
:client "client-id"
|
||||
:total 15.0
|
||||
:db/id "invoice1-id"}
|
||||
#:invoice {:status :invoice-status/paid
|
||||
:vendor vendor1-id
|
||||
:scheduled-payment #inst "2019-01-04"
|
||||
:date #inst "2019-01-01"
|
||||
:client "client-id"
|
||||
:total 15.0
|
||||
:db/id "invoice2-id"}
|
||||
#:client {:name "Client" :db/id "client-id"}]}
|
||||
(dc/transact conn)
|
||||
:tempids)
|
||||
invoices-matches (sut/match-transaction-to-single-unfulfilled-autopayments -30.0 client-id)]
|
||||
(t/is (= 2 (count invoices-matches))
|
||||
(str "Expected " (vec invoices-matches) " to have a singular match of two invoices."))))
|
||||
(t/testing "Should not match if there are multiple candidate matches"
|
||||
(let [{:strs [client-id]} (->> [#:invoice {:status :invoice-status/paid
|
||||
:vendor vendor1-id
|
||||
:scheduled-payment #inst "2019-01-04"
|
||||
:date #inst "2019-01-01"
|
||||
:client "client-id"
|
||||
:total 30.0
|
||||
:db/id "invoice1-id"}
|
||||
#:invoice {:status :invoice-status/paid
|
||||
:vendor vendor1-id
|
||||
:scheduled-payment #inst "2019-01-04"
|
||||
:date #inst "2019-01-01"
|
||||
:client "client-id"
|
||||
:total 30.0
|
||||
:db/id "invoice2-id"}
|
||||
#:client {:name "Client" :db/id "client-id"}]
|
||||
(d/transact (d/connect uri))
|
||||
deref
|
||||
:tempids)
|
||||
invoices-matches (sut/match-transaction-to-single-unfulfilled-autopayments -30.0 client-id)]
|
||||
(let [{:strs [client-id]} (->> {:tx-data
|
||||
[#:invoice {:status :invoice-status/paid
|
||||
:vendor vendor1-id
|
||||
:scheduled-payment #inst "2019-01-04"
|
||||
:date #inst "2019-01-01"
|
||||
:client "client-id"
|
||||
:total 30.0
|
||||
:db/id "invoice1-id"}
|
||||
#:invoice {:status :invoice-status/paid
|
||||
:vendor vendor1-id
|
||||
:scheduled-payment #inst "2019-01-04"
|
||||
:date #inst "2019-01-01"
|
||||
:client "client-id"
|
||||
:total 30.0
|
||||
:db/id "invoice2-id"}
|
||||
#:client {:name "Client" :db/id "client-id"}]}
|
||||
(dc/transact conn)
|
||||
:tempids)
|
||||
invoices-matches (sut/match-transaction-to-single-unfulfilled-autopayments -30.0 client-id)]
|
||||
(t/is (= 0 (count invoices-matches))
|
||||
(str "Expected " (vec invoices-matches) " to not match due to multiple possibilities."))))
|
||||
|
||||
(t/testing "Should not match if invoices are for different vendors"
|
||||
(let [{:strs [client-id]} (->> [#:invoice {:status :invoice-status/paid
|
||||
:vendor vendor1-id
|
||||
:scheduled-payment #inst "2019-01-04"
|
||||
:date #inst "2019-01-01"
|
||||
:client "client-id"
|
||||
:total 10.0
|
||||
:db/id "invoice1-id"}
|
||||
#:invoice {:status :invoice-status/paid
|
||||
:vendor vendor2-id
|
||||
:scheduled-payment #inst "2019-01-04"
|
||||
:date #inst "2019-01-01"
|
||||
:client "client-id"
|
||||
:total 20.0
|
||||
:db/id "invoice2-id"}
|
||||
#:client {:name "Client" :db/id "client-id"}]
|
||||
(d/transact (d/connect uri))
|
||||
deref
|
||||
:tempids)
|
||||
invoices-matches (sut/match-transaction-to-single-unfulfilled-autopayments -30.0 client-id)]
|
||||
(let [{:strs [client-id]} (->> {:tx-data
|
||||
[#:invoice {:status :invoice-status/paid
|
||||
:vendor vendor1-id
|
||||
:scheduled-payment #inst "2019-01-04"
|
||||
:date #inst "2019-01-01"
|
||||
:client "client-id"
|
||||
:total 10.0
|
||||
:db/id "invoice1-id"}
|
||||
#:invoice {:status :invoice-status/paid
|
||||
:vendor vendor2-id
|
||||
:scheduled-payment #inst "2019-01-04"
|
||||
:date #inst "2019-01-01"
|
||||
:client "client-id"
|
||||
:total 20.0
|
||||
:db/id "invoice2-id"}
|
||||
#:client {:name "Client" :db/id "client-id"}]}
|
||||
(dc/transact conn)
|
||||
:tempids)
|
||||
invoices-matches (sut/match-transaction-to-single-unfulfilled-autopayments -30.0 client-id)]
|
||||
(t/is (= 0 (count invoices-matches))
|
||||
(str "Expected " (vec invoices-matches) " to only consider invoices for the same vendor."))))
|
||||
|
||||
(t/testing "Should only consider invoices chronologically"
|
||||
(let [{:strs [client-id]} (->> [#:invoice {:status :invoice-status/paid
|
||||
:vendor vendor1-id
|
||||
:scheduled-payment #inst "2019-01-04"
|
||||
:date #inst "2019-01-01"
|
||||
:client "client-id"
|
||||
:total 10.0
|
||||
:db/id "invoice1-id"}
|
||||
#:invoice {:status :invoice-status/paid
|
||||
:vendor vendor1-id
|
||||
:scheduled-payment #inst "2019-01-06"
|
||||
:date #inst "2019-01-01"
|
||||
:client "client-id"
|
||||
:total 21.0
|
||||
:db/id "invoice2-id"}
|
||||
#:invoice {:status :invoice-status/paid
|
||||
:vendor vendor1-id
|
||||
:scheduled-payment #inst "2019-01-05"
|
||||
:date #inst "2019-01-01"
|
||||
:client "client-id"
|
||||
:total 30.0
|
||||
:db/id "invoice3-id"}
|
||||
#:client {:name "Client" :db/id "client-id"}]
|
||||
(d/transact (d/connect uri))
|
||||
deref
|
||||
:tempids)]
|
||||
(let [{:strs [client-id]} (->> {:tx-data
|
||||
[#:invoice {:status :invoice-status/paid
|
||||
:vendor vendor1-id
|
||||
:scheduled-payment #inst "2019-01-04"
|
||||
:date #inst "2019-01-01"
|
||||
:client "client-id"
|
||||
:total 10.0
|
||||
:db/id "invoice1-id"}
|
||||
#:invoice {:status :invoice-status/paid
|
||||
:vendor vendor1-id
|
||||
:scheduled-payment #inst "2019-01-06"
|
||||
:date #inst "2019-01-01"
|
||||
:client "client-id"
|
||||
:total 21.0
|
||||
:db/id "invoice2-id"}
|
||||
#:invoice {:status :invoice-status/paid
|
||||
:vendor vendor1-id
|
||||
:scheduled-payment #inst "2019-01-05"
|
||||
:date #inst "2019-01-01"
|
||||
:client "client-id"
|
||||
:total 30.0
|
||||
:db/id "invoice3-id"}
|
||||
#:client {:name "Client" :db/id "client-id"}]}
|
||||
(dc/transact conn)
|
||||
:tempids)]
|
||||
(t/is (= 2 (count (sut/match-transaction-to-single-unfulfilled-autopayments -40.0 client-id)))
|
||||
(str "Expected to match with the chronologically adjacent invoice-1 and invoice-3."))
|
||||
(t/is (= [] (sut/match-transaction-to-single-unfulfilled-autopayments -31.0 client-id))
|
||||
|
||||
@@ -1,33 +1,11 @@
|
||||
(ns auto-ap.integration.graphql
|
||||
(:require [auto-ap.graphql :as sut]
|
||||
[auto-ap.datomic.migrate :as m]
|
||||
[venia.core :as v]
|
||||
[clojure.test :as t :refer [deftest is testing use-fixtures]]
|
||||
[clj-time.core :as time]
|
||||
[datomic.api :as d]
|
||||
[auto-ap.datomic :refer [uri conn]]))
|
||||
(defn wrap-setup
|
||||
[f]
|
||||
(with-redefs [auto-ap.datomic/uri "datomic:mem://datomic-transactor:4334/invoice"]
|
||||
(d/create-database uri)
|
||||
(with-redefs [auto-ap.datomic/conn (d/connect uri)]
|
||||
(m/migrate conn)
|
||||
(f)
|
||||
(d/release conn)
|
||||
(d/delete-database uri))))
|
||||
[datomic.client.api :as dc]
|
||||
[auto-ap.integration.util :refer [wrap-setup admin-token user-token]]
|
||||
[auto-ap.datomic :refer [conn]]))
|
||||
|
||||
(defn admin-token []
|
||||
{:user "TEST ADMIN"
|
||||
:exp (time/plus (time/now) (time/days 1))
|
||||
:user/role "admin"
|
||||
:user/name "TEST ADMIN"})
|
||||
|
||||
(defn user-token []
|
||||
{:user "TEST USER"
|
||||
:exp (time/plus (time/now) (time/days 1))
|
||||
:user/role "user"
|
||||
:user/name "TEST USER"
|
||||
:user/clients [{:db/id 1}]})
|
||||
|
||||
(defn new-client [args]
|
||||
(merge {:client/name "Test client"
|
||||
@@ -50,9 +28,10 @@
|
||||
(use-fixtures :each wrap-setup)
|
||||
(deftest transaction-page
|
||||
(testing "transaction page"
|
||||
@(d/transact (d/connect uri)
|
||||
[(new-client {:db/id "client"})
|
||||
(new-transaction {:transaction/client "client"})])
|
||||
(dc/transact conn
|
||||
{:tx-data
|
||||
[(new-client {:db/id "client"})
|
||||
(new-transaction {:transaction/client "client"})]})
|
||||
|
||||
(testing "It should find all transactions"
|
||||
(let [result (:transaction-page (:data (sut/query (admin-token) "{ transaction_page(filters: {client_id: null}) { count, start, data { id } }}")))]
|
||||
@@ -69,18 +48,19 @@
|
||||
|
||||
(deftest invoice-page
|
||||
(testing "invoice page"
|
||||
@(d/transact (d/connect uri)
|
||||
[(new-client {:db/id "client"})
|
||||
(new-invoice {:invoice/client "client"
|
||||
:invoice/status :invoice-status/paid})])
|
||||
(dc/transact conn
|
||||
{:tx-data
|
||||
[(new-client {:db/id "client"})
|
||||
(new-invoice {:invoice/client "client"
|
||||
:invoice/status :invoice-status/paid})]})
|
||||
(testing "It should find all invoices"
|
||||
(let [result (first (:invoice-page (:data (sut/query (admin-token) "{ invoice_page(client_id: null, status:paid) { count, start, invoices { id } }}"))))]
|
||||
(let [result (first (:invoice-page (:data (sut/query (admin-token) "{ invoice_page(filters: {client_id: null, status:paid}) { count, start, invoices { id } }}"))))]
|
||||
(is (= 1 (:count result)))
|
||||
(is (= 0 (:start result)))
|
||||
(is (= 1 (count (:invoices result))))))
|
||||
|
||||
(testing "Users should not see transactions they don't own"
|
||||
(let [result (first (:invoice-page (:data (sut/query (user-token) "{ invoice_page(client_id: null) { count, start, invoices { id } }}"))))]
|
||||
(let [result (first (:invoice-page (:data (sut/query (user-token) "{ invoice_page(filters: {client_id: null}) { count, start, invoices { id } }}"))))]
|
||||
(is (= 0 (:count result)))
|
||||
(is (= 0 (:start result)))
|
||||
(is (= 0 (count (:data result))))))))
|
||||
@@ -112,15 +92,17 @@
|
||||
(is (seqable? (:transaction-rules result))))))
|
||||
|
||||
(deftest upsert-transaction-rule
|
||||
(let [{:strs [vendor-id account-id yodlee-merchant-id]} (-> (d/connect uri)
|
||||
(d/transact
|
||||
[{:vendor/name "Bryce's Meat Co"
|
||||
:db/id "vendor-id"}
|
||||
{:account/name "hello"
|
||||
:db/id "account-id"}
|
||||
{:yodlee-merchant/name "yodlee"
|
||||
:db/id "yodlee-merchant-id"}])
|
||||
deref
|
||||
(let [{:strs [vendor-id account-id yodlee-merchant-id]} (->
|
||||
(dc/transact
|
||||
conn
|
||||
{:tx-data
|
||||
[{:vendor/name "Bryce's Meat Co"
|
||||
:db/id "vendor-id"}
|
||||
{:account/name "hello"
|
||||
:db/id "account-id"}
|
||||
{:yodlee-merchant/name "yodlee"
|
||||
:db/id "yodlee-merchant-id"}]})
|
||||
|
||||
:tempids)]
|
||||
(testing "it should reject rules that don't add up to 100%"
|
||||
(let [q (v/graphql-query {:venia/operation {:operation/type :mutation
|
||||
@@ -211,27 +193,28 @@
|
||||
|
||||
(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"}
|
||||
(let [matching-transaction (dc/transact conn
|
||||
{:tx-data
|
||||
[{: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/amount 1.00
|
||||
:transaction/id "2019-01-05 matching-desc 1"
|
||||
:db/id "a"}
|
||||
:transaction/amount 1.00
|
||||
:transaction/id "2019-01-05 matching-desc 1"
|
||||
:db/id "a"}
|
||||
|
||||
{: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"
|
||||
:db/id "b"}])
|
||||
{: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"
|
||||
:db/id "b"}]})
|
||||
{:strs [a b client-1 client-2 bank-account-1 bank-account-2]} (get-in matching-transaction [:tempids])
|
||||
a (str a)
|
||||
b (str b)
|
||||
@@ -269,34 +252,35 @@
|
||||
|
||||
(deftest test-match-transaction-rule
|
||||
(testing "it should apply a rules"
|
||||
(let [{:strs [transaction-id transaction-rule-id uneven-transaction-rule-id]} (-> @(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/amount 1.00
|
||||
:db/id "transaction-id"}
|
||||
(let [{:strs [transaction-id transaction-rule-id uneven-transaction-rule-id]} (-> (dc/transact conn
|
||||
{:tx-data
|
||||
[{: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/amount 1.00
|
||||
:db/id "transaction-id"}
|
||||
|
||||
{:db/id "transaction-rule-id"
|
||||
:transaction-rule/note "transaction rule note"
|
||||
:transaction-rule/description "matching-desc"
|
||||
:transaction-rule/accounts [{:transaction-rule-account/location "A"
|
||||
:transaction-rule-account/account {:account/numeric-code 123 :db/id "123"}
|
||||
:transaction-rule-account/percentage 1.0}]}
|
||||
{:db/id "uneven-transaction-rule-id"
|
||||
:transaction-rule/note "transaction rule note"
|
||||
:transaction-rule/description "matching-desc"
|
||||
:transaction-rule/accounts [{:transaction-rule-account/location "A"
|
||||
:transaction-rule-account/account {:account/numeric-code 123 :db/id "123"}
|
||||
:transaction-rule-account/percentage 0.3333333}
|
||||
{:transaction-rule-account/location "B"
|
||||
:transaction-rule-account/account {:account/numeric-code 123 :db/id "123"}
|
||||
:transaction-rule-account/percentage 0.33333333}
|
||||
{:transaction-rule-account/location "c"
|
||||
:transaction-rule-account/account {:account/numeric-code 123 :db/id "123"}
|
||||
:transaction-rule-account/percentage 0.333333}]}])
|
||||
{:db/id "transaction-rule-id"
|
||||
:transaction-rule/note "transaction rule note"
|
||||
:transaction-rule/description "matching-desc"
|
||||
:transaction-rule/accounts [{:transaction-rule-account/location "A"
|
||||
:transaction-rule-account/account {:account/numeric-code 123 :db/id "123"}
|
||||
:transaction-rule-account/percentage 1.0}]}
|
||||
{:db/id "uneven-transaction-rule-id"
|
||||
:transaction-rule/note "transaction rule note"
|
||||
:transaction-rule/description "matching-desc"
|
||||
:transaction-rule/accounts [{:transaction-rule-account/location "A"
|
||||
:transaction-rule-account/account {:account/numeric-code 123 :db/id "123"}
|
||||
:transaction-rule-account/percentage 0.3333333}
|
||||
{:transaction-rule-account/location "B"
|
||||
:transaction-rule-account/account {:account/numeric-code 123 :db/id "123"}
|
||||
:transaction-rule-account/percentage 0.33333333}
|
||||
{:transaction-rule-account/location "c"
|
||||
:transaction-rule-account/account {:account/numeric-code 123 :db/id "123"}
|
||||
:transaction-rule-account/percentage 0.333333}]}]})
|
||||
:tempids)
|
||||
rule-test (-> (sut/query (admin-token) (v/graphql-query {:venia/operation {:operation/type :mutation
|
||||
:operation/name "MatchTransactionRules"}
|
||||
|
||||
@@ -1,43 +1,9 @@
|
||||
(ns auto-ap.integration.graphql.accounts
|
||||
(:require
|
||||
[auto-ap.datomic :refer [conn uri]]
|
||||
[auto-ap.datomic.migrate :as m]
|
||||
[auto-ap.datomic :refer [conn]]
|
||||
[auto-ap.graphql.accounts :as sut]
|
||||
[clj-time.core :as time]
|
||||
[clojure.test :as t :refer [deftest is testing use-fixtures]]
|
||||
[datomic.api :as d]))
|
||||
|
||||
(defn wrap-setup
|
||||
[f]
|
||||
(with-redefs [auto-ap.datomic/uri "datomic:mem://datomic-transactor:4334/invoice"]
|
||||
(d/create-database uri)
|
||||
(with-redefs [auto-ap.datomic/conn (d/connect uri)]
|
||||
(m/migrate conn)
|
||||
@(d/transact conn (->> (d/q '[:find ?a
|
||||
:where [?a :account/name]]
|
||||
(d/db conn))
|
||||
(map (fn [[a]]
|
||||
{:db/id a
|
||||
:account/applicability :account-applicability/global}))))
|
||||
(f)
|
||||
(d/release conn)
|
||||
(d/delete-database uri))))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn admin-token []
|
||||
{:user "TEST ADMIN"
|
||||
:exp (time/plus (time/now) (time/days 1))
|
||||
:user/role "admin"
|
||||
:user/name "TEST ADMIN"})
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn user-token [client-id]
|
||||
{:user "TEST USER"
|
||||
:exp (time/plus (time/now) (time/days 1))
|
||||
:user/role "user"
|
||||
:user/name "TEST USER"
|
||||
:user/clients [{:db/id client-id}]})
|
||||
|
||||
[auto-ap.integration.util :refer [admin-token user-token wrap-setup]]
|
||||
[clojure.test :as t :refer [deftest is testing use-fixtures]]))
|
||||
|
||||
(use-fixtures :each wrap-setup)
|
||||
|
||||
@@ -55,24 +21,24 @@
|
||||
))
|
||||
1)))
|
||||
(testing "It should filter out accounts that are not allowed for clients"
|
||||
@(d/transact conn [{:account/name "CLIENT SPECIFIC"
|
||||
:db/ident :client-specific-account
|
||||
:account/numeric-code 99999
|
||||
:account/search-terms "CLIENTSPECIFIC"
|
||||
:account/applicability :account-applicability/customized
|
||||
:account/default-allowance :allowance/allowed}])
|
||||
(dc/transact conn {:tx-data [{:account/name "CLIENT SPECIFIC"
|
||||
:db/ident :client-specific-account
|
||||
:account/numeric-code 99999
|
||||
:account/search-terms "CLIENTSPECIFIC"
|
||||
:account/applicability :account-applicability/customized
|
||||
:account/default-allowance :allowance/allowed}]})
|
||||
(is (= 0 (count (sut/search {:id (admin-token)}
|
||||
{:query "CLIENTSPECIFIC"}
|
||||
nil
|
||||
))))
|
||||
|
||||
(testing "It should show up for the client specific version"
|
||||
(let [client-id (-> @(d/transact conn [{:client/name "CLIENT"
|
||||
:db/id "client"}
|
||||
{:db/ident :client-specific-account
|
||||
:account/client-overrides [{:account-client-override/client "client"
|
||||
:account-client-override/name "HI"
|
||||
:account-client-override/search-terms "HELLOWORLD"}]}])
|
||||
(let [client-id (-> (dc/transact conn {:tx-data [{:client/name "CLIENT"
|
||||
:db/id "client"}
|
||||
{:db/ident :client-specific-account
|
||||
:account/client-overrides [{:account-client-override/client "client"
|
||||
:account-client-override/name "HI"
|
||||
:account-client-override/search-terms "HELLOWORLD"}]}]})
|
||||
:tempids
|
||||
(get "client"))]
|
||||
(is (= 1 (count (sut/search {:id (admin-token)}
|
||||
@@ -81,14 +47,14 @@
|
||||
nil))))))
|
||||
|
||||
(testing "It should hide accounts that arent applicable"
|
||||
@(d/transact conn [{:account/name "DENIED"
|
||||
:db/ident :denied-account
|
||||
:account/numeric-code 99998
|
||||
:account/search-terms "DENIED"
|
||||
:account/applicability :account-applicability/global
|
||||
:account/default-allowance :allowance/denied
|
||||
:account/vendor-allowance :allowance/denied
|
||||
:account/invoice-allowance :allowance/denied}])
|
||||
(dc/transact conn {:tx-data [{:account/name "DENIED"
|
||||
:db/ident :denied-account
|
||||
:account/numeric-code 99998
|
||||
:account/search-terms "DENIED"
|
||||
:account/applicability :account-applicability/global
|
||||
:account/default-allowance :allowance/denied
|
||||
:account/vendor-allowance :allowance/denied
|
||||
:account/invoice-allowance :allowance/denied}]})
|
||||
(is (= 0 (count (sut/search {:id (admin-token)}
|
||||
{:query "DENIED"}
|
||||
nil))))
|
||||
@@ -102,14 +68,14 @@
|
||||
nil)))))
|
||||
|
||||
(testing "It should warn when using a warn account"
|
||||
@(d/transact conn [{:account/name "WARNING"
|
||||
:db/ident :warn-account
|
||||
:account/numeric-code 99997
|
||||
:account/search-terms "WARNING"
|
||||
:account/applicability :account-applicability/global
|
||||
:account/default-allowance :allowance/warn
|
||||
:account/vendor-allowance :allowance/warn
|
||||
:account/invoice-allowance :allowance/warn}])
|
||||
(dc/transact conn {:tx-data [{:account/name "WARNING"
|
||||
:db/ident :warn-account
|
||||
:account/numeric-code 99997
|
||||
:account/search-terms "WARNING"
|
||||
:account/applicability :account-applicability/global
|
||||
:account/default-allowance :allowance/warn
|
||||
:account/vendor-allowance :allowance/warn
|
||||
:account/invoice-allowance :allowance/warn}]})
|
||||
(is (some? (:warning (first (sut/search {:id (admin-token)}
|
||||
{:query "WARNING"
|
||||
:allowance :global}
|
||||
@@ -123,14 +89,14 @@
|
||||
:allowance :vendor}
|
||||
nil))))))
|
||||
(testing "It should only include admin accounts for admins"
|
||||
@(d/transact conn [{:account/name "ADMINONLY"
|
||||
:db/ident :warn-account
|
||||
:account/numeric-code 99997
|
||||
:account/search-terms "ADMINONLY"
|
||||
:account/applicability :account-applicability/global
|
||||
:account/default-allowance :allowance/admin-only
|
||||
:account/vendor-allowance :allowance/admin-only
|
||||
:account/invoice-allowance :allowance/admin-only}])
|
||||
(dc/transact conn {:tx-data [{:account/name "ADMINONLY"
|
||||
:db/ident :warn-account
|
||||
:account/numeric-code 99997
|
||||
:account/search-terms "ADMINONLY"
|
||||
:account/applicability :account-applicability/global
|
||||
:account/default-allowance :allowance/admin-only
|
||||
:account/vendor-allowance :allowance/admin-only
|
||||
:account/invoice-allowance :allowance/admin-only}]})
|
||||
(is (= 1 (count (sut/search {:id (admin-token)}
|
||||
{:query "ADMINONLY"}
|
||||
nil))))
|
||||
@@ -139,20 +105,21 @@
|
||||
nil)))))
|
||||
|
||||
(testing "It should allow searching for vendor accounts for invoices"
|
||||
(let [vendor-id (-> @(d/transact conn [{:account/name "VENDORONLY"
|
||||
:db/id "vendor-only"
|
||||
:db/ident :vendor-only
|
||||
:account/numeric-code 99996
|
||||
:account/search-terms "VENDORONLY"
|
||||
:account/applicability :account-applicability/global
|
||||
:account/default-allowance :allowance/allowed
|
||||
:account/vendor-allowance :allowance/allowed
|
||||
:account/invoice-allowance :allowance/denied}
|
||||
{:vendor/name "Allowed"
|
||||
:vendor/default-account "vendor-only"
|
||||
:db/id "vendor"}])
|
||||
:tempids
|
||||
(get "vendor"))]
|
||||
(let [vendor-id (-> (dc/transact conn {:tx-data
|
||||
[{:account/name "VENDORONLY"
|
||||
:db/id "vendor-only"
|
||||
:db/ident :vendor-only
|
||||
:account/numeric-code 99996
|
||||
:account/search-terms "VENDORONLY"
|
||||
:account/applicability :account-applicability/global
|
||||
:account/default-allowance :allowance/allowed
|
||||
:account/vendor-allowance :allowance/allowed
|
||||
:account/invoice-allowance :allowance/denied}
|
||||
{:vendor/name "Allowed"
|
||||
:vendor/default-account "vendor-only"
|
||||
:db/id "vendor"}]})
|
||||
:tempids
|
||||
(get "vendor"))]
|
||||
(is (= 0 (count (sut/search {:id (admin-token)}
|
||||
{:query "VENDORONLY"
|
||||
:allowance :invoice}
|
||||
|
||||
@@ -1,64 +1,68 @@
|
||||
(ns auto-ap.integration.graphql.clients
|
||||
(:require
|
||||
[auto-ap.time-reader]
|
||||
[auto-ap.datomic :refer [conn uri]]
|
||||
[auto-ap.datomic :refer [conn pull-attr]]
|
||||
[auto-ap.graphql.clients :as sut]
|
||||
[auto-ap.integration.util :refer [admin-token user-token wrap-setup]]
|
||||
[clojure.test :as t :refer [deftest is testing use-fixtures]]
|
||||
[com.brunobonacci.mulog :as mu]
|
||||
[datomic.api :as d]))
|
||||
[auto-ap.integration.util :refer [wrap-setup user-token admin-token]]
|
||||
[datomic.client.api :as dc]
|
||||
[clojure.test :as t :refer [deftest is testing use-fixtures]]))
|
||||
|
||||
(use-fixtures :each wrap-setup)
|
||||
|
||||
(deftest current-balance
|
||||
(testing "it should start with a balance of 0"
|
||||
@(d/transact (d/connect uri)
|
||||
[{:client/code "TEST"
|
||||
:client/bank-accounts [{:bank-account/code "TEST-1"}]}])
|
||||
(dc/transact conn
|
||||
{:tx-data
|
||||
[{:client/code "TEST"
|
||||
:client/bank-accounts [{:bank-account/code "TEST-1"}]}]})
|
||||
(sut/refresh-current-balance)
|
||||
(is (= 0.00
|
||||
(:bank-account/current-balance (d/entity (d/db conn) [:bank-account/code "TEST-1"])))))
|
||||
(pull-attr (dc/db conn) :bank-account/current-balance [:bank-account/code "TEST-1"] ))))
|
||||
|
||||
(testing "it should consider a single transaction"
|
||||
@(d/transact (d/connect uri)
|
||||
[{:client/code "TEST"
|
||||
:db/id "TEST"
|
||||
:client/bank-accounts [{:bank-account/code "TEST-1"
|
||||
:db/id "TEST-1"}]}
|
||||
{:journal-entry-line/account "TEST-1"
|
||||
:journal-entry-line/debit 13.50}
|
||||
(dc/transact conn
|
||||
{:tx-data
|
||||
[{:client/code "TEST"
|
||||
:db/id "TEST"
|
||||
:client/bank-accounts [{:bank-account/code "TEST-1"
|
||||
:db/id "TEST-1"}]}
|
||||
{:journal-entry-line/account "TEST-1"
|
||||
:journal-entry-line/debit 13.50}
|
||||
|
||||
{:journal-entry-line/account "TEST-1"
|
||||
:journal-entry-line/debit 19.50}])
|
||||
{:journal-entry-line/account "TEST-1"
|
||||
:journal-entry-line/debit 19.50}]})
|
||||
(sut/refresh-current-balance)
|
||||
(is (= -33.0
|
||||
(:bank-account/current-balance (d/entity (d/db conn) [:bank-account/code "TEST-1"])))))
|
||||
(pull-attr (dc/db conn) :bank-account/current-balance [:bank-account/code "TEST-1"]))))
|
||||
|
||||
(testing "bank accounts should start in a needing refresh state"
|
||||
(let [bank-account-id (-> @(d/transact (d/connect uri)
|
||||
[{:client/code "TEST"
|
||||
:db/id "TEST"
|
||||
:client/bank-accounts [{:bank-account/code "TEST-2" :db/id "TEST-2"}]}
|
||||
])
|
||||
(let [bank-account-id (-> (dc/transact conn
|
||||
{:tx-data
|
||||
[{:client/code "TEST"
|
||||
:db/id "TEST"
|
||||
:client/bank-accounts [{:bank-account/code "TEST-2" :db/id "TEST-2"}]}
|
||||
]})
|
||||
:tempids
|
||||
(get "TEST-2"))]
|
||||
|
||||
(is ((sut/bank-accounts-needing-refresh) bank-account-id ))))
|
||||
|
||||
(testing "bank accounts should not need a refresh if balance is up-to-date"
|
||||
(let [bank-account-id (-> @(d/transact (d/connect uri)
|
||||
[{:client/code "TEST"
|
||||
:db/id "TEST"
|
||||
:client/bank-accounts [{:bank-account/code "TEST-3" :db/id "TEST-3"}]}
|
||||
])
|
||||
(let [bank-account-id (-> (dc/transact conn
|
||||
{:tx-data
|
||||
[{:client/code "TEST"
|
||||
:db/id "TEST"
|
||||
:client/bank-accounts [{:bank-account/code "TEST-3" :db/id "TEST-3"}]}
|
||||
]})
|
||||
:tempids
|
||||
(get "TEST-3"))]
|
||||
(sut/refresh-bank-account-current-balance bank-account-id)
|
||||
(is (not ((sut/bank-accounts-needing-refresh) bank-account-id )))
|
||||
@(d/transact (d/connect uri)
|
||||
[{:journal-entry-line/account [:bank-account/code "TEST-3"]
|
||||
:journal-entry-line/debit -10.50}
|
||||
])
|
||||
(dc/transact conn
|
||||
{:tx-data
|
||||
[{:journal-entry-line/account [:bank-account/code "TEST-3"]
|
||||
:journal-entry-line/debit -10.50}
|
||||
]})
|
||||
(is ((sut/bank-accounts-needing-refresh) bank-account-id ))
|
||||
(sut/refresh-bank-account-current-balance bank-account-id)
|
||||
(is (not ((sut/bank-accounts-needing-refresh) bank-account-id ))))))
|
||||
|
||||
@@ -1,55 +1,26 @@
|
||||
(ns auto-ap.integration.graphql.invoices
|
||||
(:require
|
||||
[auto-ap.datomic :refer [conn uri]]
|
||||
[auto-ap.datomic.migrate :as m]
|
||||
[auto-ap.time-reader]
|
||||
[auto-ap.datomic :refer [conn]]
|
||||
[auto-ap.graphql.invoices :as sut]
|
||||
[clj-time.core :as time]
|
||||
[clojure.test :as t :refer [deftest is testing use-fixtures]]
|
||||
[datomic.api :as d]))
|
||||
|
||||
(defn wrap-setup
|
||||
[f]
|
||||
(with-redefs [auto-ap.datomic/uri "datomic:mem://datomic-transactor:4334/invoice"]
|
||||
(d/create-database uri)
|
||||
(with-redefs [auto-ap.datomic/conn (d/connect uri)]
|
||||
(m/migrate conn)
|
||||
|
||||
(f)
|
||||
(d/release conn)
|
||||
(d/delete-database uri))))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn admin-token []
|
||||
{:user "TEST ADMIN"
|
||||
:exp (time/plus (time/now) (time/days 1))
|
||||
:user/role "admin"
|
||||
:user/name "TEST ADMIN"})
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn user-token [client-id]
|
||||
{:user "TEST USER"
|
||||
:exp (time/plus (time/now) (time/days 1))
|
||||
:user/role "user"
|
||||
:user/name "TEST USER"
|
||||
:user/clients [{:db/id client-id}]})
|
||||
|
||||
[auto-ap.integration.util :refer [admin-token wrap-setup]]
|
||||
[clojure.test :as t :refer [deftest is testing use-fixtures]]))
|
||||
|
||||
(use-fixtures :each wrap-setup)
|
||||
|
||||
(deftest test-add-invoice
|
||||
(testing "It should Add an invoice"
|
||||
(let [{:strs [vendor-id client-id account-id]}
|
||||
(:tempids @(d/transact conn [{:client/code "ABC"
|
||||
:db/id "client-id"
|
||||
:client/locations ["DT"]}
|
||||
{:vendor/name "Vendy"
|
||||
:db/id "vendor-id"
|
||||
:vendor/default-account "account-id"}
|
||||
{:account/name "Account"
|
||||
:account/numeric-code 123
|
||||
:account/invoice-allowance :allowance/allowed
|
||||
:db/id "account-id"}]))]
|
||||
(:tempids (dc/transact conn
|
||||
{:tx-data [{:client/code "ABC"
|
||||
:db/id "client-id"
|
||||
:client/locations ["DT"]}
|
||||
{:vendor/name "Vendy"
|
||||
:db/id "vendor-id"
|
||||
:vendor/default-account "account-id"}
|
||||
{:account/name "Account"
|
||||
:account/numeric-code 123
|
||||
:account/invoice-allowance :allowance/allowed
|
||||
:db/id "account-id"}]}))]
|
||||
(is (some? (sut/add-invoice {:id (admin-token)}
|
||||
{:invoice {:client_id client-id
|
||||
:vendor_id vendor-id
|
||||
@@ -62,11 +33,11 @@
|
||||
nil)))
|
||||
(testing "It should prevent an expense account that isn't allowed"
|
||||
(let [{:strs [denied-account-id]}
|
||||
(:tempids @(d/transact conn [
|
||||
{:account/name "Account"
|
||||
:account/numeric-code 123
|
||||
:account/invoice-allowance :allowance/denied
|
||||
:db/id "denied-account-id"}]))]
|
||||
(:tempids (dc/transact conn
|
||||
{:tx-data [{:account/name "Account"
|
||||
:account/numeric-code 123
|
||||
:account/invoice-allowance :allowance/denied
|
||||
:db/id "denied-account-id"}]}))]
|
||||
(is (thrown? Exception (sut/add-invoice {:id (admin-token)}
|
||||
{:invoice {:client_id client-id
|
||||
:vendor_id vendor-id
|
||||
@@ -80,15 +51,15 @@
|
||||
|
||||
(testing "It should allow an expense account that is valid for the vendor"
|
||||
(let [{:strs [vendor-account-id vendor-2]}
|
||||
(:tempids @(d/transact conn [
|
||||
{:account/name "Account"
|
||||
:account/numeric-code 123
|
||||
:account/invoice-allowance :allowance/denied
|
||||
:account/vendor-allowance :allowance/allowed
|
||||
:db/id "vendor-account-id"}
|
||||
{:vendor/name "Testy"
|
||||
:vendor/default-account "vendor-account-id"
|
||||
:db/id "vendor-2"}]))]
|
||||
(:tempids (dc/transact conn {:tx-data [
|
||||
{:account/name "Account"
|
||||
:account/numeric-code 123
|
||||
:account/invoice-allowance :allowance/denied
|
||||
:account/vendor-allowance :allowance/allowed
|
||||
:db/id "vendor-account-id"}
|
||||
{:vendor/name "Testy"
|
||||
:vendor/default-account "vendor-account-id"
|
||||
:db/id "vendor-2"}]}))]
|
||||
(is (some? (sut/add-invoice {:id (admin-token)}
|
||||
{:invoice {:client_id client-id
|
||||
:vendor_id vendor-2
|
||||
|
||||
@@ -1,49 +1,21 @@
|
||||
(ns auto-ap.integration.graphql.vendors
|
||||
(:require [auto-ap.graphql.vendors :as sut2]
|
||||
[auto-ap.datomic :refer [uri conn]]
|
||||
[auto-ap.datomic.migrate :as m]
|
||||
|
||||
[clojure.test :as t :refer [deftest is testing use-fixtures]]
|
||||
[datomic.api :as d]
|
||||
[clj-time.core :as time]))
|
||||
|
||||
(defn wrap-setup
|
||||
[f]
|
||||
(with-redefs [auto-ap.datomic/uri "datomic:mem://datomic-transactor:4334/invoice"]
|
||||
(d/create-database uri)
|
||||
(with-redefs [auto-ap.datomic/conn (d/connect uri)]
|
||||
(m/migrate conn)
|
||||
(f)
|
||||
(d/release conn)
|
||||
(d/delete-database uri))))
|
||||
|
||||
(defn admin-token []
|
||||
{:user "TEST ADMIN"
|
||||
:exp (time/plus (time/now) (time/days 1))
|
||||
:user/role "admin"
|
||||
:user/name "TEST ADMIN"})
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn user-token [client-id]
|
||||
{:user "TEST USER"
|
||||
:exp (time/plus (time/now) (time/days 1))
|
||||
:user/role "user"
|
||||
:user/name "TEST USER"
|
||||
:user/clients [{:db/id client-id}]})
|
||||
|
||||
(:require
|
||||
[auto-ap.datomic :refer [conn]]
|
||||
[auto-ap.graphql.vendors :as sut2]
|
||||
[auto-ap.integration.util :refer [admin-token wrap-setup]]
|
||||
[clojure.test :as t :refer [deftest is testing use-fixtures]]
|
||||
[datomic.client.api :as dc]))
|
||||
|
||||
(use-fixtures :each wrap-setup)
|
||||
|
||||
|
||||
(deftest vendors
|
||||
(testing "vendors"
|
||||
(let [{:strs [vendor]} (:tempids @(d/transact (d/connect uri) [{:vendor/name "Test" :db/id "vendor"}
|
||||
{:db/id "client"
|
||||
:client/code "DEF"}]))]
|
||||
(let [{:strs [vendor]} (:tempids (dc/transact conn {:tx-data [{:vendor/name "Test" :db/id "vendor"}
|
||||
{:db/id "client"
|
||||
:client/code "DEF"}]}))]
|
||||
(testing "it should find vendors"
|
||||
(let [result (sut2/get-graphql {:id (admin-token)} {} {})]
|
||||
(is ((into #{} (map :id (:vendors result))) vendor ))))
|
||||
|
||||
)))
|
||||
(is ((into #{} (map :id (:vendors result))) vendor )))))))
|
||||
|
||||
|
||||
|
||||
@@ -1,20 +1,8 @@
|
||||
(ns auto-ap.integration.rule-matching
|
||||
(:require
|
||||
[auto-ap.datomic :refer [uri]]
|
||||
[auto-ap.datomic.migrate :as m]
|
||||
[auto-ap.integration.util :refer [wrap-setup]]
|
||||
[auto-ap.rule-matching :as sut]
|
||||
[clojure.test :as t]
|
||||
[datomic.api :as d]))
|
||||
|
||||
(defn wrap-setup
|
||||
[f]
|
||||
(with-redefs [auto-ap.datomic/uri "datomic:mem://datomic-transactor:4334/invoice"]
|
||||
(d/create-database uri)
|
||||
(with-redefs [auto-ap.datomic/conn (d/connect uri)]
|
||||
(m/migrate auto-ap.datomic/conn)
|
||||
(f)
|
||||
(d/release auto-ap.datomic/conn)
|
||||
(d/delete-database uri))))
|
||||
[clojure.test :as t]))
|
||||
|
||||
(t/use-fixtures :each wrap-setup)
|
||||
|
||||
|
||||
@@ -1,19 +1,7 @@
|
||||
(ns auto-ap.ledger-test
|
||||
(:require
|
||||
[auto-ap.datomic :refer [uri]]
|
||||
[auto-ap.datomic.migrate :as m]
|
||||
[clojure.test :as t]
|
||||
[datomic.api :as d]))
|
||||
|
||||
(defn wrap-setup
|
||||
[f]
|
||||
(with-redefs [auto-ap.datomic/uri "datomic:mem://datomic-transactor:4334/invoice"]
|
||||
(d/create-database uri)
|
||||
(with-redefs [auto-ap.datomic/conn (d/connect uri)]
|
||||
(m/migrate auto-ap.datomic/conn)
|
||||
(f)
|
||||
(d/release auto-ap.datomic/conn)
|
||||
(d/delete-database uri))))
|
||||
[auto-ap.integration.util :refer [wrap-setup]]
|
||||
[clojure.test :as t]))
|
||||
|
||||
(t/use-fixtures :each wrap-setup)
|
||||
|
||||
|
||||
@@ -1,26 +1,15 @@
|
||||
(ns auto-ap.routes.invoice-test
|
||||
(:require
|
||||
[auto-ap.datomic :refer [uri conn]]
|
||||
[auto-ap.datomic.migrate :as m]
|
||||
[auto-ap.datomic :refer [conn]]
|
||||
[auto-ap.integration.util :refer [user-token wrap-setup]]
|
||||
[auto-ap.routes.invoices :as sut]
|
||||
[clojure.test :as t]
|
||||
[datomic.api :as d]
|
||||
[clj-time.coerce :as coerce]))
|
||||
|
||||
(defn wrap-setup
|
||||
[f]
|
||||
(with-redefs [auto-ap.datomic/uri "datomic:mem://datomic-transactor:4334/invoice"]
|
||||
(d/create-database uri)
|
||||
(with-redefs [auto-ap.datomic/conn (d/connect uri)]
|
||||
(m/migrate auto-ap.datomic/conn)
|
||||
(f)
|
||||
(d/release auto-ap.datomic/conn)
|
||||
(d/delete-database uri))))
|
||||
[datomic.client.api :as dc]
|
||||
[clj-time.coerce :as coerce]
|
||||
[clojure.test :as t]))
|
||||
|
||||
(t/use-fixtures :each wrap-setup)
|
||||
|
||||
(def user {:user/role "admin"
|
||||
:user/name "Bryce"})
|
||||
(def user (user-token))
|
||||
|
||||
(def client {:client/code "ABC"
|
||||
:client/name "ABC"
|
||||
@@ -35,10 +24,10 @@
|
||||
|
||||
(defn invoice-count-for-client [c]
|
||||
(or
|
||||
(first (first (d/q '[:find (count ?i)
|
||||
(first (first (dc/q '[:find (count ?i)
|
||||
:in $ ?c
|
||||
:where [?i :invoice/client ?c]]
|
||||
(d/db conn) c)))
|
||||
(dc/db conn) c)))
|
||||
0))
|
||||
|
||||
(def invoice {:customer-identifier "ABC"
|
||||
@@ -49,7 +38,7 @@
|
||||
|
||||
(t/deftest import-uploaded-invoices
|
||||
(t/testing "It should import one"
|
||||
@(d/transact conn [client expense-account vendor])
|
||||
(dc/transact conn {:tx-data [client expense-account vendor]})
|
||||
|
||||
(t/is (= 0 (invoice-count-for-client [:client/code "ABC"])))
|
||||
(sut/import-uploaded-invoice user [(assoc invoice :customer-identifier "ABC")])
|
||||
@@ -69,26 +58,28 @@
|
||||
:location-override "DE"
|
||||
:customer-identifier "ABC"
|
||||
:invoice-number "789")])
|
||||
(t/is (= ["DE"] (d/q '[:find [?l ...]
|
||||
(t/is (= [["DE"]] (dc/q '[:find ?l
|
||||
:where [?i :invoice/invoice-number "789"]
|
||||
[?i :invoice/expense-accounts ?ea]
|
||||
[?ea :invoice-expense-account/location ?l]]
|
||||
(d/db conn)))))
|
||||
(dc/db conn)))))
|
||||
|
||||
(t/testing "Should code invoice"
|
||||
(let [{{:strs [my-default-account coded-vendor]} :tempids} @(d/transact conn [{:vendor/name "Coded"
|
||||
:db/id "coded-vendor"
|
||||
:vendor/terms 12
|
||||
:vendor/default-account "my-default-account"}
|
||||
{:db/id "my-default-account"
|
||||
:account/name "My default-account"}])]
|
||||
(let [{{:strs [my-default-account coded-vendor]} :tempids} (dc/transact conn
|
||||
{:tx-data
|
||||
[{:vendor/name "Coded"
|
||||
:db/id "coded-vendor"
|
||||
:vendor/terms 12
|
||||
:vendor/default-account "my-default-account"}
|
||||
{:db/id "my-default-account"
|
||||
:account/name "My default-account"}]})]
|
||||
(sut/import-uploaded-invoice user [(assoc invoice
|
||||
:invoice-number "456"
|
||||
:customer-identifier "ABC"
|
||||
:vendor-code "Coded")])
|
||||
(let [[result] (d/q '[:find [(pull ?i [*]) ...]
|
||||
(let [[[result]] (dc/q '[:find (pull ?i [*])
|
||||
:where [?i :invoice/invoice-number "456"]]
|
||||
(d/db conn))]
|
||||
(dc/db conn))]
|
||||
(t/is (= coded-vendor (:db/id (:invoice/vendor result))))
|
||||
(t/is (= [my-default-account]
|
||||
(map (comp :db/id :invoice-expense-account/account) (:invoice/expense-accounts result))))
|
||||
|
||||
Reference in New Issue
Block a user