mirror of
https://github.com/penpot/penpot.git
synced 2025-08-04 01:09:39 +02:00
🔥 Remove deprecated queries and mutations
This commit is contained in:
parent
36953eef1a
commit
c0ccbaebaf
23 changed files with 105 additions and 978 deletions
|
@ -29,7 +29,6 @@
|
|||
[app.rpc.commands.files-update :as files.update]
|
||||
[app.rpc.commands.teams :as teams]
|
||||
[app.rpc.helpers :as rph]
|
||||
[app.rpc.mutations.profile :as profile]
|
||||
[app.util.blob :as blob]
|
||||
[app.util.services :as sv]
|
||||
[app.util.time :as dt]
|
||||
|
@ -231,7 +230,7 @@
|
|||
([pool i {:keys [profile-id project-id] :as params}]
|
||||
(us/assert uuid? profile-id)
|
||||
(us/assert uuid? project-id)
|
||||
(dm/with-open [conn (db/open pool)]
|
||||
(db/with-atomic [conn (db/open pool)]
|
||||
(files.create/create-file conn
|
||||
(merge {:id (mk-uuid "file" i)
|
||||
:name (str "file" i)
|
||||
|
@ -367,7 +366,7 @@
|
|||
|
||||
(defn command!
|
||||
[{:keys [::type] :as data}]
|
||||
(let [[mdata method-fn] (get-in *system* [:app.rpc/methods :commands type])]
|
||||
(let [[mdata method-fn] (get-in *system* [:app.rpc/methods type])]
|
||||
(when-not method-fn
|
||||
(ex/raise :type :assertion
|
||||
:code :rpc-method-not-found
|
||||
|
@ -378,23 +377,6 @@
|
|||
(dissoc ::type)
|
||||
(assoc :app.rpc/request-at (dt/now)))))))
|
||||
|
||||
(defn mutation!
|
||||
[{:keys [::type profile-id] :as data}]
|
||||
(let [[mdata method-fn] (get-in *system* [:app.rpc/methods :mutations type])]
|
||||
(try-on! (method-fn (-> data
|
||||
(dissoc ::type)
|
||||
(assoc ::rpc/profile-id profile-id)
|
||||
(d/without-nils))))))
|
||||
|
||||
(defn query!
|
||||
[{:keys [::type profile-id] :as data}]
|
||||
(let [[mdata method-fn] (get-in *system* [:app.rpc/methods :queries type])]
|
||||
(try-on! (method-fn (-> data
|
||||
(dissoc ::type)
|
||||
(assoc ::rpc/profile-id profile-id)
|
||||
(d/without-nils))))))
|
||||
|
||||
|
||||
(defn run-task!
|
||||
([name]
|
||||
(run-task! name {}))
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
res (th/run-task! :process-webhook-event
|
||||
{:props
|
||||
{:app.loggers.webhooks/event
|
||||
{:type "mutation"
|
||||
{:type "command"
|
||||
:name "create-project"
|
||||
:props {:team-id (:default-team-id prof)}}}})]
|
||||
|
||||
|
@ -37,7 +37,7 @@
|
|||
res (th/run-task! :process-webhook-event
|
||||
{:props
|
||||
{:app.loggers.webhooks/event
|
||||
{:type "mutation"
|
||||
{:type "command"
|
||||
:name "create-project"
|
||||
:props {:team-id (:default-team-id prof)}}}})]
|
||||
|
||||
|
@ -48,7 +48,7 @@
|
|||
(with-mocks [http-mock {:target 'app.http.client/req! :return {:status 200}}]
|
||||
(let [prof (th/create-profile* 1 {:is-active true})
|
||||
whk (th/create-webhook* {:team-id (:default-team-id prof)})
|
||||
evt {:type "mutation"
|
||||
evt {:type "command"
|
||||
:name "create-project"
|
||||
:props {:team-id (:default-team-id prof)}}
|
||||
res (th/run-task! :run-webhook
|
||||
|
@ -73,7 +73,7 @@
|
|||
(with-mocks [http-mock {:target 'app.http.client/req! :return {:status 400}}]
|
||||
(let [prof (th/create-profile* 1 {:is-active true})
|
||||
whk (th/create-webhook* {:team-id (:default-team-id prof)})
|
||||
evt {:type "mutation"
|
||||
evt {:type "command"
|
||||
:name "create-project"
|
||||
:props {:team-id (:default-team-id prof)}}
|
||||
res (th/run-task! :run-webhook
|
||||
|
|
|
@ -129,12 +129,12 @@
|
|||
:mtype "image/jpeg"
|
||||
:size 312043}
|
||||
params {::th/type :upload-file-media-object
|
||||
:profile-id profile-id
|
||||
::rpc/profile-id profile-id
|
||||
:file-id file-id
|
||||
:is-local true
|
||||
:name "testfile"
|
||||
:content mfile}
|
||||
out (th/mutation! params)]
|
||||
out (th/command! params)]
|
||||
|
||||
;; (th/print-result! out)
|
||||
(t/is (nil? (:error out)))
|
||||
|
|
|
@ -26,11 +26,11 @@
|
|||
:is-shared false})
|
||||
url "https://raw.githubusercontent.com/uxbox/uxbox/develop/sample_media/images/unsplash/anna-pelzer.jpg"
|
||||
params {::th/type :create-file-media-object-from-url
|
||||
:profile-id (:id prof)
|
||||
::rpc/profile-id (:id prof)
|
||||
:file-id (:id file)
|
||||
:is-local true
|
||||
:url url}
|
||||
out (th/mutation! params)]
|
||||
out (th/command! params)]
|
||||
|
||||
;; (th/print-result! out)
|
||||
(t/is (nil? (:error out)))
|
||||
|
@ -66,12 +66,12 @@
|
|||
:size 312043}
|
||||
|
||||
params {::th/type :upload-file-media-object
|
||||
:profile-id (:id prof)
|
||||
::rpc/profile-id (:id prof)
|
||||
:file-id (:id file)
|
||||
:is-local true
|
||||
:name "testfile"
|
||||
:content mfile}
|
||||
out (th/mutation! params)]
|
||||
out (th/command! params)]
|
||||
|
||||
;; (th/print-result! out)
|
||||
(t/is (nil? (:error out)))
|
||||
|
@ -105,7 +105,7 @@
|
|||
:size 312043}
|
||||
|
||||
params {::th/type :upload-file-media-object
|
||||
:profile-id (:id prof)
|
||||
::rpc/profile-id (:id prof)
|
||||
:file-id (:id file)
|
||||
:is-local true
|
||||
:name "testfile"
|
||||
|
@ -113,7 +113,7 @@
|
|||
:id (uuid/next)}]
|
||||
|
||||
;; First try
|
||||
(let [{:keys [result error] :as out} (th/mutation! params)]
|
||||
(let [{:keys [result error] :as out} (th/command! params)]
|
||||
;; (th/print-result! out)
|
||||
(t/is (nil? error))
|
||||
(t/is (= (:id params) (:id result)))
|
||||
|
@ -125,7 +125,7 @@
|
|||
(t/is (uuid? (:thumbnail-id result))))
|
||||
|
||||
;; Second try
|
||||
(let [{:keys [result error] :as out} (th/mutation! params)]
|
||||
(let [{:keys [result error] :as out} (th/command! params)]
|
||||
;; (th/print-result! out)
|
||||
(t/is (nil? error))
|
||||
(t/is (= (:id params) (:id result)))
|
||||
|
|
|
@ -24,11 +24,11 @@
|
|||
|
||||
;; create project
|
||||
(let [data {::th/type :create-project
|
||||
::rpc/profile-id (:id profile)
|
||||
:id project-id
|
||||
:profile-id (:id profile)
|
||||
:team-id (:id team)
|
||||
:name "test project"}
|
||||
out (th/mutation! data)]
|
||||
out (th/command! data)]
|
||||
;; (th/print-result! out)
|
||||
|
||||
(t/is (nil? (:error out)))
|
||||
|
@ -36,10 +36,10 @@
|
|||
(t/is (= (:name data) (:name result)))))
|
||||
|
||||
;; query the list of projects of a team
|
||||
(let [data {::th/type :projects
|
||||
:team-id (:id team)
|
||||
:profile-id (:id profile)}
|
||||
out (th/query! data)]
|
||||
(let [data {::th/type :get-projects
|
||||
::rpc/profile-id (:id profile)
|
||||
:team-id (:id team)}
|
||||
out (th/command! data)]
|
||||
;; (th/print-result! out)
|
||||
|
||||
(t/is (nil? (:error out)))
|
||||
|
@ -49,9 +49,9 @@
|
|||
(t/is (= "test project" (get-in result [0 :name])))))
|
||||
|
||||
;; query all projects of a user
|
||||
(let [data {::th/type :all-projects
|
||||
:profile-id (:id profile)}
|
||||
out (th/query! data)]
|
||||
(let [data {::th/type :get-all-projects
|
||||
::rpc/profile-id (:id profile)}
|
||||
out (th/command! data)]
|
||||
;; (th/print-result! out)
|
||||
|
||||
(t/is (nil? (:error out)))
|
||||
|
@ -68,19 +68,19 @@
|
|||
|
||||
;; rename project
|
||||
(let [data {::th/type :rename-project
|
||||
::rpc/profile-id (:id profile)
|
||||
:id project-id
|
||||
:name "renamed project"
|
||||
:profile-id (:id profile)}
|
||||
out (th/mutation! data)]
|
||||
:name "renamed project"}
|
||||
out (th/command! data)]
|
||||
;; (th/print-result! out)
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (nil? (:result out))))
|
||||
|
||||
;; retrieve project
|
||||
(let [data {::th/type :project
|
||||
:id project-id
|
||||
:profile-id (:id profile)}
|
||||
out (th/query! data)]
|
||||
(let [data {::th/type :get-project
|
||||
::rpc/profile-id (:id profile)
|
||||
:id project-id}
|
||||
out (th/command! data)]
|
||||
;; (th/print-result! out)
|
||||
(t/is (nil? (:error out)))
|
||||
(let [result (:result out)]
|
||||
|
@ -88,19 +88,19 @@
|
|||
|
||||
;; delete project
|
||||
(let [data {::th/type :delete-project
|
||||
:id project-id
|
||||
:profile-id (:id profile)}
|
||||
out (th/mutation! data)]
|
||||
::rpc/profile-id (:id profile)
|
||||
:id project-id}
|
||||
out (th/command! data)]
|
||||
|
||||
;; (th/print-result! out)
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (nil? (:result out))))
|
||||
|
||||
;; query a list of projects after delete
|
||||
(let [data {::th/type :projects
|
||||
:team-id (:id team)
|
||||
:profile-id (:id profile)}
|
||||
out (th/query! data)]
|
||||
(let [data {::th/type :get-projects
|
||||
::rpc/profile-id (:id profile)
|
||||
:team-id (:id team)}
|
||||
out (th/command! data)]
|
||||
;; (th/print-result! out)
|
||||
(t/is (nil? (:error out)))
|
||||
(let [result (:result out)]
|
||||
|
@ -112,10 +112,10 @@
|
|||
profile2 (th/create-profile* 2)
|
||||
|
||||
data {::th/type :create-project
|
||||
:profile-id (:id profile2)
|
||||
::rpc/profile-id (:id profile2)
|
||||
:team-id (:default-team-id profile1)
|
||||
:name "test project"}
|
||||
out (th/mutation! data)
|
||||
out (th/command! data)
|
||||
error (:error out)]
|
||||
|
||||
;; (th/print-result! out)
|
||||
|
@ -128,10 +128,10 @@
|
|||
project (th/create-project* 1 {:team-id (:default-team-id profile1)
|
||||
:profile-id (:id profile1)})
|
||||
data {::th/type :rename-project
|
||||
::rpc/profile-id (:id profile2)
|
||||
:id (:id project)
|
||||
:profile-id (:id profile2)
|
||||
:name "foobar"}
|
||||
out (th/mutation! data)
|
||||
out (th/command! data)
|
||||
error (:error out)]
|
||||
|
||||
;; (th/print-result! out)
|
||||
|
@ -144,9 +144,9 @@
|
|||
project (th/create-project* 1 {:team-id (:default-team-id profile1)
|
||||
:profile-id (:id profile1)})
|
||||
data {::th/type :delete-project
|
||||
:id (:id project)
|
||||
:profile-id (:id profile2)}
|
||||
out (th/mutation! data)
|
||||
::rpc/profile-id (:id profile2)
|
||||
:id (:id project)}
|
||||
out (th/command! data)
|
||||
error (:error out)]
|
||||
|
||||
;; (th/print-result! out)
|
||||
|
@ -159,12 +159,12 @@
|
|||
project (th/create-project* 1 {:team-id (:default-team-id profile1)
|
||||
:profile-id (:id profile1)})
|
||||
data {::th/type :update-project-pin
|
||||
::rpc/profile-id (:id profile2)
|
||||
:id (:id project)
|
||||
:team-id (:default-team-id profile1)
|
||||
:profile-id (:id profile2)
|
||||
:is-pinned true}
|
||||
|
||||
out (th/mutation! data)
|
||||
out (th/command! data)
|
||||
error (:error out)]
|
||||
|
||||
;; (th/print-result! out)
|
||||
|
@ -184,10 +184,10 @@
|
|||
(t/is (= 0 (:processed result))))
|
||||
|
||||
;; query the list of projects
|
||||
(let [data {::th/type :projects
|
||||
:team-id (:default-team-id profile1)
|
||||
:profile-id (:id profile1)}
|
||||
out (th/query! data)]
|
||||
(let [data {::th/type :get-projects
|
||||
::rpc/profile-id (:id profile1)
|
||||
:team-id (:default-team-id profile1)}
|
||||
out (th/command! data)]
|
||||
;; (th/print-result! out)
|
||||
(t/is (nil? (:error out)))
|
||||
(let [result (:result out)]
|
||||
|
@ -195,16 +195,16 @@
|
|||
|
||||
;; Request project to be deleted
|
||||
(let [params {::th/type :delete-project
|
||||
:id (:id project)
|
||||
:profile-id (:id profile1)}
|
||||
out (th/mutation! params)]
|
||||
::rpc/profile-id (:id profile1)
|
||||
:id (:id project)}
|
||||
out (th/command! params)]
|
||||
(t/is (nil? (:error out))))
|
||||
|
||||
;; query the list of projects after soft deletion
|
||||
(let [data {::th/type :projects
|
||||
:team-id (:default-team-id profile1)
|
||||
:profile-id (:id profile1)}
|
||||
out (th/query! data)]
|
||||
(let [data {::th/type :get-projects
|
||||
::rpc/profile-id (:id profile1)
|
||||
:team-id (:default-team-id profile1)}
|
||||
out (th/command! data)]
|
||||
;; (th/print-result! out)
|
||||
(t/is (nil? (:error out)))
|
||||
(let [result (:result out)]
|
||||
|
|
|
@ -70,12 +70,12 @@
|
|||
profile-2 (th/create-profile* 2)
|
||||
team-id (:default-team-id profile-1)
|
||||
data {::th/type :create-project
|
||||
:profile-id (:id profile-1)
|
||||
::rpc/profile-id (:id profile-1)
|
||||
:team-id team-id}
|
||||
|
||||
check-ok! (fn [name]
|
||||
(let [data (assoc data :name (str "project" name))
|
||||
out (th/mutation! data)]
|
||||
out (th/command! data)]
|
||||
;; (th/print-result! out)
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (some? (:result out)))))
|
||||
|
@ -83,7 +83,7 @@
|
|||
check-ko! (fn [name]
|
||||
;; create second project
|
||||
(let [data (assoc data :name (str "project" name))
|
||||
out (th/mutation! data)]
|
||||
out (th/command! data)]
|
||||
;; (th/print-result! out)
|
||||
(t/is (not (th/success? out)))
|
||||
(let [error (:error out)]
|
||||
|
|
|
@ -321,10 +321,10 @@
|
|||
(t/is (= 0 (:processed result))))
|
||||
|
||||
;; query the list of projects after hard deletion
|
||||
(let [data {::th/type :projects
|
||||
:profile-id (:id profile1)
|
||||
(let [data {::th/type :get-projects
|
||||
::rpc/profile-id (:id profile1)
|
||||
:team-id (:id team)}
|
||||
out (th/query! data)]
|
||||
out (th/command! data)]
|
||||
;; (th/print-result! out)
|
||||
(t/is (not (th/success? out)))
|
||||
(let [edata (-> out :error ex-data)]
|
||||
|
@ -335,10 +335,10 @@
|
|||
(t/is (= 1 (:processed result))))
|
||||
|
||||
;; query the list of projects of a after hard deletion
|
||||
(let [data {::th/type :projects
|
||||
:profile-id (:id profile1)
|
||||
(let [data {::th/type :get-projects
|
||||
::rpc/profile-id (:id profile1)
|
||||
:team-id (:id team)}
|
||||
out (th/query! data)]
|
||||
out (th/command! data)]
|
||||
;; (th/print-result! out)
|
||||
|
||||
(t/is (not (th/success? out)))
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
[backend-tests.helpers :as th]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.db :as db]
|
||||
[app.rpc :as-alias rpc]
|
||||
[clojure.test :as t]
|
||||
[datoteka.core :as fs]))
|
||||
|
||||
|
@ -27,13 +28,13 @@
|
|||
share-id (atom nil)]
|
||||
|
||||
(t/testing "authenticated with page-id"
|
||||
(let [data {::th/type :view-only-bundle
|
||||
:profile-id (:id prof)
|
||||
(let [data {::th/type :get-view-only-bundle
|
||||
::rpc/profile-id (:id prof)
|
||||
:file-id (:id file)
|
||||
:page-id (get-in file [:data :pages 0])
|
||||
:components-v2 true}
|
||||
|
||||
out (th/query! data)]
|
||||
out (th/command! data)]
|
||||
|
||||
;; (th/print-result! out)
|
||||
(t/is (nil? (:error out)))
|
||||
|
@ -47,12 +48,12 @@
|
|||
|
||||
(t/testing "generate share token"
|
||||
(let [data {::th/type :create-share-link
|
||||
:profile-id (:id prof)
|
||||
::rpc/profile-id (:id prof)
|
||||
:file-id (:id file)
|
||||
:pages #{(get-in file [:data :pages 0])}
|
||||
:who-comment "team"
|
||||
:who-inspect "all"}
|
||||
out (th/mutation! data)]
|
||||
out (th/command! data)]
|
||||
|
||||
;; (th/print-result! out)
|
||||
(t/is (nil? (:error out)))
|
||||
|
@ -61,12 +62,12 @@
|
|||
(reset! share-id (:id result)))))
|
||||
|
||||
(t/testing "not authenticated with page-id"
|
||||
(let [data {::th/type :view-only-bundle
|
||||
:profile-id (:id prof2)
|
||||
(let [data {::th/type :get-view-only-bundle
|
||||
::rpc/profile-id (:id prof2)
|
||||
:file-id (:id file)
|
||||
:page-id (get-in file [:data :pages 0])
|
||||
:components-v2 true}
|
||||
out (th/query! data)]
|
||||
out (th/command! data)]
|
||||
|
||||
;; (th/print-result! out)
|
||||
(let [error (:error out)
|
||||
|
@ -76,13 +77,13 @@
|
|||
(t/is (= (:code error-data) :object-not-found)))))
|
||||
|
||||
(t/testing "authenticated with token & profile"
|
||||
(let [data {::th/type :view-only-bundle
|
||||
:profile-id (:id prof2)
|
||||
(let [data {::th/type :get-view-only-bundle
|
||||
::rpc/profile-id (:id prof2)
|
||||
:share-id @share-id
|
||||
:file-id (:id file)
|
||||
:page-id (get-in file [:data :pages 0])
|
||||
:components-v2 true}
|
||||
out (th/query! data)]
|
||||
out (th/command! data)]
|
||||
|
||||
;; (th/print-result! out)
|
||||
(t/is (nil? (:error out)))
|
||||
|
@ -92,12 +93,12 @@
|
|||
(t/is (contains? result :project)))))
|
||||
|
||||
(t/testing "authenticated with token"
|
||||
(let [data {::th/type :view-only-bundle
|
||||
(let [data {::th/type :get-view-only-bundle
|
||||
:share-id @share-id
|
||||
:file-id (:id file)
|
||||
:page-id (get-in file [:data :pages 0])
|
||||
:components-v2 true}
|
||||
out (th/query! data)]
|
||||
out (th/command! data)]
|
||||
|
||||
;; (th/print-result! out)
|
||||
(t/is (nil? (:error out)))
|
||||
|
|
|
@ -6,12 +6,13 @@
|
|||
|
||||
(ns backend-tests.storage-test
|
||||
(:require
|
||||
[backend-tests.helpers :as th]
|
||||
[app.common.exceptions :as ex]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.db :as db]
|
||||
[app.rpc :as-alias rpc]
|
||||
[app.storage :as sto]
|
||||
[app.util.time :as dt]
|
||||
[backend-tests.helpers :as th]
|
||||
[clojure.test :as t]
|
||||
[cuerdas.core :as str]
|
||||
[datoteka.core :as fs]
|
||||
|
@ -134,14 +135,14 @@
|
|||
:size 312043}
|
||||
|
||||
params {::th/type :upload-file-media-object
|
||||
:profile-id (:id prof)
|
||||
::rpc/profile-id (:id prof)
|
||||
:file-id (:id file)
|
||||
:is-local true
|
||||
:name "testfile"
|
||||
:content mfile}
|
||||
|
||||
out1 (th/mutation! params)
|
||||
out2 (th/mutation! params)]
|
||||
out1 (th/command! params)
|
||||
out2 (th/command! params)]
|
||||
|
||||
(t/is (nil? (:error out1)))
|
||||
(t/is (nil? (:error out2)))
|
||||
|
@ -209,14 +210,14 @@
|
|||
:size 312043}
|
||||
|
||||
params1 {::th/type :upload-file-media-object
|
||||
:profile-id (:id prof)
|
||||
::rpc/profile-id (:id prof)
|
||||
:file-id (:id file)
|
||||
:is-local true
|
||||
:name "testfile"
|
||||
:content mfile}
|
||||
|
||||
params2 {::th/type :create-font-variant
|
||||
:profile-id (:id prof)
|
||||
::rpc/profile-id (:id prof)
|
||||
:team-id team-id
|
||||
:font-id font-id
|
||||
:font-family "somefont"
|
||||
|
@ -224,8 +225,8 @@
|
|||
:font-style "normal"
|
||||
:data {"font/ttf" ttfdata}}
|
||||
|
||||
out1 (th/mutation! params1)
|
||||
out2 (th/mutation! params2)]
|
||||
out1 (th/command! params1)
|
||||
out2 (th/command! params2)]
|
||||
|
||||
;; (th/print-result! out)
|
||||
|
||||
|
@ -275,14 +276,14 @@
|
|||
:size 312043}
|
||||
|
||||
params {::th/type :upload-file-media-object
|
||||
:profile-id (:id prof)
|
||||
::rpc/profile-id (:id prof)
|
||||
:file-id (:id file)
|
||||
:is-local true
|
||||
:name "testfile"
|
||||
:content mfile}
|
||||
|
||||
out1 (th/mutation! params)
|
||||
out2 (th/mutation! params)]
|
||||
out1 (th/command! params)
|
||||
out2 (th/command! params)]
|
||||
|
||||
(t/is (nil? (:error out1)))
|
||||
(t/is (nil? (:error out2)))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue