mirror of
https://github.com/penpot/penpot.git
synced 2025-12-11 22:14:05 +01:00
🎉 Add conditional reading to RPC
This commit is contained in:
committed by
Andrés Moya
parent
5192b36669
commit
fde03e21b0
@@ -17,6 +17,7 @@
|
||||
[app.main :as main]
|
||||
[app.media]
|
||||
[app.migrations]
|
||||
[app.rpc.helpers :as rph]
|
||||
[app.rpc.commands.auth :as cmd.auth]
|
||||
[app.rpc.commands.files :as files]
|
||||
[app.rpc.commands.files.create :as files.create]
|
||||
@@ -295,7 +296,7 @@
|
||||
[expr]
|
||||
`(try
|
||||
(let [result# (deref ~expr)
|
||||
result# (cond-> result# (sv/wrapped? result#) deref)]
|
||||
result# (cond-> result# (rph/wrapped? result#) deref)]
|
||||
{:error nil
|
||||
:result result#})
|
||||
(catch Exception e#
|
||||
|
||||
42
backend/test/backend_tests/rpc_cond_middleware_test.clj
Normal file
42
backend/test/backend_tests/rpc_cond_middleware_test.clj
Normal file
@@ -0,0 +1,42 @@
|
||||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; Copyright (c) KALEIDOS INC
|
||||
|
||||
(ns backend-tests.rpc-cond-middleware-test
|
||||
(:require
|
||||
[backend-tests.storage-test :refer [configure-storage-backend]]
|
||||
[backend-tests.helpers :as th]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.db :as db]
|
||||
[app.http :as http]
|
||||
[app.rpc.cond :as cond]
|
||||
[clojure.test :as t]
|
||||
[datoteka.core :as fs]))
|
||||
|
||||
(t/use-fixtures :once th/state-init)
|
||||
(t/use-fixtures :each th/database-reset)
|
||||
|
||||
(t/deftest conditional-requests
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
project (th/create-project* 1 {:team-id (:default-team-id profile)
|
||||
:profile-id (:id profile)})
|
||||
file1 (th/create-file* 1 {:profile-id (:id profile)
|
||||
:project-id (:id project)})
|
||||
params {::th/type :get-file :id (:id file1) :profile-id (:id profile)}]
|
||||
|
||||
(binding [cond/*enabled* true]
|
||||
(let [{:keys [error result]} (th/command! params)]
|
||||
(t/is (nil? error))
|
||||
(t/is (map? result))
|
||||
(t/is (contains? (meta result) :app.http/headers))
|
||||
(t/is (contains? (meta result) :app.rpc.cond/key))
|
||||
|
||||
(let [etag (-> result meta :app.http/headers (get "etag"))
|
||||
{:keys [error result]} (th/command! (assoc params ::cond/key etag))]
|
||||
(t/is (nil? error))
|
||||
(t/is (fn? result))
|
||||
(t/is (= 304 (-> (result nil) :status))))
|
||||
))))
|
||||
|
||||
Reference in New Issue
Block a user