diff --git a/backend/tests/uxbox/tests/helpers.clj b/backend/tests/uxbox/tests/helpers.clj index d6d4e9abd..5d24948c4 100644 --- a/backend/tests/uxbox/tests/helpers.clj +++ b/backend/tests/uxbox/tests/helpers.clj @@ -17,7 +17,10 @@ [uxbox.util.blob :as blob] [uxbox.util.uuid :as uuid] [uxbox.util.storage :as ust] - [uxbox.config :as cfg])) + [uxbox.config :as cfg] + [vertx.util :as vu])) + +(def ^:dynamic *context* nil) (defn state-init [next] @@ -33,7 +36,8 @@ (mount/swap {#'uxbox.config/config config}) (mount/start)) (try - (next) + (binding [*context* (vu/get-or-create-context uxbox.core/system)] + (next)) (finally (mount/stop))))) @@ -120,13 +124,17 @@ (catch Exception e# [(handle-error e#) nil]))) - (defmacro try-on! [expr] `(try - (let [result# (deref ~expr)] - {:error nil - :result result#}) + (let [d# (p/deferred)] + (->> #(p/finally ~expr (fn [v# e#] + (if e# + (p/reject! d# e#) + (p/resolve! d# v#)))) + (vu/run-on-context! *context*)) + (array-map :error nil + :result (deref d#))) (catch Exception e# {:error (handle-error e#) :result nil}))) diff --git a/backend/tests/uxbox/tests/test_services_project_files.clj b/backend/tests/uxbox/tests/test_services_project_files.clj index faedb82cc..ccabdecb6 100644 --- a/backend/tests/uxbox/tests/test_services_project_files.clj +++ b/backend/tests/uxbox/tests/test_services_project_files.clj @@ -96,8 +96,7 @@ :width 800 :height 800} - out (with-redefs [vc/*context* (vc/get-or-create-context system)] - (th/try-on! (sm/handle data)))] + out (th/try-on! (sm/handle data))] ;; (th/print-result! out) @@ -110,7 +109,8 @@ (t/is (string? (get-in out [:result :path]))) (t/is (string? (get-in out [:result :thumb-path]))) (t/is (string? (get-in out [:result :uri]))) - (t/is (string? (get-in out [:result :thumb-uri]))))) + (t/is (string? (get-in out [:result :thumb-uri]))) + )) (t/deftest mutation-import-image-file-from-collection (let [user @(th/create-user db/pool 1)