scrubbed all reference to datomic.api
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user