mirror of
https://github.com/penpot/penpot.git
synced 2025-01-10 08:50:57 -05:00
🐛 More test fixes.
This commit is contained in:
parent
d546d1fdca
commit
4a395ec761
8 changed files with 76 additions and 105 deletions
|
@ -142,7 +142,7 @@
|
||||||
;; --- Mutation: Update Page Metadata
|
;; --- Mutation: Update Page Metadata
|
||||||
|
|
||||||
(s/def ::update-page-metadata
|
(s/def ::update-page-metadata
|
||||||
(s/keys :req-un [::data ::user ::project-id ::name ::metadata ::id]))
|
(s/keys :req-un [::user ::project-id ::name ::metadata ::id]))
|
||||||
|
|
||||||
(sv/defmutation :update-page-metadata
|
(sv/defmutation :update-page-metadata
|
||||||
{:doc "Update an existing page."
|
{:doc "Update an existing page."
|
||||||
|
|
|
@ -137,9 +137,17 @@
|
||||||
{:error (handle-error e#)
|
{:error (handle-error e#)
|
||||||
:result nil})))
|
:result nil})))
|
||||||
|
|
||||||
|
(defmacro try!
|
||||||
|
[expr]
|
||||||
|
`(try
|
||||||
|
{:error nil
|
||||||
|
:result ~expr}
|
||||||
|
(catch Exception e#
|
||||||
|
{:error (handle-error e#)
|
||||||
|
:result nil})))
|
||||||
|
|
||||||
(defn print-result!
|
(defn print-result!
|
||||||
[{:keys [error result]}]
|
[{:keys [error result]}]
|
||||||
|
|
||||||
(if error
|
(if error
|
||||||
(do
|
(do
|
||||||
(println "====> START ERROR")
|
(println "====> START ERROR")
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
;;
|
;;
|
||||||
;; Copyright (c) 2019 Andrey Antukh <niwi@niwi.nz>
|
;; Copyright (c) 2019 Andrey Antukh <niwi@niwi.nz>
|
||||||
|
|
||||||
(ns uxbox.tests.test-auth
|
(ns uxbox.tests.test-services-auth
|
||||||
(:require
|
(:require
|
||||||
[clojure.test :as t]
|
[clojure.test :as t]
|
||||||
[promesa.core :as p]
|
[promesa.core :as p]
|
|
@ -1,4 +1,4 @@
|
||||||
(ns uxbox.tests.test-kvstore
|
(ns uxbox.tests.test-services-kvstore
|
||||||
(:require
|
(:require
|
||||||
[clojure.spec.alpha :as s]
|
[clojure.spec.alpha :as s]
|
||||||
[clojure.test :as t]
|
[clojure.test :as t]
|
|
@ -1,4 +1,4 @@
|
||||||
(ns uxbox.tests.test-pages
|
(ns uxbox.tests.test-services-pages
|
||||||
(:require
|
(:require
|
||||||
[clojure.spec.alpha :as s]
|
[clojure.spec.alpha :as s]
|
||||||
[clojure.test :as t]
|
[clojure.test :as t]
|
||||||
|
@ -20,13 +20,14 @@
|
||||||
:project-id (:id proj)
|
:project-id (:id proj)
|
||||||
:name "test page"
|
:name "test page"
|
||||||
:user (:id user)}
|
:user (:id user)}
|
||||||
[err rsp] (th/try-on (sv/mutation data))]
|
res (th/try-on! (sv/mutation data))]
|
||||||
(t/is (nil? err))
|
(t/is (nil? (:error res)))
|
||||||
(t/is (uuid? (:id rsp)))
|
(t/is (uuid? (get-in res [:result :id])))
|
||||||
(t/is (= (:user data) (:user-id rsp)))
|
(let [rsp (:result res)]
|
||||||
(t/is (= (:name data) (:name rsp)))
|
(t/is (= (:user data) (:user-id rsp)))
|
||||||
(t/is (= (:data data) (:data rsp)))
|
(t/is (= (:name data) (:name rsp)))
|
||||||
(t/is (= (:metadata data) (:metadata rsp)))))
|
(t/is (= (:data data) (:data rsp)))
|
||||||
|
(t/is (= (:metadata data) (:metadata rsp))))))
|
||||||
|
|
||||||
(t/deftest test-mutation-update-page
|
(t/deftest test-mutation-update-page
|
||||||
(let [user @(th/create-user db/pool 1)
|
(let [user @(th/create-user db/pool 1)
|
||||||
|
@ -54,7 +55,7 @@
|
||||||
(let [user @(th/create-user db/pool 1)
|
(let [user @(th/create-user db/pool 1)
|
||||||
proj @(th/create-project db/pool (:id user) 1)
|
proj @(th/create-project db/pool (:id user) 1)
|
||||||
page @(th/create-page db/pool (:id user) (:id proj) 1)
|
page @(th/create-page db/pool (:id user) (:id proj) 1)
|
||||||
data {::sv/type :update-page
|
data {::sv/type :update-page-metadata
|
||||||
:id (:id page)
|
:id (:id page)
|
||||||
:metadata {:foo 2}
|
:metadata {:foo 2}
|
||||||
:project-id (:id proj)
|
:project-id (:id proj)
|
||||||
|
@ -91,7 +92,7 @@
|
||||||
:user (:id user)}
|
:user (:id user)}
|
||||||
res (th/try-on! (sv/query data))]
|
res (th/try-on! (sv/query data))]
|
||||||
|
|
||||||
(th/print-result! res)
|
;; (th/print-result! res)
|
||||||
(t/is (nil? (:error res)))
|
(t/is (nil? (:error res)))
|
||||||
(t/is (vector? (:result res)))
|
(t/is (vector? (:result res)))
|
||||||
(t/is (= 1 (count (:result res))))
|
(t/is (= 1 (count (:result res))))
|
|
@ -1,4 +1,4 @@
|
||||||
(ns uxbox.tests.test-projects
|
(ns uxbox.tests.test-services-projects
|
||||||
(:require
|
(:require
|
||||||
[clojure.test :as t]
|
[clojure.test :as t]
|
||||||
[promesa.core :as p]
|
[promesa.core :as p]
|
|
@ -1,90 +0,0 @@
|
||||||
(ns uxbox.tests.test-svgparse
|
|
||||||
#_(:require [clojure.test :as t]
|
|
||||||
[clojure.java.io :as io]
|
|
||||||
[uxbox.http :as http]
|
|
||||||
[uxbox.services :as usv]
|
|
||||||
[uxbox.services.svgparse :as svg]
|
|
||||||
[uxbox.tests.helpers :as th]))
|
|
||||||
|
|
||||||
;; (t/use-fixtures :once th/state-init)
|
|
||||||
|
|
||||||
;; (t/deftest parse-svg-test
|
|
||||||
;; (t/testing "parsing valid svg 1"
|
|
||||||
;; (let [image (slurp (io/resource "uxbox/tests/_files/sample1.svg"))
|
|
||||||
;; result (svg/parse-string image)]
|
|
||||||
;; (t/is (contains? result :width))
|
|
||||||
;; (t/is (contains? result :height))
|
|
||||||
;; (t/is (contains? result :view-box))
|
|
||||||
;; (t/is (contains? result :name))
|
|
||||||
;; (t/is (contains? result :content))
|
|
||||||
;; (t/is (= 500.0 (:width result)))
|
|
||||||
;; (t/is (= 500.0 (:height result)))
|
|
||||||
;; (t/is (= [0.0 0.0 500.00001 500.00001] (:view-box result)))
|
|
||||||
;; (t/is (= "lock.svg" (:name result)))))
|
|
||||||
|
|
||||||
;; (t/testing "parsing valid svg 2"
|
|
||||||
;; (let [image (slurp (io/resource "uxbox/tests/_files/sample2.svg"))
|
|
||||||
;; result (svg/parse-string image)]
|
|
||||||
;; (t/is (contains? result :width))
|
|
||||||
;; (t/is (contains? result :height))
|
|
||||||
;; (t/is (contains? result :view-box))
|
|
||||||
;; (t/is (contains? result :name))
|
|
||||||
;; (t/is (contains? result :content))
|
|
||||||
;; (t/is (= 500.0 (:width result)))
|
|
||||||
;; (t/is (= 500.0 (:height result)))
|
|
||||||
;; (t/is (= [0.0 0.0 500.0 500.00001] (:view-box result)))
|
|
||||||
;; (t/is (= "play.svg" (:name result)))))
|
|
||||||
|
|
||||||
;; (t/testing "parsing invalid data 1"
|
|
||||||
;; (let [image (slurp (io/resource "uxbox/tests/_files/sample.jpg"))
|
|
||||||
;; [e result] (th/try-on (svg/parse-string image))]
|
|
||||||
;; (t/is (th/exception? e))
|
|
||||||
;; (t/is (th/ex-info? e))
|
|
||||||
;; (t/is (th/ex-with-code? e :uxbox.services.svgparse/invalid-input))))
|
|
||||||
|
|
||||||
;; (t/testing "parsing invalid data 2"
|
|
||||||
;; (let [[e result] (th/try-on (svg/parse-string ""))]
|
|
||||||
;; (t/is (th/exception? e))
|
|
||||||
;; (t/is (th/ex-info? e))
|
|
||||||
;; (t/is (th/ex-with-code? e :uxbox.services.svgparse/invalid-input))))
|
|
||||||
|
|
||||||
;; (t/testing "parsing invalid data 3"
|
|
||||||
;; (let [[e result] (th/try-on (svg/parse-string "<svg></svg>"))]
|
|
||||||
;; (t/is (th/exception? e))
|
|
||||||
;; (t/is (th/ex-info? e))
|
|
||||||
;; (t/is (th/ex-with-code? e :uxbox.services.svgparse/invalid-result))))
|
|
||||||
|
|
||||||
;; ;; (t/testing "valid http request"
|
|
||||||
;; ;; (with-open [conn (db/connection)]
|
|
||||||
;; ;; (let [image (slurp (io/resource "uxbox/tests/_files/sample2.svg"))
|
|
||||||
;; ;; path "/api/svg/parse"
|
|
||||||
;; ;; user (th/create-user conn 1)]
|
|
||||||
;; ;; (th/with-server {:handler @http/app}
|
|
||||||
;; ;; (let [rsp (th/request {:method :post
|
|
||||||
;; ;; :path path
|
|
||||||
;; ;; :body image
|
|
||||||
;; ;; :raw? true})]
|
|
||||||
;; ;; (t/is (= 200 (:status rsp)))
|
|
||||||
;; ;; (prn "RESPONSE" rsp)
|
|
||||||
;; ;; ;; (t/is (contains? (:body rsp) :width))
|
|
||||||
;; ;; ;; (t/is (contains? (:body rsp) :height))
|
|
||||||
;; ;; ;; (t/is (contains? (:body rsp) :view-box))
|
|
||||||
;; ;; ;; (t/is (contains? (:body rsp) :name))
|
|
||||||
;; ;; ;; (t/is (contains? (:body rsp) :content))
|
|
||||||
;; ;; ;; (t/is (= 500.0 (:width (:body rsp))))
|
|
||||||
;; ;; #_(t/is (= 500.0 (:height (:body rsp))))
|
|
||||||
;; ;; #_(t/is (= [0.0 0.0 500.0 500.00001] (:view-box (:body rsp))))
|
|
||||||
;; ;; #_(t/is (= "play.svg" (:name (:body rsp))))))))
|
|
||||||
|
|
||||||
;; ;; (t/testing "invalid http request"
|
|
||||||
;; ;; (let [path "/api/svg/parse"
|
|
||||||
;; ;; image "<svg></svg>"]
|
|
||||||
;; ;; (with-server {:handler (uft/routes)}
|
|
||||||
;; ;; (let [rsp (th/request {:method :post
|
|
||||||
;; ;; :path path
|
|
||||||
;; ;; :body image
|
|
||||||
;; ;; :raw? true})]
|
|
||||||
;; ;; (t/is (= 400 (:status rsp)))
|
|
||||||
;; ;; (t/is (= :validation (get-in rsp [:body :type])))
|
|
||||||
;; ;; (t/is (= ::svg/invalid-result (get-in rsp [:body :code])))))))
|
|
||||||
;; )
|
|
52
backend/test/uxbox/tests/test_util_svg.clj
Normal file
52
backend/test/uxbox/tests/test_util_svg.clj
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
(ns uxbox.tests.test-util-svg
|
||||||
|
(:require
|
||||||
|
[clojure.test :as t]
|
||||||
|
[clojure.java.io :as io]
|
||||||
|
[uxbox.http :as http]
|
||||||
|
[uxbox.util.svg :as svg]
|
||||||
|
[uxbox.tests.helpers :as th]))
|
||||||
|
|
||||||
|
(t/deftest parse-svg-1
|
||||||
|
(let [result (-> (io/resource "uxbox/tests/_files/sample1.svg")
|
||||||
|
(svg/parse))]
|
||||||
|
(t/is (contains? result :width))
|
||||||
|
(t/is (contains? result :height))
|
||||||
|
(t/is (contains? result :view-box))
|
||||||
|
(t/is (contains? result :name))
|
||||||
|
(t/is (contains? result :content))
|
||||||
|
(t/is (= 500.0 (:width result)))
|
||||||
|
(t/is (= 500.0 (:height result)))
|
||||||
|
(t/is (= [0.0 0.0 500.00001 500.00001] (:view-box result)))
|
||||||
|
(t/is (= "lock.svg" (:name result)))))
|
||||||
|
|
||||||
|
(t/deftest parse-svg-2
|
||||||
|
(let [result (-> (io/resource "uxbox/tests/_files/sample2.svg")
|
||||||
|
(svg/parse))]
|
||||||
|
(t/is (contains? result :width))
|
||||||
|
(t/is (contains? result :height))
|
||||||
|
(t/is (contains? result :view-box))
|
||||||
|
(t/is (contains? result :name))
|
||||||
|
(t/is (contains? result :content))
|
||||||
|
(t/is (= 500.0 (:width result)))
|
||||||
|
(t/is (= 500.0 (:height result)))
|
||||||
|
(t/is (= [0.0 0.0 500.0 500.00001] (:view-box result)))
|
||||||
|
(t/is (= "play.svg" (:name result)))))
|
||||||
|
|
||||||
|
(t/deftest parse-invalid-svg-1
|
||||||
|
(let [image (io/resource "uxbox/tests/_files/sample.jpg")
|
||||||
|
result (th/try! (svg/parse image))]
|
||||||
|
(t/is (map? (:error result)))
|
||||||
|
(t/is (= (get-in result [:error :code])
|
||||||
|
::svg/invalid-input))))
|
||||||
|
|
||||||
|
(t/deftest parse-invalid-svg-2
|
||||||
|
(let [result (th/try! (svg/parse-string ""))]
|
||||||
|
(t/is (map? (:error result)))
|
||||||
|
(t/is (= (get-in result [:error :code])
|
||||||
|
::svg/invalid-input))))
|
||||||
|
|
||||||
|
(t/deftest parse-invalid-svg-3
|
||||||
|
(let [result (th/try! (svg/parse-string "<svg></svg>"))]
|
||||||
|
(t/is (map? (:error result)))
|
||||||
|
(t/is (= (get-in result [:error :code])
|
||||||
|
::svg/invalid-result))))
|
Loading…
Reference in a new issue