mirror of
https://github.com/penpot/penpot.git
synced 2025-01-26 08:29:42 -05:00
183f0a5400
And fix many tests.
65 lines
2.3 KiB
Clojure
65 lines
2.3 KiB
Clojure
(ns uxbox.tests.test-services-user-attrs
|
|
(:require
|
|
[clojure.spec.alpha :as s]
|
|
[clojure.test :as t]
|
|
[promesa.core :as p]
|
|
[uxbox.db :as db]
|
|
[uxbox.http :as http]
|
|
[uxbox.services.mutations :as sm]
|
|
[uxbox.services.queries :as sq]
|
|
[uxbox.tests.helpers :as th]))
|
|
|
|
(t/use-fixtures :once th/state-init)
|
|
(t/use-fixtures :each th/database-reset)
|
|
|
|
(t/deftest test-user-attrs
|
|
(let [{:keys [id] :as user} @(th/create-user db/pool 1)]
|
|
(let [out (th/try-on! (sq/handle {::sq/type :user-attr
|
|
:key "foobar"
|
|
:user id}))]
|
|
(t/is (nil? (:result out)))
|
|
|
|
(let [error (:error out)]
|
|
(t/is (th/ex-info? error))
|
|
(t/is (th/ex-of-type? error :service-error)))
|
|
|
|
(let [error (ex-cause (:error out))]
|
|
(t/is (th/ex-info? error))
|
|
(t/is (th/ex-of-type? error :not-found))))
|
|
|
|
(let [out (th/try-on! (sm/handle {::sm/type :upsert-user-attr
|
|
:user id
|
|
:key "foobar"
|
|
:val {:some #{:value}}}))]
|
|
;; (th/print-result! out)
|
|
(t/is (nil? (:error out)))
|
|
(t/is (nil? (:result out))))
|
|
|
|
(let [out (th/try-on! (sq/handle {::sq/type :user-attr
|
|
:key "foobar"
|
|
:user id}))]
|
|
;; (th/print-result! out)
|
|
(t/is (nil? (:error out)))
|
|
(t/is (= {:some #{:value}} (get-in out [:result :val])))
|
|
(t/is (= "foobar" (get-in out [:result :key]))))
|
|
|
|
(let [out (th/try-on! (sm/handle {::sm/type :delete-user-attr
|
|
:user id
|
|
:key "foobar"}))]
|
|
;; (th/print-result! out)
|
|
(t/is (nil? (:error out)))
|
|
(t/is (nil? (:result out))))
|
|
|
|
(let [out (th/try-on! (sq/handle {::sq/type :user-attr
|
|
:key "foobar"
|
|
:user id}))]
|
|
;; (th/print-result! out)
|
|
(t/is (nil? (:result out)))
|
|
(let [error (:error out)]
|
|
(t/is (th/ex-info? error))
|
|
(t/is (th/ex-of-type? error :service-error)))
|
|
|
|
(let [error (ex-cause (:error out))]
|
|
(t/is (th/ex-info? error))
|
|
(t/is (th/ex-of-type? error :not-found))))))
|
|
|