2019-03-03 19:55:39 +00:00
|
|
|
(ns reitit.exception-test
|
2022-02-14 14:59:20 +00:00
|
|
|
(:require [clojure.spec.alpha :as s]
|
2023-01-10 06:05:42 +00:00
|
|
|
[clojure.test :refer [are deftest is]]
|
2022-02-14 14:59:20 +00:00
|
|
|
[reitit.core :as r]
|
|
|
|
|
[reitit.dev.pretty :as pretty]
|
|
|
|
|
[reitit.exception :as exception]
|
|
|
|
|
[reitit.spec :as rs])
|
2019-03-03 19:55:39 +00:00
|
|
|
#?(:clj
|
2022-02-14 14:59:20 +00:00
|
|
|
(:import (clojure.lang ExceptionInfo))))
|
2019-03-03 19:55:39 +00:00
|
|
|
|
|
|
|
|
(s/def ::role #{:admin :manager})
|
|
|
|
|
(s/def ::roles (s/coll-of ::role :into #{}))
|
|
|
|
|
(s/def ::data (s/keys :req [::role ::roles]))
|
|
|
|
|
|
|
|
|
|
(deftest errors-test
|
|
|
|
|
|
|
|
|
|
(are [exception]
|
2019-03-03 19:58:17 +00:00
|
|
|
(are [error routes]
|
2019-03-03 19:55:39 +00:00
|
|
|
(is (thrown-with-msg?
|
2022-02-12 20:34:26 +00:00
|
|
|
ExceptionInfo
|
|
|
|
|
error
|
|
|
|
|
(r/router
|
|
|
|
|
routes
|
|
|
|
|
{:validate rs/validate
|
|
|
|
|
:exception exception})))
|
2019-03-03 19:55:39 +00:00
|
|
|
|
|
|
|
|
#"Router contains conflicting route paths"
|
|
|
|
|
[["/:a/1"]
|
|
|
|
|
["/1/:a"]]
|
|
|
|
|
|
|
|
|
|
#"Router contains conflicting route names"
|
|
|
|
|
[["/kikka" ::kikka]
|
|
|
|
|
["/kukka" ::kikka]]
|
|
|
|
|
|
|
|
|
|
#":reitit.trie/multiple-terminators"
|
|
|
|
|
[["/{a}.pdf"]
|
|
|
|
|
["/{a}-pdf"]]
|
|
|
|
|
|
|
|
|
|
#":reitit.trie/following-parameters"
|
|
|
|
|
["/{a}{b}"]
|
|
|
|
|
|
|
|
|
|
#":reitit.trie/unclosed-brackets"
|
|
|
|
|
["/api/{ipa"]
|
|
|
|
|
|
|
|
|
|
#"Invalid route data"
|
2019-05-15 19:54:35 +00:00
|
|
|
["/api/ipa" {::roles #{:adminz}}]
|
|
|
|
|
|
|
|
|
|
#"Error merging route-data"
|
|
|
|
|
["/a" {:body {}}
|
|
|
|
|
["/b" {:body [:FAIL]}]])
|
2019-03-03 19:55:39 +00:00
|
|
|
|
|
|
|
|
exception/exception
|
|
|
|
|
pretty/exception))
|