Skip to content

Commit

Permalink
Merge branch 'master' into Generate-Options-endpoints-by-Default
Browse files Browse the repository at this point in the history
  • Loading branch information
ikitommi authored Sep 24, 2018
2 parents b015eec + fde2d16 commit e739a62
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
2 changes: 1 addition & 1 deletion examples/ring-spec-swagger/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ To test the endpoints using [httpie](https://httpie.org/):

```bash
http GET :3000/math/plus x==1 y==20
http POST :3000/math/spec/plus x:=1 y:=20
http POST :3000/math/plus x:=1 y:=20

http GET :3000/swagger.json
```
Expand Down
2 changes: 1 addition & 1 deletion examples/ring-spec-swagger/project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
:dependencies [[org.clojure/clojure "1.9.0"]
[ring/ring-jetty-adapter "1.7.0"]
[metosin/reitit "0.2.3-SNAPSHOT"]]
:repl-options {:init-ns example.server})
:repl-options {:init-ns example.server})
38 changes: 38 additions & 0 deletions examples/ring-spec-swagger/test/example/server_test.clj
Original file line number Diff line number Diff line change
@@ -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}")))))

0 comments on commit e739a62

Please sign in to comment.