summaryrefslogtreecommitdiff
path: root/compojure-3.2/test/compojure/http/response_test.clj
blob: 45a0d01431b8bde757dae6ec420467f42b6081f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
(ns compojure.http.response-test
  (:use compojure.http.response
        clojure.contrib.test-is))

(deftest nil-response
  (is (= (create-response {} nil)
         {:status 200, :headers {}})))

(deftest int-response
  (is (= (:status (create-response {} 404))
         404)))
         
(deftest next-response
  (is (nil? (create-response {} :next))))

(deftest string-response
  (is (= (:body (create-response {} "Lorem Ipsum"))
         "Lorem Ipsum")))

(deftest seq-response
  (is (= (:body (create-response {} (list "a" "b" "c")))
         (list "a" "b" "c"))))

(deftest map-response
  (let [response {:status  200
                  :headers {"Content-Type" "text/plain"}
                  :body    "Lorem Ipsum"}]
    (is (= (create-response {} response) response))))

(deftest vector-string-response
  (is (= (:body (create-response {} ["Foo" "Bar" "Baz"]))
         "FooBarBaz")))

(deftest vector-int-response
  (is (= (:status (create-response {} [200 500 403]))
         403)))

(deftest default-content-type
  (let [response {:headers {"Foo" "Bar"}}]
    (is (= (:headers (update-response {} response "Foo"))
           {"Foo" "Bar" "Content-Type" "text/html"}))))

(deftest supplied-content-type
  (let [response {:headers {"Content-Type" "text/plain" "Foo" "Bar"}}]
    (is (= (:headers (update-response {} response "Foo"))
           {"Content-Type" "text/plain" "Foo" "Bar"}))))