Added rest-support
This commit is contained in:
parent
3e64062dcc
commit
28e58ea03d
4 changed files with 175 additions and 20 deletions
|
|
@ -40,5 +40,12 @@
|
|||
(is (= expected actual) "params and form-params differ"))
|
||||
(let [expected {:id 67 :offset 0 :limit 50}
|
||||
actual (massage-params {:id 60} {:id "67" :offset "0" :limit "50"} #{:id})]
|
||||
(is (= expected actual) "Limit and offset in form-params"))
|
||||
(is (= expected actual) "prefer values from form-params"))
|
||||
(let [expected {:id 67 :offset 0 :limit 50}
|
||||
actual (massage-params {:params {:id "67" :offset "0" :limit "50"} :form-params {}})]
|
||||
(is (= expected actual) "Request with no form params"))
|
||||
(let [expected {:id 67 :offset 0 :limit 50}
|
||||
actual (massage-params {:params {:id "0" :offset "1000" :limit "150"}
|
||||
:form-params {:id "67" :offset "0" :limit "50"}})]
|
||||
(is (= expected actual) "Request with form params, params and form params differ"))
|
||||
))
|
||||
|
|
|
|||
38
test/adl_support/rest_support_test.clj
Normal file
38
test/adl_support/rest_support_test.clj
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
(ns adl-support.core-test
|
||||
(:require [clojure.test :refer :all]
|
||||
[adl-support.rest_support :refer :all]))
|
||||
|
||||
|
||||
(deftest if-valid-user-tests
|
||||
(testing "correct handling of if-valid-user"
|
||||
(let [expected "hello"
|
||||
actual (if-valid-user "hello" {:session {:user {:id 4}}} "goodbye")]
|
||||
(is (= expected actual) "User in session"))
|
||||
(let [expected "goodbye"
|
||||
actual (if-valid-user "hello" {:session {}} "goodbye")]
|
||||
(is (= expected actual) "No user in session"))))
|
||||
|
||||
|
||||
(deftest valid-user-or-forbid-tests
|
||||
(testing "valid-user-or-forbid"
|
||||
(let [expected "hello"
|
||||
actual (valid-user-or-forbid "hello" {:session {:user {:id 4}}})]
|
||||
(is (= expected actual) "User in session"))
|
||||
(let [expected 403
|
||||
actual (:status (valid-user-or-forbid "hello" {:session {:user {:id 4}}}))]
|
||||
(is (= expected actual) "No user in session"))))
|
||||
|
||||
|
||||
(deftest with-params-or-error-tests
|
||||
(let [expected "hello"
|
||||
actual (with-params-or-error "hello" {:a 1 :b 2} #{:a :b})]
|
||||
(is (= expected actual) "All requirements satisfied"))
|
||||
(let [expected "hello"
|
||||
actual (with-params-or-error "hello" {:a 1 :b 2 :c 3} #{:a :b})]
|
||||
(is (= expected actual) "Unrequired parameter present"))
|
||||
(let [expected 400
|
||||
actual (:status (with-params-or-error "hello" {:a 1 :b 2} #{:a :b :c}))]
|
||||
(is (= expected actual) "Some requirements unsatisfied"))
|
||||
(let [expected 400
|
||||
actual (:status (with-params-or-error (/ 1 0) {:a 1 :b 2} #{:a :b :c}))]
|
||||
(is (= expected actual) "Exception should not be throwen")))
|
||||
Loading…
Add table
Add a link
Reference in a new issue