File: utils_test.clj

package info (click to toggle)
puppetlabs-ring-middleware-clojure 2.0.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 336 kB
  • sloc: sh: 69; makefile: 33; xml: 10
file content (25 lines) | stat: -rw-r--r-- 1,004 bytes parent folder | download | duplicates (4)
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
(ns puppetlabs.ring-middleware.utils-test
  (:require [cheshire.core :as json]
            [clojure.test :refer :all]
            [puppetlabs.ring-middleware.utils :as utils]))

(deftest json-response-test
  (testing "json response"
    (let [source {:key 1}
          response (utils/json-response 200 source)]
      (testing "has 200 status code"
        (is (= 200 (:status response))))
      (testing "has json content-type"
        (is (re-matches #"application/json.*" (get-in response [:headers "Content-Type"]))))
      (testing "is properly converted to a json string"
        (is (= 1 ((json/parse-string (:body response)) "key")))))))

(deftest plain-response-test
  (testing "json response"
    (let [message "Response message"
          response (utils/plain-response 200 message)]
      (testing "has 200 status code"
        (is (= 200 (:status response))))
      (testing "has plain content-type"
        (is (re-matches #"text/plain.*" (get-in response [:headers "Content-Type"])))))))