diff --git a/test/clj/auto_ap/integration/graphql/accounts.clj b/test/clj/auto_ap/integration/graphql/accounts.clj index de92616e..e6b9b522 100644 --- a/test/clj/auto_ap/integration/graphql/accounts.clj +++ b/test/clj/auto_ap/integration/graphql/accounts.clj @@ -143,3 +143,73 @@ :allowance :invoice :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))))))))) diff --git a/test/clj/auto_ap/integration/util.clj b/test/clj/auto_ap/integration/util.clj index b35f81c7..2615d922 100644 --- a/test/clj/auto_ap/integration/util.clj +++ b/test/clj/auto_ap/integration/util.clj @@ -20,9 +20,11 @@ :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 user-token + ([] (user-token 1)) + ([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}]}))