 (ns daveconservatoire.server.parser-tests
   (:require-macros [cljs.core.async.macros :refer [go]])
   (:require [cljs.test :refer [is are run-tests async testing deftest do-report]]
-            [cljs.core.async :refer [<!]]
+            [cljs.core.async :refer [<?]]
             [pathom.test :refer [async-test]]
             [common.async :refer [<?]]
             [pathom.sql :as ps]

  (async-test
    (testing "reading me when logged in"
      (is (= (->> (p/parse (assoc env :current-user-id 720
                                      :http-request (blank-request)) [{:app/me [:db/id]}]) <!
                  :app/me)
             {:db/id 720 :db/table :user})))
    (testing "blank map when user is not signed in"
      (is (= (->> (p/parse (assoc env :http-request (blank-request)) [{:app/me [:db/id]}]) <!
                  :app/me)
             {:db/id -1})))
    (testing "get score for guest user"
      (testing "zero when there is no information"
        (is (= (->> (p/parse (assoc env :http-request (blank-request)) [{:app/me [:user/score]}]) <!
                    :app/me)
               {:user/score 0})))
      (testing "sum the scores"
        (let [req (js-obj "session" (js-obj ":guest-tx" (pr-str [{:guest-tx/increase-score 4}
                                                                 {:guest-tx/increase-score 3}])))]
          (is (= (->> (p/parse (assoc env :http-request req) [{:app/me [:user/score]}]) <!
                      :app/me)
                 {:user/score 7})))))))


(deftest parse-read-not-found
  (async done
    (go
      (is (= (<? (p/parse {} [:invalid]))
             {:invalid [:error :not-found]}))
      (done))))

