Added test for client graphql
This commit is contained in:
@@ -96,7 +96,6 @@
|
||||
(first))))
|
||||
|
||||
(defn raw-graphql-ids [db args]
|
||||
(println args)
|
||||
(let [query (cond-> {:query {:find []
|
||||
:in ['$]
|
||||
:where []}
|
||||
|
||||
@@ -15,7 +15,8 @@
|
||||
[com.walmartlabs.lacinia.util :refer [attach-resolvers]]
|
||||
[datomic.api :as d]
|
||||
[unilog.context :as lc]
|
||||
[auto-ap.graphql.utils :refer [attach-tracing-resolvers]])
|
||||
[auto-ap.graphql.utils :refer [attach-tracing-resolvers]]
|
||||
[com.brunobonacci.mulog :as mu])
|
||||
(:import
|
||||
(java.util UUID)
|
||||
(org.apache.commons.codec.binary Base64)))
|
||||
|
||||
@@ -21,10 +21,53 @@
|
||||
[mount.core :as mount]
|
||||
[nrepl.middleware.print]
|
||||
[unilog.context :as lc]
|
||||
[com.brunobonacci.mulog :as mu])
|
||||
[com.brunobonacci.mulog :as mu]
|
||||
[com.brunobonacci.mulog.buffer :as rb])
|
||||
(:import
|
||||
(org.apache.commons.io.input BOMInputStream)))
|
||||
|
||||
(defn println-event [item]
|
||||
(printf "%s - %s: %s\n" (:mulog/namespace item) (:mulog/event-name item)
|
||||
(pr-str (reduce
|
||||
(fn [acc [k v]]
|
||||
(if (= "mulog" (namespace k))
|
||||
acc
|
||||
(assoc acc k v)))
|
||||
{}
|
||||
item))))
|
||||
|
||||
|
||||
(deftype DevPublisher [config buffer transform]
|
||||
|
||||
com.brunobonacci.mulog.publisher.PPublisher
|
||||
(agent-buffer [_]
|
||||
buffer)
|
||||
|
||||
|
||||
(publish-delay [_]
|
||||
200)
|
||||
|
||||
|
||||
(publish [_ buffer]
|
||||
;; items are pairs [offset <item>]
|
||||
(doseq [item (transform (map second (rb/items buffer)))]
|
||||
(println-event item)
|
||||
)
|
||||
(flush)
|
||||
(rb/clear buffer)))
|
||||
|
||||
|
||||
|
||||
(defn dev-publisher
|
||||
[{:keys [transform pretty?] :as config}]
|
||||
(DevPublisher. config (rb/agent-buffer 10000) (or transform identity)))
|
||||
|
||||
(defmethod com.brunobonacci.mulog.publisher/publisher-factory :dev
|
||||
[config]
|
||||
(dev-publisher config))
|
||||
|
||||
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn mark-until-date [client end]
|
||||
(let [conn (d/connect uri)]
|
||||
@@ -398,7 +441,7 @@
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn start-db []
|
||||
(mu/start-publisher! {:type :console-json})
|
||||
(mu/start-publisher! {:type :dev})
|
||||
(mount.core/start (mount.core/only #{#'auto-ap.datomic/conn})))
|
||||
|
||||
|
||||
|
||||
@@ -1,38 +1,13 @@
|
||||
(ns auto-ap.integration.graphql.clients
|
||||
(:require
|
||||
[auto-ap.time-reader]
|
||||
[auto-ap.datomic :refer [conn uri]]
|
||||
[auto-ap.datomic.migrate :as m]
|
||||
[auto-ap.graphql.clients :as sut]
|
||||
[clj-time.core :as time]
|
||||
[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]))
|
||||
|
||||
(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}]})
|
||||
|
||||
|
||||
(use-fixtures :each wrap-setup)
|
||||
|
||||
(deftest current-balance
|
||||
@@ -88,3 +63,83 @@
|
||||
(sut/refresh-bank-account-current-balance bank-account-id)
|
||||
(is (not ((sut/bank-accounts-needing-refresh) bank-account-id ))))))
|
||||
|
||||
(deftest upsert-client
|
||||
(testing "Should create a new client"
|
||||
(let [create-client-request {:code "TEST"
|
||||
:name "Test Co"
|
||||
:matches ["Test Company"]
|
||||
:email "hello@hi.com"
|
||||
:locked_until #clj-time/date-time "2022-01-01"
|
||||
:locations ["DT"]
|
||||
:week_a_debits 1000.0
|
||||
:week_a_credits 2000.0
|
||||
:week_b_debits 3000.0
|
||||
:week_b_credits 9000.0
|
||||
:location_matches [{:location "DT"
|
||||
:match "DOWNTOWN"}]
|
||||
:address {:street1 "hi street"
|
||||
:street2 "downtown"
|
||||
:city "seattle"
|
||||
:state "wa"
|
||||
:zip "1238"}
|
||||
:feature_flags ["new-square"]
|
||||
:bank_accounts [{:code "TEST-1"
|
||||
:bank_name "Bank of America"
|
||||
:bank_code "BANKCODE"
|
||||
:start_date #clj-time/date-time "2022-01-01"
|
||||
:routing "1235"
|
||||
:include_in_reports true
|
||||
|
||||
:name "Bank of Am Check"
|
||||
:visible true
|
||||
:number "1000"
|
||||
:check_number 1001
|
||||
:numeric_code 12001
|
||||
:sort_order 1
|
||||
:locations ["DT"]
|
||||
:use_date_instead_of_post_date? false
|
||||
:type :cash}]
|
||||
|
||||
}
|
||||
create-result (sut/edit-client {:id (admin-token)} {:edit_client create-client-request} nil)]
|
||||
(mu/log ::result :result create-result)
|
||||
(is (some? (-> create-result :id)))
|
||||
(is (some? (-> create-result :bank_accounts first :id)))
|
||||
(is (= (set (keys create-client-request)) (disj (set (keys create-result))
|
||||
:square_integration_status :yodlee_provider_accounts :plaid_items :id)))
|
||||
|
||||
(testing "Should be able to retrieve created client"
|
||||
(let [[created-client] (sut/get-client {:id (admin-token)} nil nil)]
|
||||
(is (some? (-> created-client :id)))
|
||||
(is (some? (-> created-client :bank_accounts first :id)))
|
||||
(is (= (set (keys create-client-request)) (disj (set (keys created-client))
|
||||
:square_integration_status :yodlee_provider_accounts :plaid_items :id)))))
|
||||
|
||||
(testing "Should edit an existing client"
|
||||
(let [edit-result (sut/edit-client {:id (admin-token)} {:edit_client {:id (:id create-result)
|
||||
:name "New Company Name"
|
||||
:code "TEST"}} nil)]
|
||||
(is (some? (:id edit-result)))
|
||||
(is (= "New Company Name" (:name edit-result)))))
|
||||
|
||||
(testing "Should support removing collections"
|
||||
(let [edit-result (sut/edit-client {:id (admin-token)} {:edit_client {:id (:id create-result)
|
||||
:matches []
|
||||
:location_matches []
|
||||
:feature_flags []}}
|
||||
nil)]
|
||||
(is (some? (:id edit-result)))
|
||||
(is (seq (:location_matches create-result)))
|
||||
(is (not (seq (:location_matches edit-result))))
|
||||
|
||||
(is (seq (:matches create-result)))
|
||||
(is (not (seq (:matches edit-result))))
|
||||
|
||||
(is (seq (:feature_flags create-result)))
|
||||
(is (not (seq (:feature_flags edit-result))))
|
||||
))
|
||||
))
|
||||
|
||||
(testing "Only admins can create clients"
|
||||
(is (thrown? Exception (sut/edit-client {:id (user-token)} {:edit_client {:code "INVALID"}} nil)))))
|
||||
|
||||
|
||||
30
test/clj/auto_ap/integration/util.clj
Normal file
30
test/clj/auto_ap/integration/util.clj
Normal file
@@ -0,0 +1,30 @@
|
||||
(ns auto-ap.integration.util
|
||||
(:require
|
||||
[auto-ap.datomic :refer [conn uri]]
|
||||
[clj-time.core :as time]
|
||||
[datomic.api :as dc]
|
||||
[auto-ap.datomic.migrate :as migrate])
|
||||
)
|
||||
|
||||
(defn wrap-setup
|
||||
[f]
|
||||
(with-redefs [auto-ap.datomic/uri "datomic:mem://datomic-transactor:4334/invoice"]
|
||||
(dc/create-database uri)
|
||||
(with-redefs [auto-ap.datomic/conn (dc/connect uri)]
|
||||
(migrate/migrate conn)
|
||||
(f)
|
||||
(dc/delete-database uri))))
|
||||
|
||||
|
||||
(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}]})
|
||||
Reference in New Issue
Block a user