test whole stack (use query-string and json-body)

This commit is contained in:
Johannes Lötzsch 2018-09-23 22:48:32 +02:00
parent 5ae17159cf
commit fb91499efd
2 changed files with 13 additions and 5 deletions

View file

@ -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}}})

View file

@ -1,16 +1,23 @@
(ns example.server-test
(:require [clojure.test :refer :all]
[example.server :refer [app]]))
[example.server :refer [app]]
[ring.mock.request :refer [request json-body]]))
(deftest example-server
(testing "GET"
(is (= (-> {:request-method :get :uri "/math/plus" :query-params {:x 20 :y 3}}
(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-method :post :uri "/math/plus" :body-params {:x 40 :y 2}}
(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}")))