account tests.
This commit is contained in:
@@ -1,44 +1,11 @@
|
||||
(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]
|
||||
[auto-ap.integration.util :refer [admin-token user-token wrap-setup]]
|
||||
[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}]})
|
||||
|
||||
|
||||
(use-fixtures :each wrap-setup)
|
||||
|
||||
(deftest test-account-search
|
||||
@@ -164,4 +131,75 @@
|
||||
:vendor_id vendor-id}
|
||||
nil))))))))
|
||||
|
||||
(deftest get-graphql
|
||||
(testing "should retrieve a single account"
|
||||
(d/transact conn [{:account/numeric-code 1
|
||||
:account/default-allowance :allowance/allowed
|
||||
:account/type :account-type/asset
|
||||
:account/location "A"
|
||||
:account/name "Test"}])
|
||||
(is (= {:name "Test",
|
||||
:invoice_allowance nil,
|
||||
:numeric_code 1,
|
||||
:vendor_allowance nil,
|
||||
:location "A",
|
||||
:applicability nil}
|
||||
(dissoc (first (:accounts (sut/get-graphql {:id (admin-token)} {} nil)))
|
||||
:id
|
||||
:type
|
||||
:default_allowance)))))
|
||||
|
||||
(deftest upsert-account
|
||||
(testing "should create a new account"
|
||||
(let [result (sut/upsert-account {:id (admin-token)} {:account {:client_overrides []
|
||||
:numeric_code 123
|
||||
:location "A"
|
||||
:applicability :global
|
||||
:account-set "global"
|
||||
:name "Test"
|
||||
:invoice-allowance :allowed
|
||||
:vendor-allowance :allowed
|
||||
:type :asset}} nil)]
|
||||
(is (= {:search_terms "Test",
|
||||
:name "Test",
|
||||
:invoice_allowance :allowed,
|
||||
:numeric_code 123,
|
||||
:code "123",
|
||||
:account_set "global",
|
||||
:vendor_allowance :allowed,
|
||||
:location "A",
|
||||
:applicability :global}
|
||||
(dissoc result
|
||||
:id
|
||||
:type
|
||||
:default_allowance)))
|
||||
(testing "Should allow updating account"
|
||||
(let [edit-result (sut/upsert-account {:id (admin-token)} {:account {:client_overrides []
|
||||
:id (:id result)
|
||||
:numeric_code 890
|
||||
:location "B"
|
||||
:applicability :global
|
||||
:account-set "global"
|
||||
:name "Hello"
|
||||
:invoice-allowance :denied
|
||||
:vendor-allowance :denied
|
||||
:type :expense}} nil)]
|
||||
(is (= {:search_terms "Hello",
|
||||
:name "Hello",
|
||||
:invoice_allowance :denied,
|
||||
:code "123",
|
||||
:account_set "global",
|
||||
:vendor_allowance :denied,
|
||||
:location "B",
|
||||
:applicability :global}
|
||||
(dissoc edit-result
|
||||
:id
|
||||
:type
|
||||
:default_allowance
|
||||
:numeric_code)))
|
||||
(testing "Should not allow changing numeric code"
|
||||
|
||||
(is (= 123 (:numeric_code edit-result)))
|
||||
))))))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user