From 1718f49a90968cc7fc6b1139bfbd0be5f9ba2c3d Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 2 Jan 2023 15:49:08 +0100 Subject: [PATCH] :lipstick: Fix code consistency issues on comments rpc methods related to the ::rpc/profile-id usage. --- backend/src/app/rpc.clj | 40 +++-- backend/src/app/rpc/commands/audit.clj | 2 +- backend/src/app/rpc/commands/comments.clj | 4 +- backend/src/app/rpc/commands/files.clj | 32 ++-- backend/src/app/rpc/commands/management.clj | 19 +- backend/src/app/rpc/commands/profile.clj | 4 +- backend/src/app/rpc/commands/search.clj | 7 +- backend/src/app/rpc/commands/teams.clj | 21 ++- backend/src/app/rpc/commands/viewer.clj | 4 +- backend/src/app/rpc/queries/files.clj | 5 +- backend/test/backend_tests/helpers.clj | 1 - backend/test/backend_tests/rpc_file_test.clj | 178 +++++++++---------- backend/test/backend_tests/rpc_team_test.clj | 96 +++++----- 13 files changed, 211 insertions(+), 202 deletions(-) diff --git a/backend/src/app/rpc.clj b/backend/src/app/rpc.clj index 26e39ef09..3700a9321 100644 --- a/backend/src/app/rpc.clj +++ b/backend/src/app/rpc.clj @@ -72,12 +72,14 @@ internal async flow into ring async flow." [methods {:keys [profile-id session-id params] :as request} respond raise] (let [type (keyword (:type params)) - data (into {::http/request request} params) + data (-> params + (assoc ::request-at (dt/now)) + (assoc ::http/request request)) data (if profile-id - (assoc data - :profile-id profile-id - ::profile-id profile-id - ::session-id session-id) + (-> data + (assoc :profile-id profile-id) + (assoc ::profile-id profile-id) + (assoc ::session-id session-id)) (dissoc data :profile-id ::profile-id)) method (get methods type default-handler)] @@ -93,14 +95,15 @@ internal async flow into ring async flow." [methods {:keys [profile-id session-id params] :as request} respond raise] (let [type (keyword (:type params)) - data (into {::http/request request} params) + data (-> params + (assoc ::request-at (dt/now)) + (assoc ::http/request request)) data (if profile-id - (assoc data - :profile-id profile-id - ::profile-id profile-id - ::session-id session-id) + (-> data + (assoc :profile-id profile-id) + (assoc ::profile-id profile-id) + (assoc ::session-id session-id)) (dissoc data :profile-id ::profile-id)) - method (get methods type default-handler)] (-> (method data) (p/then (partial handle-response request)) @@ -115,12 +118,15 @@ [methods {:keys [profile-id session-id params] :as request} respond raise] (let [cmd (keyword (:type params)) etag (yrq/get-header request "if-none-match") - data (into {::request-at (dt/now) - ::http/request request - ::cond/key etag} params) - data (if profile-id - (assoc data ::profile-id profile-id ::session-id session-id) - (dissoc data ::profile-id)) + + data (-> params + (assoc ::request-at (dt/now)) + (assoc ::http/request request) + (assoc ::cond/key etag) + (cond-> (uuid? profile-id) + (-> (assoc ::profile-id profile-id) + (assoc ::session-id session-id)))) + method (get methods cmd default-handler)] (binding [cond/*enabled* true] (-> (method data) diff --git a/backend/src/app/rpc/commands/audit.clj b/backend/src/app/rpc/commands/audit.clj index 44efcd7f4..b12e12b22 100644 --- a/backend/src/app/rpc/commands/audit.clj +++ b/backend/src/app/rpc/commands/audit.clj @@ -72,7 +72,7 @@ (sv/defmethod ::push-audit-events {::climit/queue :push-audit-events - ::climit/key-fn :profile-id + ::climit/key-fn ::rpc/profile-id ::audit/skip true ::doc/added "1.17"} [{:keys [::db/pool ::wrk/executor] :as cfg} params] diff --git a/backend/src/app/rpc/commands/comments.clj b/backend/src/app/rpc/commands/comments.clj index 168c5a295..73e40642f 100644 --- a/backend/src/app/rpc/commands/comments.clj +++ b/backend/src/app/rpc/commands/comments.clj @@ -288,7 +288,9 @@ (sv/defmethod ::create-comment-thread {::doc/added "1.15" ::webhooks/event? true} - [{:keys [::db/pool] :as cfg} {:keys [::rpc/profile-id ::rpc/request-at file-id page-id share-id position content frame-id]}] + [{:keys [::db/pool] :as cfg} + {:keys [::rpc/profile-id ::rpc/request-at file-id page-id share-id position content frame-id]}] + (db/with-atomic [conn pool] (let [{:keys [team-id project-id page-name] :as file} (get-file conn file-id page-id)] (files/check-comment-permissions! conn profile-id file-id share-id) diff --git a/backend/src/app/rpc/commands/files.clj b/backend/src/app/rpc/commands/files.clj index affa92e57..059d3aa94 100644 --- a/backend/src/app/rpc/commands/files.clj +++ b/backend/src/app/rpc/commands/files.clj @@ -268,7 +268,7 @@ {::doc/added "1.17" ::cond/get-object #(get-minimal-file %1 (:id %2)) ::cond/key-fn get-file-etag} - [{:keys [pool] :as cfg} {:keys [::rpc/profile-id id features] :as params}] + [{:keys [pool] :as cfg} {:keys [::rpc/profile-id id features]}] (with-open [conn (db/open pool)] (let [perms (get-permissions conn profile-id id)] (check-read-permissions! perms) @@ -296,7 +296,7 @@ "Retrieve a file by its ID. Only authenticated users." {::doc/added "1.17" ::rpc/:auth false} - [{:keys [pool] :as cfg} {:keys [::rpc/profile-id file-id fragment-id share-id] :as params}] + [{:keys [pool] :as cfg} {:keys [::rpc/profile-id file-id fragment-id share-id] }] (with-open [conn (db/open pool)] (let [perms (get-permissions conn profile-id file-id share-id)] (check-read-permissions! perms) @@ -363,7 +363,7 @@ (sv/defmethod ::get-project-files "Get all files for the specified project." {::doc/added "1.17"} - [{:keys [pool] :as cfg} {:keys [::rpc/profile-id project-id] :as params}] + [{:keys [pool] :as cfg} {:keys [::rpc/profile-id project-id]}] (with-open [conn (db/open pool)] (projects/check-read-permissions! conn profile-id project-id) (get-project-files conn project-id))) @@ -376,15 +376,16 @@ (s/def ::file-id ::us/uuid) (s/def ::has-file-libraries - (s/keys :req [::rpc/profile-id] :req-un [::file-id])) + (s/keys :req [::rpc/profile-id] + :req-un [::file-id])) (sv/defmethod ::has-file-libraries "Checks if the file has libraries. Returns a boolean" {::doc/added "1.15.1"} - [{:keys [pool] :as cfg} {:keys [::rpc/profile-id file-id] :as params}] + [{:keys [pool] :as cfg} {:keys [::rpc/profile-id file-id]}] (with-open [conn (db/open pool)] (check-read-permissions! pool profile-id file-id) - (get-has-file-libraries conn params))) + (get-has-file-libraries conn file-id))) (def ^:private sql:has-file-libraries "SELECT COUNT(*) > 0 AS has_libraries @@ -395,7 +396,7 @@ fl.deleted_at > now())") (defn- get-has-file-libraries - [conn {:keys [file-id]}] + [conn file-id] (let [row (db/exec-one! conn [sql:has-file-libraries file-id])] (:has-libraries row))) @@ -474,7 +475,7 @@ order by f.modified_at desc") (defn get-team-shared-files - [conn {:keys [team-id] :as params}] + [conn team-id] (letfn [(assets-sample [assets limit] (let [sorted-assets (->> (vals assets) (sort-by #(str/lower (:name %))))] @@ -494,14 +495,16 @@ (map #(dissoc % :data))))))) (s/def ::get-team-shared-files - (s/keys :req [::rpc/profile-id] :req-un [::team-id])) + (s/keys :req [::rpc/profile-id] + :req-un [::team-id])) (sv/defmethod ::get-team-shared-files "Get all file (libraries) for the specified team." {::doc/added "1.17"} - [{:keys [pool] :as cfg} params] + [{:keys [pool] :as cfg} {:keys [::rpc/profile-id team-id]}] (with-open [conn (db/open pool)] - (get-team-shared-files conn params))) + (teams/check-read-permissions! conn profile-id team-id) + (get-team-shared-files conn team-id))) ;; --- COMMAND QUERY: get-file-libraries @@ -552,7 +555,7 @@ (sv/defmethod ::get-file-libraries "Get libraries used by the specified file." {::doc/added "1.17"} - [{:keys [pool] :as cfg} {:keys [::rpc/profile-id file-id features] :as params}] + [{:keys [pool] :as cfg} {:keys [::rpc/profile-id file-id features]}] (with-open [conn (db/open pool)] (check-read-permissions! conn profile-id file-id) (get-file-libraries conn file-id features))) @@ -583,7 +586,6 @@ (check-read-permissions! conn profile-id file-id) (get-library-file-references conn file-id))) - ;; --- COMMAND QUERY: get-team-recent-files (def sql:team-recent-files @@ -765,7 +767,7 @@ ;; --- MUTATION COMMAND: rename-file (defn rename-file - [conn {:keys [id name] :as params}] + [conn {:keys [id name]}] (db/update! conn :file {:name name :modified-at (dt/now)} @@ -899,7 +901,7 @@ ;; --- MUTATION COMMAND: unlink-file-from-library (defn unlink-file-from-library - [conn {:keys [file-id library-id] :as params}] + [conn {:keys [file-id library-id]}] (db/delete! conn :file-library-rel {:file-id file-id :library-file-id library-id})) diff --git a/backend/src/app/rpc/commands/management.clj b/backend/src/app/rpc/commands/management.clj index f3f882ef5..2337ff844 100644 --- a/backend/src/app/rpc/commands/management.clj +++ b/backend/src/app/rpc/commands/management.clj @@ -46,9 +46,9 @@ "Duplicate a single file in the same team." {::doc/added "1.16" ::webhooks/event? true} - [{:keys [pool] :as cfg} params] + [{:keys [pool] :as cfg} {:keys [::rpc/profile-id] :as params}] (db/with-atomic [conn pool] - (duplicate-file conn (assoc params :profile-id (::rpc/profile-id params))))) + (duplicate-file conn (assoc params :profile-id profile-id)))) (defn- remap-id [item index key] @@ -136,7 +136,7 @@ and so.deleted_at is null") (defn duplicate-file* - [conn {:keys [profile-id file index project-id name flibs fmeds]} {:keys [reset-shared-flag] :as opts}] + [conn {:keys [profile-id file index project-id name flibs fmeds]} {:keys [reset-shared-flag]}] (let [flibs (or flibs (db/exec! conn [sql:retrieve-used-libraries (:id file)])) fmeds (or fmeds (db/exec! conn [sql:retrieve-used-media-objects (:id file)])) @@ -329,10 +329,9 @@ "Move a set of files from one project to other." {::doc/added "1.16" ::webhooks/event? true} - [{:keys [pool] :as cfg} params] + [{:keys [pool] :as cfg} {:keys [::rpc/profile-id] :as params}] (db/with-atomic [conn pool] - (move-files conn (assoc params :profile-id (::rpc/profile-id params))))) - + (move-files conn (assoc params :profile-id profile-id)))) ;; --- COMMAND: Move project @@ -370,9 +369,9 @@ "Move projects between teams." {::doc/added "1.16" ::webhooks/event? true} - [{:keys [pool] :as cfg} params] + [{:keys [pool] :as cfg} {:keys [::rpc/profile-id] :as params}] (db/with-atomic [conn pool] - (move-project conn (assoc params :profile-id (::rpc/profile-id params))))) + (move-project conn (assoc params :profile-id profile-id)))) ;; --- COMMAND: Clone Template @@ -387,10 +386,10 @@ "Clone into the specified project the template by its id." {::doc/added "1.16" ::webhooks/event? true} - [{:keys [pool] :as cfg} params] + [{:keys [pool] :as cfg} {:keys [::rpc/profile-id] :as params}] (db/with-atomic [conn pool] (-> (assoc cfg :conn conn) - (clone-template (assoc params :profile-id (::rpc/profile-id params)))))) + (clone-template (assoc params :profile-id profile-id))))) (defn- clone-template [{:keys [conn templates] :as cfg} {:keys [profile-id template-id project-id]}] diff --git a/backend/src/app/rpc/commands/profile.clj b/backend/src/app/rpc/commands/profile.clj index 876b609df..141664b8c 100644 --- a/backend/src/app/rpc/commands/profile.clj +++ b/backend/src/app/rpc/commands/profile.clj @@ -34,10 +34,10 @@ {::climit/queue :auth ::climit/key-fn ::rpc/profile-id ::doc/added "1.18"} - [{:keys [::db/pool]} {:keys [password] :as params}] + [{:keys [::db/pool]} {:keys [::rpc/profile-id password]}] (db/with-atomic [conn pool] (let [admins (cf/get :admins) - profile (db/get-by-id conn :profile (::rpc/profile-id params))] + profile (db/get-by-id conn :profile profile-id)] (if (or (:is-admin profile) (contains? admins (:email profile))) diff --git a/backend/src/app/rpc/commands/search.clj b/backend/src/app/rpc/commands/search.clj index 92534fafc..5f1ddc559 100644 --- a/backend/src/app/rpc/commands/search.clj +++ b/backend/src/app/rpc/commands/search.clj @@ -48,7 +48,7 @@ order by f.created_at asc") (defn search-files - [conn {:keys [::rpc/profile-id team-id search-term] :as params}] + [conn profile-id team-id search-term] (db/exec! conn [sql:search-files profile-id team-id profile-id team-id @@ -64,6 +64,5 @@ (sv/defmethod ::search-files {::doc/added "1.17"} - [{:keys [pool]} {:keys [search-term] :as params}] - (when search-term - (search-files pool params))) + [{:keys [pool]} {:keys [::rpc/profile-id team-id search-term]}] + (some->> search-term (search-files pool profile-id team-id))) diff --git a/backend/src/app/rpc/commands/teams.clj b/backend/src/app/rpc/commands/teams.clj index f040a034f..bf2346f2f 100644 --- a/backend/src/app/rpc/commands/teams.clj +++ b/backend/src/app/rpc/commands/teams.clj @@ -385,14 +385,8 @@ (declare role->params) -(s/def ::reassign-to ::us/uuid) -(s/def ::leave-team - (s/keys :req [::rpc/profile-id] - :req-un [::id] - :opt-un [::reassign-to])) - (defn leave-team - [conn {:keys [::rpc/profile-id id reassign-to]}] + [conn {:keys [profile-id id reassign-to]}] (let [perms (get-permissions conn profile-id id) members (retrieve-team-members conn id)] @@ -437,12 +431,17 @@ nil)) +(s/def ::reassign-to ::us/uuid) +(s/def ::leave-team + (s/keys :req [::rpc/profile-id] + :req-un [::id] + :opt-un [::reassign-to])) (sv/defmethod ::leave-team {::doc/added "1.17"} - [{:keys [pool] :as cfg} params] + [{:keys [pool] :as cfg} {:keys [::rpc/profile-id] :as params}] (db/with-atomic [conn pool] - (leave-team conn params))) + (leave-team conn (assoc params :profile-id profile-id)))) ;; --- Mutation: Delete Team @@ -539,9 +538,9 @@ (sv/defmethod ::update-team-member-role {::doc/added "1.17"} - [{:keys [::db/pool] :as cfg} params] + [{:keys [::db/pool] :as cfg} {:keys [::rpc/profile-id] :as params}] (db/with-atomic [conn pool] - (update-team-member-role conn (assoc params :profile-id (::rpc/profile-id params))))) + (update-team-member-role conn (assoc params :profile-id profile-id)))) ;; --- Mutation: Delete Team Member diff --git a/backend/src/app/rpc/commands/viewer.clj b/backend/src/app/rpc/commands/viewer.clj index b68dc7e53..c19e84824 100644 --- a/backend/src/app/rpc/commands/viewer.clj +++ b/backend/src/app/rpc/commands/viewer.clj @@ -84,6 +84,6 @@ ::cond/key-fn files/get-file-etag ::cond/reuse-key? true ::doc/added "1.17"} - [{:keys [pool]} params] + [{:keys [pool]} {:keys [::rpc/profile-id] :as params}] (with-open [conn (db/open pool)] - (get-view-only-bundle conn (assoc params :profile-id (::rpc/profile-id params))))) + (get-view-only-bundle conn (assoc params :profile-id profile-id)))) diff --git a/backend/src/app/rpc/queries/files.clj b/backend/src/app/rpc/queries/files.clj index 398b1400a..3dc5d9f92 100644 --- a/backend/src/app/rpc/queries/files.clj +++ b/backend/src/app/rpc/queries/files.clj @@ -179,6 +179,5 @@ (sv/defmethod ::search-files {::doc/added "1.0" ::doc/deprecated "1.17"} - [{:keys [pool]} {:keys [search-term] :as params}] - (when search-term - (search/search-files pool params))) + [{:keys [pool]} {:keys [profile-id team-id search-term]}] + (some->> search-term (search/search-files pool profile-id team-id))) diff --git a/backend/test/backend_tests/helpers.clj b/backend/test/backend_tests/helpers.clj index a14dd4374..29c48e116 100644 --- a/backend/test/backend_tests/helpers.clj +++ b/backend/test/backend_tests/helpers.clj @@ -332,7 +332,6 @@ (let [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! diff --git a/backend/test/backend_tests/rpc_file_test.clj b/backend/test/backend_tests/rpc_file_test.clj index 068aa5a51..b2f6eba1d 100644 --- a/backend/test/backend_tests/rpc_file_test.clj +++ b/backend/test/backend_tests/rpc_file_test.clj @@ -6,13 +6,14 @@ (ns backend-tests.rpc-file-test (:require - [backend-tests.helpers :as th] [app.common.uuid :as uuid] [app.db :as db] [app.db.sql :as sql] [app.http :as http] + [app.rpc :as-alias rpc] [app.storage :as sto] [app.util.time :as dt] + [backend-tests.helpers :as th] [clojure.test :as t] [datoteka.core :as fs])) @@ -28,13 +29,13 @@ (t/testing "create file" (let [data {::th/type :create-file - :profile-id (:id prof) + ::rpc/profile-id (:id prof) :project-id proj-id :id file-id :name "foobar" :is-shared false :components-v2 true} - out (th/mutation! data)] + out (th/command! data)] ;; (th/print-result! out) (t/is (nil? (:error out))) @@ -47,8 +48,8 @@ (let [data {::th/type :rename-file :id file-id :name "new name" - :profile-id (:id prof)} - out (th/mutation! data)] + ::rpc/profile-id (:id prof)} + out (th/command! data)] ;; (th/print-result! out) (let [result (:result out)] @@ -56,10 +57,10 @@ (t/is (= (:name data) (:name result)))))) (t/testing "query files" - (let [data {::th/type :project-files - :project-id proj-id - :profile-id (:id prof)} - out (th/query! data)] + (let [data {::th/type :get-project-files + ::rpc/profile-id (:id prof) + :project-id proj-id} + out (th/command! data)] ;; (th/print-result! out) (t/is (nil? (:error out))) @@ -70,11 +71,11 @@ (t/is (= "new name" (get-in result [0 :name])))))) (t/testing "query single file without users" - (let [data {::th/type :file - :profile-id (:id prof) + (let [data {::th/type :get-file + ::rpc/profile-id (:id prof) :id file-id :components-v2 true} - out (th/query! data)] + out (th/command! data)] ;; (th/print-result! out) (t/is (nil? (:error out))) @@ -88,18 +89,18 @@ (t/testing "delete file" (let [data {::th/type :delete-file :id file-id - :profile-id (:id prof)} - out (th/mutation! data)] + ::rpc/profile-id (:id prof)} + out (th/command! data)] ;; (th/print-result! out) (t/is (nil? (:error out))) (t/is (nil? (:result out))))) (t/testing "query single file after delete" - (let [data {::th/type :file - :profile-id (:id prof) + (let [data {::th/type :get-file + ::rpc/profile-id (:id prof) :id file-id :components-v2 true} - out (th/query! data)] + out (th/command! data)] ;; (th/print-result! out) @@ -109,10 +110,10 @@ (t/is (= (:type error-data) :not-found))))) (t/testing "query list files after delete" - (let [data {::th/type :project-files - :project-id proj-id - :profile-id (:id prof)} - out (th/query! data)] + (let [data {::th/type :get-project-files + ::rpc/profile-id (:id prof) + :project-id proj-id} + out (th/command! data)] ;; (th/print-result! out) (t/is (nil? (:error out))) @@ -136,7 +137,6 @@ out (th/mutation! params)] ;; (th/print-result! out) - (t/is (nil? (:error out))) (:result out))) @@ -144,11 +144,11 @@ (let [params {::th/type :update-file :id file-id :session-id (uuid/random) - :profile-id profile-id + ::rpc/profile-id profile-id :revn revn :components-v2 true :changes changes} - out (th/mutation! params)] + out (th/command! params)] (t/is (nil? (:error out))) (:result out)))] @@ -257,12 +257,12 @@ profile2 (th/create-profile* 2) data {::th/type :create-file - :profile-id (:id profile2) + ::rpc/profile-id (:id profile2) :project-id (:default-project-id profile1) :name "foobar" :is-shared false :components-v2 true} - out (th/mutation! data) + out (th/command! data) error (:error out)] ;; (th/print-result! out) @@ -277,9 +277,9 @@ :profile-id (:id profile1)}) data {::th/type :rename-file :id (:id file) - :profile-id (:id profile2) + ::rpc/profile-id (:id profile2) :name "foobar"} - out (th/mutation! data) + out (th/command! data) error (:error out)] ;; (th/print-result! out) @@ -293,9 +293,9 @@ file (th/create-file* 1 {:project-id (:default-project-id profile1) :profile-id (:id profile1)}) data {::th/type :delete-file - :profile-id (:id profile2) + ::rpc/profile-id (:id profile2) :id (:id file)} - out (th/mutation! data) + out (th/command! data) error (:error out)] ;; (th/print-result! out) @@ -308,10 +308,10 @@ file (th/create-file* 1 {:project-id (:default-project-id profile1) :profile-id (:id profile1)}) data {::th/type :set-file-shared - :profile-id (:id profile2) + ::rpc/profile-id (:id profile2) :id (:id file) :is-shared true} - out (th/mutation! data) + out (th/command! data) error (:error out)] ;; (th/print-result! out) @@ -328,11 +328,11 @@ :profile-id (:id profile1)}) data {::th/type :link-file-to-library - :profile-id (:id profile2) + ::rpc/profile-id (:id profile2) :file-id (:id file2) :library-id (:id file1)} - out (th/mutation! data) + out (th/command! data) error (:error out)] ;; (th/print-result! out) @@ -350,11 +350,11 @@ :profile-id (:id profile2)}) data {::th/type :link-file-to-library - :profile-id (:id profile2) + ::rpc/profile-id (:id profile2) :file-id (:id file2) :library-id (:id file1)} - out (th/mutation! data) + out (th/command! data) error (:error out)] ;; (th/print-result! out) @@ -372,10 +372,10 @@ (t/is (= 0 (:processed result)))) ;; query the list of files - (let [data {::th/type :project-files - :project-id (:default-project-id profile1) - :profile-id (:id profile1)} - out (th/query! data)] + (let [data {::th/type :get-project-files + ::rpc/profile-id (:id profile1) + :project-id (:default-project-id profile1)} + out (th/command! data)] ;; (th/print-result! out) (t/is (nil? (:error out))) (let [result (:result out)] @@ -384,15 +384,15 @@ ;; Request file to be deleted (let [params {::th/type :delete-file :id (:id file) - :profile-id (:id profile1)} - out (th/mutation! params)] + ::rpc/profile-id (:id profile1)} + out (th/command! params)] (t/is (nil? (:error out)))) ;; query the list of files after soft deletion - (let [data {::th/type :project-files - :project-id (:default-project-id profile1) - :profile-id (:id profile1)} - out (th/query! data)] + (let [data {::th/type :get-project-files + ::rpc/profile-id (:id profile1) + :project-id (:default-project-id profile1)} + out (th/command! data)] ;; (th/print-result! out) (t/is (nil? (:error out))) (let [result (:result out)] @@ -403,10 +403,10 @@ (t/is (= 0 (:processed result)))) ;; query the list of file libraries of a after hard deletion - (let [data {::th/type :file-libraries - :file-id (:id file) - :profile-id (:id profile1)} - out (th/query! data)] + (let [data {::th/type :get-file-libraries + ::rpc/profile-id (:id profile1) + :file-id (:id file)} + out (th/command! data)] ;; (th/print-result! out) (t/is (nil? (:error out))) (let [result (:result out)] @@ -417,10 +417,10 @@ (t/is (= 1 (:processed result)))) ;; query the list of file libraries of a after hard deletion - (let [data {::th/type :file-libraries - :file-id (:id file) - :profile-id (:id profile1)} - out (th/query! data)] + (let [data {::th/type :get-file-libraries + ::rpc/profile-id (:id profile1) + :file-id (:id file)} + out (th/command! data)] ;; (th/print-result! out) (let [error (:error out) error-data (ex-data error)] @@ -483,11 +483,11 @@ (t/testing "RPC page query (rendering purposes)" ;; Query :page RPC method without passing page-id - (let [data {::th/type :page - :profile-id (:id prof) + (let [data {::th/type :get-page + ::rpc/profile-id (:id prof) :file-id (:id file) :components-v2 true} - {:keys [error result] :as out} (th/query! data)] + {:keys [error result] :as out} (th/command! data)] ;; (th/print-result! out) (t/is (map? result)) @@ -500,12 +500,12 @@ ) ;; Query :page RPC method with page-id - (let [data {::th/type :page - :profile-id (:id prof) + (let [data {::th/type :get-page + ::rpc/profile-id (:id prof) :file-id (:id file) :page-id page-id :components-v2 true} - {:keys [error result] :as out} (th/query! data)] + {:keys [error result] :as out} (th/command! data)] ;; (th/print-result! out) (t/is (map? result)) (t/is (contains? result :objects)) @@ -516,13 +516,13 @@ (t/is (contains? (:objects result) uuid/zero))) ;; Query :page RPC method with page-id and object-id - (let [data {::th/type :page - :profile-id (:id prof) + (let [data {::th/type :get-page + ::rpc/profile-id (:id prof) :file-id (:id file) :page-id page-id :object-id frame1-id :components-v2 true} - {:keys [error result] :as out} (th/query! data)] + {:keys [error result] :as out} (th/command! data)] ;; (th/print-result! out) (t/is (nil? error)) (t/is (map? result)) @@ -534,12 +534,12 @@ (t/is (not (contains? (:objects result) shape2-id)))) ;; Query :page RPC method with wrong params - (let [data {::th/type :page - :profile-id (:id prof) + (let [data {::th/type :get-page + ::rpc/profile-id (:id prof) :file-id (:id file) :object-id frame1-id :components-v2 true} - out (th/query! data)] + out (th/command! data)] (t/is (not (th/success? out))) (let [{:keys [type code]} (-> out :error ex-data)] @@ -551,21 +551,21 @@ (t/testing "RPC :file-data-for-thumbnail" ;; Insert a thumbnail data for the frame-id (let [data {::th/type :upsert-file-object-thumbnail - :profile-id (:id prof) + ::rpc/profile-id (:id prof) :file-id (:id file) :object-id (str page-id frame1-id) :data "random-data-1"} - {:keys [error result] :as out} (th/mutation! data)] + {:keys [error result] :as out} (th/command! data)] (t/is (nil? error)) (t/is (nil? result))) ;; Check the result - (let [data {::th/type :file-data-for-thumbnail - :profile-id (:id prof) + (let [data {::th/type :get-file-data-for-thumbnail + ::rpc/profile-id (:id prof) :file-id (:id file) :components-v2 true} - {:keys [error result] :as out} (th/query! data)] + {:keys [error result] :as out} (th/command! data)] ;; (th/print-result! out) (t/is (map? result)) (t/is (contains? result :page)) @@ -578,21 +578,21 @@ ;; Delete thumbnail data (let [data {::th/type :upsert-file-object-thumbnail - :profile-id (:id prof) + ::rpc/profile-id (:id prof) :file-id (:id file) :object-id (str page-id frame1-id) :data nil} - {:keys [error result] :as out} (th/mutation! data)] + {:keys [error result] :as out} (th/command! data)] ;; (th/print-result! out) (t/is (nil? error)) (t/is (nil? result))) ;; Check the result - (let [data {::th/type :file-data-for-thumbnail - :profile-id (:id prof) + (let [data {::th/type :get-file-data-for-thumbnail + ::rpc/profile-id (:id prof) :file-id (:id file) :components-v2 true} - {:keys [error result] :as out} (th/query! data)] + {:keys [error result] :as out} (th/command! data)] ;; (th/print-result! out) (t/is (map? result)) (t/is (contains? result :page)) @@ -606,11 +606,11 @@ ;; insert object snapshot for known frame (let [data {::th/type :upsert-file-object-thumbnail - :profile-id (:id prof) + ::rpc/profile-id (:id prof) :file-id (:id file) :object-id (str page-id frame1-id) :data "new-data"} - {:keys [error result] :as out} (th/mutation! data)] + {:keys [error result] :as out} (th/command! data)] (t/is (nil? error)) (t/is (nil? result))) @@ -629,11 +629,11 @@ ;; insert object snapshot for for unknown frame (let [data {::th/type :upsert-file-object-thumbnail - :profile-id (:id prof) + ::rpc/profile-id (:id prof) :file-id (:id file) :object-id (str page-id (uuid/next)) :data "new-data-2"} - {:keys [error result] :as out} (th/mutation! data)] + {:keys [error result] :as out} (th/command! data)] (t/is (nil? error)) (t/is (nil? result))) @@ -661,8 +661,8 @@ :project-id (:default-project-id prof) :revn 2 :is-shared false}) - data {::th/type :file-thumbnail - :profile-id (:id prof) + data {::th/type :get-file-thumbnail + ::rpc/profile-id (:id prof) :file-id (:id file)}] (t/testing "query a thumbnail with single revn" @@ -673,7 +673,7 @@ :revn 1 :data "testvalue1"}) - (let [{:keys [result error] :as out} (th/query! data)] + (let [{:keys [result error] :as out} (th/command! data)] ;; (th/print-result! out) (t/is (nil? error)) (t/is (= 4 (count result))) @@ -687,7 +687,7 @@ :revn 2 :data "testvalue2"}) - (let [{:keys [result error] :as out} (th/query! data)] + (let [{:keys [result error] :as out} (th/command! data)] ;; (th/print-result! out) (t/is (nil? error)) (t/is (= 4 (count result))) @@ -695,7 +695,7 @@ (t/is (= 2 (:revn result)))) ;; Then query the specific revn - (let [{:keys [result error] :as out} (th/query! (assoc data :revn 1))] + (let [{:keys [result error] :as out} (th/command! (assoc data :revn 1))] ;; (th/print-result! out) (t/is (nil? error)) (t/is (= 4 (count result))) @@ -704,18 +704,18 @@ (t/testing "upsert file-thumbnail" (let [data {::th/type :upsert-file-thumbnail - :profile-id (:id prof) + ::rpc/profile-id (:id prof) :file-id (:id file) :data "foobar" :props {:baz 1} :revn 2} - {:keys [result error] :as out} (th/mutation! data)] + {:keys [result error] :as out} (th/command! data)] ;; (th/print-result! out) (t/is (nil? error)) (t/is (nil? result)))) (t/testing "query last result" - (let [{:keys [result error] :as out} (th/query! data)] + (let [{:keys [result error] :as out} (th/command! data)] ;; (th/print-result! out) (t/is (nil? error)) (t/is (= 4 (count result))) @@ -734,7 +734,7 @@ (t/is (= 1 (:processed res)))) ;; Then query the specific revn - (let [{:keys [result error] :as out} (th/query! (assoc data :revn 1))] + (let [{:keys [result error] :as out} (th/command! (assoc data :revn 1))] (t/is (th/ex-of-type? error :not-found)) (t/is (th/ex-of-code? error :file-thumbnail-not-found)))) )) diff --git a/backend/test/backend_tests/rpc_team_test.clj b/backend/test/backend_tests/rpc_team_test.clj index 11ec08a88..d39d9fc49 100644 --- a/backend/test/backend_tests/rpc_team_test.clj +++ b/backend/test/backend_tests/rpc_team_test.clj @@ -21,7 +21,7 @@ (t/use-fixtures :once th/state-init) (t/use-fixtures :each th/database-reset) -(t/deftest invite-team-member +(t/deftest create-team-invitations (with-mocks [mock {:target 'app.emails/send! :return nil}] (let [profile1 (th/create-profile* 1 {:is-active true}) profile2 (th/create-profile* 2 {:is-active true}) @@ -30,14 +30,14 @@ team (th/create-team* 1 {:profile-id (:id profile1)}) pool (:app.db/pool th/*system*) - data {::th/type :invite-team-member + data {::th/type :create-team-invitations + ::rpc/profile-id (:id profile1) :team-id (:id team) - :role :editor - :profile-id (:id profile1)}] + :role :editor}] ;; invite external user without complaints (let [data (assoc data :email "foo@bar.com") - out (th/mutation! data) + out (th/command! data) ;; retrieve the value from the database and check its content invitation (db/exec-one! th/*pool* @@ -52,7 +52,7 @@ ;; invite internal user without complaints (th/reset-mock! mock) (let [data (assoc data :email (:email profile2)) - out (th/mutation! data)] + out (th/command! data)] (t/is (th/success? out)) (t/is (= 1 (:call-count (deref mock))))) @@ -60,7 +60,7 @@ (th/create-global-complaint-for pool {:type :complaint :email "foo@bar.com"}) (th/reset-mock! mock) (let [data (assoc data :email "foo@bar.com") - out (th/mutation! data)] + out (th/command! data)] (t/is (th/success? out)) (t/is (= 1 (:call-count (deref mock))))) @@ -79,7 +79,7 @@ (th/create-global-complaint-for pool {:type :bounce :email "foo@bar.com"}) (let [data (assoc data :email "foo@bar.com") - out (th/mutation! data)] + out (th/command! data)] (t/is (not (th/success? out))) (t/is (= 0 (:call-count @mock))) @@ -92,7 +92,7 @@ (th/reset-mock! mock) (let [data (assoc data :email (:email profile3)) - out (th/mutation! data)] + out (th/command! data)] (t/is (not (th/success? out))) (t/is (= 0 (:call-count @mock))) @@ -115,12 +115,12 @@ pool (:app.db/pool th/*system*)] ;; Try to invite a not existing user - (let [data {::th/type :invite-team-member + (let [data {::th/type :create-team-invitations + ::rpc/profile-id (:id profile1) :email "notexisting@example.com" :team-id (:id team) - :role :editor - :profile-id (:id profile1)} - out (th/mutation! data)] + :role :editor} + out (th/command! data)] ;; (th/print-result! out) (t/is (th/success? out)) @@ -139,12 +139,12 @@ (th/reset-mock! mock) ;; Try to invite existing user - (let [data {::th/type :invite-team-member + (let [data {::th/type :create-team-invitations + ::rpc/profile-id (:id profile1) :email (:email profile2) :team-id (:id team) - :role :editor - :profile-id (:id profile1)} - out (th/mutation! data)] + :role :editor} + out (th/command! data)] ;; (th/print-result! out) (t/is (th/success? out)) @@ -215,7 +215,9 @@ :role "editor" :valid-until (dt/in-future "48h")}) - (let [data {::th/type :verify-token :token token ::rpc/profile-id (:id profile2)} + (let [data {::th/type :verify-token + ::rpc/profile-id (:id profile2) + :token token} out (th/command! data)] ;; (th/print-result! out) (t/is (th/success? out)) @@ -236,7 +238,9 @@ :role "editor" :valid-until (dt/in-future "48h")}) - (let [data {::th/type :verify-token :token token ::rpc/profile-id (:id profile1)} + (let [data {::th/type :verify-token + ::rpc/profile-id (:id profile1) + :token token} out (th/command! data)] ;; (th/print-result! out) (t/is (not (th/success? out))) @@ -246,7 +250,7 @@ ))) -(t/deftest invite-team-member-with-email-verification-disabled +(t/deftest create-team-invitations-with-email-verification-disabled (with-mocks [mock {:target 'app.emails/send! :return nil}] (let [profile1 (th/create-profile* 1 {:is-active true}) profile2 (th/create-profile* 2 {:is-active true}) @@ -255,16 +259,16 @@ team (th/create-team* 1 {:profile-id (:id profile1)}) pool (:app.db/pool th/*system*) - data {::th/type :invite-team-member + data {::th/type :create-team-invitations + ::rpc/profile-id (:id profile1) :team-id (:id team) - :role :editor - :profile-id (:id profile1)}] + :role :editor}] ;; invite internal user without complaints (with-redefs [app.config/flags #{}] (th/reset-mock! mock) (let [data (assoc data :email (:email profile2)) - out (th/mutation! data)] + out (th/command! data)] (t/is (th/success? out)) (t/is (= 0 (:call-count (deref mock))))) @@ -279,8 +283,8 @@ team (th/create-team* 1 {:profile-id (:id profile1)}) pool (:app.db/pool th/*system*) data {::th/type :delete-team - :team-id (:id team) - :profile-id (:id profile1)}] + ::rpc/profile-id (:id profile1) + :team-id (:id team)}] ;; team is not deleted because it does not meet all ;; conditions to be deleted. @@ -288,9 +292,9 @@ (t/is (= 0 (:processed result)))) ;; query the list of teams - (let [data {::th/type :teams - :profile-id (:id profile1)} - out (th/query! data)] + (let [data {::th/type :get-teams + ::rpc/profile-id (:id profile1)} + out (th/command! data)] ;; (th/print-result! out) (t/is (th/success? out)) (let [result (:result out)] @@ -300,15 +304,15 @@ ;; Request team to be deleted (let [params {::th/type :delete-team - :id (:id team) - :profile-id (:id profile1)} - out (th/mutation! params)] + ::rpc/profile-id (:id profile1) + :id (:id team)} + out (th/command! params)] (t/is (th/success? out))) ;; query the list of teams after soft deletion - (let [data {::th/type :teams - :profile-id (:id profile1)} - out (th/query! data)] + (let [data {::th/type :get-teams + ::rpc/profile-id (:id profile1)} + out (th/command! data)] ;; (th/print-result! out) (t/is (th/success? out)) (let [result (:result out)] @@ -321,8 +325,8 @@ ;; query the list of projects after hard deletion (let [data {::th/type :projects - :team-id (:id team) - :profile-id (:id profile1)} + :profile-id (:id profile1) + :team-id (:id team)} out (th/query! data)] ;; (th/print-result! out) (t/is (not (th/success? out))) @@ -335,8 +339,8 @@ ;; query the list of projects of a after hard deletion (let [data {::th/type :projects - :team-id (:id team) - :profile-id (:id profile1)} + :profile-id (:id profile1) + :team-id (:id team)} out (th/query! data)] ;; (th/print-result! out) @@ -348,8 +352,8 @@ (t/deftest query-team-invitations (let [prof (th/create-profile* 1 {:is-active true}) team (th/create-team* 1 {:profile-id (:id prof)}) - data {::th/type :team-invitations - :profile-id (:id prof) + data {::th/type :get-team-invitations + ::rpc/profile-id (:id prof) :team-id (:id team)}] ;; insert an entry on the database with an enabled invitation @@ -366,7 +370,7 @@ :role "editor" :valid-until (dt/in-past "48h")}) - (let [out (th/query! data)] + (let [out (th/command! data)] (t/is (th/success? out)) (let [result (:result out) one (first result) @@ -381,7 +385,7 @@ (let [prof (th/create-profile* 1 {:is-active true}) team (th/create-team* 1 {:profile-id (:id prof)}) data {::th/type :update-team-invitation-role - :profile-id (:id prof) + ::rpc/profile-id (:id prof) :team-id (:id team) :email "TEST1@mail.com" :role :admin}] @@ -393,7 +397,7 @@ :role "editor" :valid-until (dt/in-future "48h")}) - (let [out (th/mutation! data) + (let [out (th/command! data) ;; retrieve the value from the database and check its content res (db/get* th/*pool* :team-invitation {:team-id (:team-id data) :email-to "test1@mail.com"})] @@ -405,7 +409,7 @@ (let [prof (th/create-profile* 1 {:is-active true}) team (th/create-team* 1 {:profile-id (:id prof)}) data {::th/type :delete-team-invitation - :profile-id (:id prof) + ::rpc/profile-id (:id prof) :team-id (:id team) :email "TEST1@mail.com"}] @@ -416,7 +420,7 @@ :role "editor" :valid-until (dt/in-future "48h")}) - (let [out (th/mutation! data) + (let [out (th/command! data) ;; retrieve the value from the database and check its content res (db/get* th/*pool* :team-invitation {:team-id (:team-id data) :email-to "test1@mail.com"})]