tons of small fixes.
This commit is contained in:
@@ -92,6 +92,15 @@
|
||||
(is (int? (:start result)))
|
||||
(is (seqable? (:journal-entries result)))))))
|
||||
|
||||
|
||||
(deftest vendors
|
||||
(testing "vendors"
|
||||
(testing "it should find vendors"
|
||||
(let [result (:ledger-page (:data (sut/query (admin-token) "{ ledger_page(client_id: null) { count, start, journal_entries { id } }}")))]
|
||||
(is (int? (:count result)))
|
||||
(is (int? (:start result)))
|
||||
(is (seqable? (:journal-entries result)))))))
|
||||
|
||||
(deftest transaction-rule-page
|
||||
(testing "it should find rules"
|
||||
(let [result (-> (sut/query (admin-token) "{ transaction_rule_page(client_id: null) { count, start, transaction_rules { id } }}")
|
||||
|
||||
81
test/clj/auto_ap/graphql/vendors.clj
Normal file
81
test/clj/auto_ap/graphql/vendors.clj
Normal file
@@ -0,0 +1,81 @@
|
||||
(ns clj.auto-ap.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/-main false)
|
||||
(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"})
|
||||
|
||||
(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}]})
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
(defn new-invoice [args]
|
||||
(merge {:invoice/total 100.0
|
||||
:invoice/invoice-number (.toString (java.util.UUID/randomUUID))}
|
||||
args))
|
||||
|
||||
(use-fixtures :each wrap-setup)
|
||||
|
||||
|
||||
(deftest vendors
|
||||
(testing "vendors"
|
||||
(let [{:strs [vendor client]} (:tempids @(d/transact (d/connect uri) [{:vendor/name "Test" :db/id "vendor"}
|
||||
{:db/id "client"
|
||||
:client/code "DEF"}]))]
|
||||
(testing "it should find vendors"
|
||||
(let [result (sut2/get-graphql {} {} {})]
|
||||
(is (= 1 (count result)))))
|
||||
|
||||
(testing "It should count invoice usages for each client"
|
||||
@(d/transact (d/connect uri)
|
||||
[{:invoice/client client
|
||||
:invoice/invoice-number "123"
|
||||
:invoice/vendor vendor}])
|
||||
|
||||
|
||||
(let [result (sut2/get-graphql {:id (admin-token)} {} {})]
|
||||
(is (= [{:client_id client
|
||||
:count 1}] (-> result first :usage)))))
|
||||
|
||||
(testing "It should count transaction usages for each client"
|
||||
@(d/transact (d/connect uri)
|
||||
[{:transaction/client client
|
||||
:transaction/vendor vendor}])
|
||||
(let [result (sut2/get-graphql {:id (admin-token)} {} {})]
|
||||
(is (= [{:client_id client
|
||||
:count 2}] (-> result first :usage)))))
|
||||
|
||||
(testing "It should limit usages to visible clients"
|
||||
(let [result (sut2/get-graphql {:id (user-token client)} {} {})]
|
||||
(is (= [{:client_id client
|
||||
:count 2}] (-> result first :usage))))
|
||||
|
||||
(let [result (sut2/get-graphql {:id (user-token 0)} {} {})]
|
||||
(is (= nil (-> result first :usage))))))))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user