(ns auto-ap.integration.graphql.users
  (:require
   [auto-ap.time-reader]
   [auto-ap.datomic :refer [conn uri]]
   [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]))

(use-fixtures :each wrap-setup)


#_(deftest edit-user
  (testing "should allow editing a user"
    

    (let [{{:strs [user-id] } :tempids} @(d/transact conn [{:db/id "user-id" :user/name "Bryce"}])
          result                        (sut/edit-user {:id (admin-token)} {:edit_user {:role :power_user :id user-id}} nil)]
      (is (some? (:id result))
          (= :power_user (:role result)))
      (testing "Should allow adding clients"
        (let [{{:strs [client-id] } :tempids} @(d/transact conn [{:db/id "client-id" :client/name "Bryce"}])
              result                          (sut/edit-user {:id (admin-token)} {:edit_user {:role    :power_user
                                                                                              :id      user-id
                                                                                              :clients [(str client-id)]}} nil)]
          (is (= client-id (get-in result [:clients 0 :id])))))
      (testing "Should allow adding clients"
        (let [result                          (sut/edit-user {:id (admin-token)} {:edit_user {:role    :power_user
                                                                                              :id      user-id
                                                                                              :clients []}} nil)]
          (is (not (seq (:clients result))))))
      (testing "Should disallow normies"
        (is (thrown? Exception (sut/edit-user {:id (user-token)} {:edit_user {:role    :power_user
                                                                             :id      user-id
                                                                             :clients []}} nil)))))))
