mirror of
https://github.com/penpot/penpot.git
synced 2025-03-10 14:51:37 -05:00
test(backend): fix image create/upload test
This commit is contained in:
parent
af8d19ab60
commit
4291c80259
2 changed files with 39 additions and 30 deletions
|
@ -90,26 +90,31 @@
|
|||
;; :opt-un [::us/id ::collection]))
|
||||
|
||||
(defn create-image
|
||||
[{user :identity data :data}]
|
||||
#_(let [{:keys [file id width height
|
||||
mimetype collection]} (us/conform ::create-image data)
|
||||
id (or id (uuid/random))
|
||||
filename (fs/name file)
|
||||
{:parameters {:multipart {:upload [st/required]
|
||||
:id [st/uuid-str]
|
||||
:width [st/required st/integer-str]
|
||||
:height [st/required st/integer-str]
|
||||
:mimetype [st/required st/string]
|
||||
:collection [st/uuid-str]}}}
|
||||
[{:keys [user parameters] :as ctx}]
|
||||
(prn "create-image" (:body-params ctx) (:multipart-params ctx))
|
||||
(let [params (get parameters :multipart)
|
||||
upload (get params :upload)
|
||||
filename (fs/name (:filename upload))
|
||||
tempfile (:tempfile upload)
|
||||
storage media/images-storage]
|
||||
(letfn [(persist-image-entry [path]
|
||||
(sv/novelty {:id id
|
||||
:type :create-image
|
||||
:user user
|
||||
:width width
|
||||
:height height
|
||||
:mimetype mimetype
|
||||
:collection collection
|
||||
:name filename
|
||||
:path (str path)}))
|
||||
(let [message (select-keys params [:id :width :height :collection :mimetype])]
|
||||
(sv/novelty (assoc message
|
||||
:id (or (:id params) (uuid/random))
|
||||
:type :create-image
|
||||
:name filename
|
||||
:path (str path)
|
||||
:user user))))
|
||||
(create-response [entry]
|
||||
(let [loc (str "/api/library/images/" (:id entry))]
|
||||
(http/created loc (rsp entry))))]
|
||||
(->> (st/save storage filename file)
|
||||
(http/created loc entry)))]
|
||||
(->> (ds/save storage filename tempfile)
|
||||
(p/mapcat persist-image-entry)
|
||||
(p/map populate-thumbnails)
|
||||
(p/map populate-urls)
|
||||
|
|
|
@ -72,20 +72,24 @@
|
|||
result (sc/fetch conn sqlv)]
|
||||
(t/is (empty? result))))))))
|
||||
|
||||
;; ;; (t/deftest test-http-create-image
|
||||
;; ;; (with-open [conn (db/connection)]
|
||||
;; ;; (let [user (th/create-user conn 1)]
|
||||
;; ;; (with-server {:handler (uft/routes)}
|
||||
;; ;; (let [uri (str th/+base-url+ "/api/library/images")
|
||||
;; ;; params [{:name "sample.jpg"
|
||||
;; ;; :part-name "file"
|
||||
;; ;; :content (io/input-stream
|
||||
;; ;; (io/resource "uxbox/tests/_files/sample.jpg"))}]
|
||||
;; ;; [status data] (th/http-multipart user uri params)]
|
||||
;; ;; ;; (println "RESPONSE:" status data)
|
||||
;; ;; (t/is (= 201 status))
|
||||
;; ;; (t/is (= (:user data) (:id user)))
|
||||
;; ;; (t/is (= (:name data) "sample.jpg")))))))
|
||||
(t/deftest test-http-create-image
|
||||
(with-open [conn (db/connection)]
|
||||
(let [user (th/create-user conn 1)]
|
||||
(th/with-server {:handler uapi/app}
|
||||
(let [uri (str th/+base-url+ "/api/library/images")
|
||||
parts [{:name "sample.jpg"
|
||||
:part-name "upload"
|
||||
:content (io/input-stream
|
||||
(io/resource "uxbox/tests/_files/sample.jpg"))}
|
||||
{:part-name "user" :content (str (:id user))}
|
||||
{:part-name "width" :content "100"}
|
||||
{:part-name "height" :content "100"}
|
||||
{:part-name "mimetype" :content "image/png"}]
|
||||
[status data] (th/http-multipart user uri parts)]
|
||||
;; (println "RESPONSE:" status data)
|
||||
(t/is (= 201 status))
|
||||
(t/is (= (:user data) (:id user)))
|
||||
(t/is (= (:name data) "sample.jpg")))))))
|
||||
|
||||
(t/deftest test-http-update-image
|
||||
(with-open [conn (db/connection)]
|
||||
|
|
Loading…
Add table
Reference in a new issue