/
issue336_test.clj
59 lines (53 loc) · 2.19 KB
/
issue336_test.clj
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
47
48
49
50
51
52
53
54
55
56
57
58
59
(ns compojure.api.coercion.issue336-test
(:require [clojure.test :refer [deftest is testing]]
[compojure.api.test-utils :refer :all]
[ring.util.http-response :refer :all]
[compojure.api.sweet :refer :all]
[clojure.spec.alpha :as s]
[spec-tools.spec :as spec]
[spec-tools.core :as st]))
(s/def ::customer-id spec/string?)
(s/def ::requestor-id spec/string?)
(s/def ::requestor-email spec/string?)
(s/def ::requestor-name spec/string?)
(s/def ::endpoint spec/string?)
(s/def ::from-year spec/int?)
(s/def ::from-month spec/int?)
(s/def ::to-year spec/int?)
(s/def ::to-month spec/int?)
(s/def ::input-settings (s/and (s/keys :req-un [::endpoint
::customer-id
::requestor-id]
:opt-un [::from-year
::from-month
::to-year
::to-month
::requestor-email
::requestor-name])))
(def app
(api
{:formatter :muuntaja
:swagger
{:ui "/"
:spec "/swagger.json"
:data {:info {:title "Futomaki"
:description "API for counter stats over the Sushi protocol"}
:tags [{:name "Reports", :description "Retrieve information per report definition"}]}}}
(context "/api" []
:tags ["api"]
:coercion :spec
(context "/jr1" []
(resource
{:get
{:summary "Number of successful full-text article requests by month and journal"
:parameters {:query-params ::input-settings}
:response {200 {:schema ::input-settings}}
:handler (fn [{:keys [query-params]}]
(ok query-params))}})))))
(deftest coercion-works-with-s-and-test
(let [data {:endpoint "http://sushi.cambridge.org/GetReport"
:customer-id "abc"
:requestor-id "abc"}
[status body] (get* app "/api/jr1" data)]
(is (= status 200))
(is (= body data))))