0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-10 00:40:30 -05:00

🐛 More test fixes.

This commit is contained in:
Andrey Antukh 2019-11-25 15:56:49 +01:00
parent d546d1fdca
commit 4a395ec761
8 changed files with 76 additions and 105 deletions

View file

@ -142,7 +142,7 @@
;; --- Mutation: 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
{:doc "Update an existing page."

View file

@ -137,9 +137,17 @@
{:error (handle-error e#)
:result nil})))
(defmacro try!
[expr]
`(try
{:error nil
:result ~expr}
(catch Exception e#
{:error (handle-error e#)
:result nil})))
(defn print-result!
[{:keys [error result]}]
(if error
(do
(println "====> START ERROR")

View file

@ -4,7 +4,7 @@
;;
;; Copyright (c) 2019 Andrey Antukh <niwi@niwi.nz>
(ns uxbox.tests.test-auth
(ns uxbox.tests.test-services-auth
(:require
[clojure.test :as t]
[promesa.core :as p]

View file

@ -1,4 +1,4 @@
(ns uxbox.tests.test-kvstore
(ns uxbox.tests.test-services-kvstore
(:require
[clojure.spec.alpha :as s]
[clojure.test :as t]

View file

@ -1,4 +1,4 @@
(ns uxbox.tests.test-pages
(ns uxbox.tests.test-services-pages
(:require
[clojure.spec.alpha :as s]
[clojure.test :as t]
@ -20,13 +20,14 @@
:project-id (:id proj)
:name "test page"
:user (:id user)}
[err rsp] (th/try-on (sv/mutation data))]
(t/is (nil? err))
(t/is (uuid? (:id rsp)))
(t/is (= (:user data) (:user-id rsp)))
(t/is (= (:name data) (:name rsp)))
(t/is (= (:data data) (:data rsp)))
(t/is (= (:metadata data) (:metadata rsp)))))
res (th/try-on! (sv/mutation data))]
(t/is (nil? (:error res)))
(t/is (uuid? (get-in res [:result :id])))
(let [rsp (:result res)]
(t/is (= (:user data) (:user-id rsp)))
(t/is (= (:name data) (:name rsp)))
(t/is (= (:data data) (:data rsp)))
(t/is (= (:metadata data) (:metadata rsp))))))
(t/deftest test-mutation-update-page
(let [user @(th/create-user db/pool 1)
@ -54,7 +55,7 @@
(let [user @(th/create-user db/pool 1)
proj @(th/create-project db/pool (:id user) 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)
:metadata {:foo 2}
:project-id (:id proj)
@ -91,7 +92,7 @@
:user (:id user)}
res (th/try-on! (sv/query data))]
(th/print-result! res)
;; (th/print-result! res)
(t/is (nil? (:error res)))
(t/is (vector? (:result res)))
(t/is (= 1 (count (:result res))))

View file

@ -1,4 +1,4 @@
(ns uxbox.tests.test-projects
(ns uxbox.tests.test-services-projects
(:require
[clojure.test :as t]
[promesa.core :as p]

View file

@ -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])))))))
;; )

View 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))))