Skip to content

Commit 500cf61

Browse files
committed
Add test for the primitive arrays (metosin#177)
1 parent 2162e2a commit 500cf61

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

test/compojure/api/integration_test.clj

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,8 @@
382382
body => {:total 1}))))
383383

384384
(fact "primitive support"
385-
(let [api (api
385+
(let [app (api
386+
{:swagger {:spec "/swagger.json"}}
386387
(context "/primitives" []
387388
(GET "/return-long" []
388389
:return Long
@@ -398,24 +399,43 @@
398399
(ok longs))))]
399400

400401
(fact "when :return is set, longs can be returned"
401-
(let [[status body] (raw-get* api "/primitives/return-long")]
402+
(let [[status body] (raw-get* app "/primitives/return-long")]
402403
status => 200
403404
body => "1"))
404405

405406
(fact "when :return is not set, longs won't be encoded"
406-
(let [[status body] (raw-get* api "/primitives/long")]
407+
(let [[status body] (raw-get* app "/primitives/long")]
407408
status => 200
408409
body => number?))
409410

410411
(fact "when :return is set, raw strings can be returned"
411-
(let [[status body] (raw-get* api "/primitives/return-string")]
412+
(let [[status body] (raw-get* app "/primitives/return-string")]
412413
status => 200
413414
body => "\"kikka\""))
414415

415416
(fact "primitive arrays work"
416-
(let [[status body] (raw-post* api "/primitives/arrays" (json/generate-string [1 2 3]))]
417+
(let [[status body] (raw-post* app "/primitives/arrays" (json/generate-string [1 2 3]))]
417418
status => 200
418-
body => "[1,2,3]"))))
419+
body => "[1,2,3]"))
420+
421+
(fact "swagger-spec is valid"
422+
(validator/validate app))
423+
424+
(fact "primitive array swagger-docs are good"
425+
426+
(-> app get-spec :paths (get "/primitives/arrays") :post :parameters)
427+
=> [{:description ""
428+
:in "body"
429+
:name ""
430+
:required true
431+
:schema {:items {:format "int64"
432+
:type "integer"}
433+
:type "array"}}]
434+
435+
(-> app get-spec :paths (get "/primitives/arrays") :post :responses :200 :schema)
436+
=> {:items {:format "int64",
437+
:type "integer"},
438+
:type "array"})))
419439

420440
(fact "compojure destructuring support"
421441
(let [app (api

0 commit comments

Comments
 (0)