mirror of
https://github.com/metosin/reitit.git
synced 2026-01-03 15:08:25 +00:00
test for examples/ring-spec-swagger
This commit is contained in:
parent
3b7f09b870
commit
5ae17159cf
1 changed files with 31 additions and 0 deletions
31
examples/ring-spec-swagger/test/example/server_test.clj
Normal file
31
examples/ring-spec-swagger/test/example/server_test.clj
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
(ns example.server-test
|
||||
(:require [clojure.test :refer :all]
|
||||
[example.server :refer [app]]))
|
||||
|
||||
(deftest example-server
|
||||
|
||||
(testing "GET"
|
||||
(is (= (-> {:request-method :get :uri "/math/plus" :query-params {:x 20 :y 3}}
|
||||
app :body slurp)
|
||||
"{\"total\":23}")))
|
||||
|
||||
(testing "POST"
|
||||
(is (= (-> {:request-method :post :uri "/math/plus" :body-params {:x 40 :y 2}}
|
||||
app :body slurp)
|
||||
"{\"total\":42}")))
|
||||
|
||||
(testing "Download"
|
||||
(is (= (-> {:request-method :get :uri "/files/download"}
|
||||
app :body (#(slurp % :encoding "ascii")) count) ;; binary
|
||||
(.length (clojure.java.io/file "resources/reitit.png"))
|
||||
506325)))
|
||||
|
||||
(testing "Upload"
|
||||
(let [file (clojure.java.io/file "resources/reitit.png")
|
||||
multipart-temp-file-part {:tempfile file
|
||||
:size (.length file)
|
||||
:filename (.getName file)
|
||||
:content-type "image/png;"}]
|
||||
(is (= (-> {:request-method :post :uri "/files/upload" :multipart-params {:file multipart-temp-file-part}}
|
||||
app :body slurp)
|
||||
"{\"name\":\"reitit.png\",\"size\":506325}")))))
|
||||
Loading…
Reference in a new issue