2019-11-25 15:56:49 +01:00
|
|
|
(ns uxbox.tests.test-services-projects
|
2019-11-18 11:52:57 +01:00
|
|
|
(:require
|
|
|
|
[clojure.test :as t]
|
|
|
|
[promesa.core :as p]
|
|
|
|
[uxbox.db :as db]
|
|
|
|
[uxbox.http :as http]
|
2019-12-01 16:48:41 +01:00
|
|
|
[uxbox.services.mutations :as sm]
|
|
|
|
[uxbox.services.queries :as sq]
|
2019-11-18 11:52:57 +01:00
|
|
|
[uxbox.tests.helpers :as th]))
|
2016-11-20 20:04:52 +01:00
|
|
|
|
2019-06-15 18:20:36 +02:00
|
|
|
(t/use-fixtures :once th/state-init)
|
2016-11-20 20:04:52 +01:00
|
|
|
(t/use-fixtures :each th/database-reset)
|
|
|
|
|
2019-12-01 16:48:41 +01:00
|
|
|
;; TODO: migrate from try-on to try-on!
|
|
|
|
|
2019-11-25 17:08:06 +01:00
|
|
|
(t/deftest query-project-list
|
2019-11-18 11:52:57 +01:00
|
|
|
(let [user @(th/create-user db/pool 1)
|
|
|
|
proj @(th/create-project db/pool (:id user) 1)
|
2019-12-01 16:48:41 +01:00
|
|
|
data {::sq/type :projects
|
2019-11-18 11:52:57 +01:00
|
|
|
:user (:id user)}
|
2019-12-01 16:48:41 +01:00
|
|
|
out (th/try-on! (sq/handle data))]
|
|
|
|
|
|
|
|
;; (th/print-result! out)
|
|
|
|
|
|
|
|
(t/is (nil? (:error out)))
|
|
|
|
(t/is (= 1 (count (:result out))))
|
|
|
|
(t/is (= (:id proj) (get-in out [:result 0 :id])))
|
|
|
|
(t/is (= (:name proj) (get-in out [:result 0 :name])))))
|
2016-11-20 20:04:52 +01:00
|
|
|
|
2019-11-25 17:08:06 +01:00
|
|
|
(t/deftest mutation-create-project
|
2019-11-18 11:52:57 +01:00
|
|
|
(let [user @(th/create-user db/pool 1)
|
2019-12-01 16:48:41 +01:00
|
|
|
data {::sm/type :create-project
|
2019-11-18 11:52:57 +01:00
|
|
|
:user (:id user)
|
|
|
|
:name "test project"}
|
2019-12-01 16:48:41 +01:00
|
|
|
[err rsp] (th/try-on (sm/handle data))]
|
2019-11-18 11:52:57 +01:00
|
|
|
;; (prn "RESPONSE:" err rsp)
|
|
|
|
(t/is (nil? err))
|
|
|
|
(t/is (= (:user data) (:user-id rsp)))
|
|
|
|
(t/is (= (:name data) (:name rsp)))))
|
2016-11-20 20:04:52 +01:00
|
|
|
|
2019-11-25 17:08:06 +01:00
|
|
|
(t/deftest mutation-update-project
|
2019-11-18 11:52:57 +01:00
|
|
|
(let [user @(th/create-user db/pool 1)
|
|
|
|
proj @(th/create-project db/pool (:id user) 1)
|
2019-12-01 16:48:41 +01:00
|
|
|
data {::sm/type :update-project
|
2019-11-18 11:52:57 +01:00
|
|
|
:id (:id proj)
|
|
|
|
:name "test project mod"
|
|
|
|
:user (:id user)}
|
2019-12-01 16:48:41 +01:00
|
|
|
[err rsp] (th/try-on (sm/handle data))]
|
2019-11-18 11:52:57 +01:00
|
|
|
;; (prn "RESPONSE:" err rsp)
|
|
|
|
(t/is (nil? err))
|
|
|
|
(t/is (= (:id data) (:id rsp)))
|
|
|
|
(t/is (= (:user data) (:user-id rsp)))
|
|
|
|
(t/is (= (:name data) (:name rsp)))))
|
2016-11-20 20:04:52 +01:00
|
|
|
|
2019-11-25 17:08:06 +01:00
|
|
|
(t/deftest mutation-delete-project
|
2019-11-18 11:52:57 +01:00
|
|
|
(let [user @(th/create-user db/pool 1)
|
|
|
|
proj @(th/create-project db/pool (:id user) 1)
|
2019-12-01 16:48:41 +01:00
|
|
|
data {::sm/type :delete-project
|
2019-11-18 11:52:57 +01:00
|
|
|
:id (:id proj)
|
|
|
|
:user (:id user)}
|
2019-12-01 16:48:41 +01:00
|
|
|
[err rsp] (th/try-on (sm/handle data))]
|
2019-11-18 11:52:57 +01:00
|
|
|
;; (prn "RESPONSE:" err rsp)
|
|
|
|
(t/is (nil? err))
|
|
|
|
(t/is (nil? rsp))
|
2016-11-20 20:04:52 +01:00
|
|
|
|
2019-11-18 11:52:57 +01:00
|
|
|
(let [sql "SELECT * FROM projects
|
|
|
|
WHERE user_id=$1 AND deleted_at is null"
|
|
|
|
res @(db/query db/pool [sql (:id user)])]
|
|
|
|
(t/is (empty? res)))))
|