mirror of
https://github.com/metosin/reitit.git
synced 2025-12-28 12:18:25 +00:00
Merge pull request #151 from johannesloetzsch/master
test for examples/ring-spec-swagger
This commit is contained in:
commit
fde2d16d56
2 changed files with 41 additions and 2 deletions
|
|
@ -2,5 +2,6 @@
|
|||
:description "Reitit Ring App with Swagger"
|
||||
:dependencies [[org.clojure/clojure "1.9.0"]
|
||||
[ring/ring-jetty-adapter "1.7.0-RC2"]
|
||||
[metosin/reitit "0.2.2"]]
|
||||
:repl-options {:init-ns example.server})
|
||||
[metosin/reitit "0.2.3-SNAPSHOT"]]
|
||||
:profiles {:dev {:dependencies [[ring/ring-mock "0.3.2"]]
|
||||
:repl-options {:init-ns example.server}}})
|
||||
|
|
|
|||
38
examples/ring-spec-swagger/test/example/server_test.clj
Normal file
38
examples/ring-spec-swagger/test/example/server_test.clj
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
(ns example.server-test
|
||||
(:require [clojure.test :refer :all]
|
||||
[example.server :refer [app]]
|
||||
[ring.mock.request :refer [request json-body]]))
|
||||
|
||||
(deftest example-server
|
||||
|
||||
(testing "GET"
|
||||
(is (= (-> (request :get "/math/plus?x=20&y=3")
|
||||
app :body slurp)
|
||||
(-> {:request-method :get :uri "/math/plus" :query-string "x=20&y=3"}
|
||||
app :body slurp)
|
||||
(-> {:request-method :get :uri "/math/plus" :query-params {:x 20 :y 3}}
|
||||
app :body slurp)
|
||||
"{\"total\":23}")))
|
||||
|
||||
(testing "POST"
|
||||
(is (= (-> (request :post "/math/plus") (json-body {:x 40 :y 2})
|
||||
app :body slurp)
|
||||
(-> {: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