mirror of
https://github.com/metosin/reitit.git
synced 2026-02-15 15:55:15 +00:00
Add reitit.frontend test case
This commit is contained in:
parent
1819fa5d75
commit
5829e1c656
2 changed files with 35 additions and 12 deletions
|
|
@ -78,12 +78,9 @@
|
||||||
;; on the coercion?
|
;; on the coercion?
|
||||||
;; NOTE: Re-creates coercer on every call, could this be pre-compiled somewhere
|
;; NOTE: Re-creates coercer on every call, could this be pre-compiled somewhere
|
||||||
;; or memoized? Does it matter much?
|
;; or memoized? Does it matter much?
|
||||||
(str "?" (let [schema (-> match :data :parameters :query
|
(str "?" (let [coercion (-> match :data :coercion)
|
||||||
;; FIXME: Why?
|
schema (when coercion
|
||||||
;; Due the Malli schema merge? Needs
|
(coercion/-compile-model coercion (-> match :data :parameters :query) nil))
|
||||||
;; coercion/-compile-model call first.
|
|
||||||
first)
|
|
||||||
coercion (-> match :data :coercion)
|
|
||||||
coercer (when (and schema coercion)
|
coercer (when (and schema coercion)
|
||||||
(coercion/-query-string-coercer coercion schema))
|
(coercion/-query-string-coercer coercion schema))
|
||||||
query-params (or (when coercer
|
query-params (or (when coercer
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,14 @@
|
||||||
(ns reitit.frontend.core-test
|
(ns reitit.frontend.core-test
|
||||||
(:require [clojure.test :refer [deftest testing is are]]
|
(:require [clojure.string :as str]
|
||||||
|
[clojure.test :refer [are deftest is testing]]
|
||||||
|
[reitit.coercion :as rc]
|
||||||
|
[reitit.coercion.malli :as rcm]
|
||||||
|
[reitit.coercion.schema :as rcs]
|
||||||
[reitit.core :as r]
|
[reitit.core :as r]
|
||||||
[reitit.frontend :as rf]
|
[reitit.frontend :as rf]
|
||||||
[reitit.coercion :as rc]
|
|
||||||
[schema.core :as s]
|
|
||||||
[reitit.coercion.schema :as rcs]
|
|
||||||
[reitit.coercion.malli :as rcm]
|
|
||||||
[reitit.frontend.test-utils :refer [capture-console]]
|
[reitit.frontend.test-utils :refer [capture-console]]
|
||||||
[reitit.impl :as impl]))
|
[reitit.impl :as impl]
|
||||||
|
[schema.core :as s]))
|
||||||
|
|
||||||
(deftest query-params-test
|
(deftest query-params-test
|
||||||
(is (= {:foo "1"}
|
(is (= {:foo "1"}
|
||||||
|
|
@ -297,3 +298,28 @@
|
||||||
(testing "Fragment encoding"
|
(testing "Fragment encoding"
|
||||||
(is (= "foo#foo+bar+%25"
|
(is (= "foo#foo+bar+%25"
|
||||||
(rf/match->path {:path "foo"} nil "foo bar %")))))
|
(rf/match->path {:path "foo"} nil "foo bar %")))))
|
||||||
|
|
||||||
|
(defn instant->string
|
||||||
|
[x]
|
||||||
|
(str "x" (.toISOString x)))
|
||||||
|
|
||||||
|
(defn string->instant
|
||||||
|
[x]
|
||||||
|
(if (string? x)
|
||||||
|
(js/Date. (subs x 1 (count x)))
|
||||||
|
x))
|
||||||
|
|
||||||
|
(deftest match->path-coercion-test
|
||||||
|
(testing "default Date toString"
|
||||||
|
(is (str/starts-with?
|
||||||
|
(rf/match->path {:path "foo"} {:date (js/Date. 2024 0 1 12 13 0)})
|
||||||
|
"foo?date=Mon+Jan+01+2024+12")))
|
||||||
|
|
||||||
|
(is (= "foo?date=x2024-01-01T10%3A13%3A00.000Z"
|
||||||
|
(rf/match->path {:data {:coercion rcm/coercion
|
||||||
|
:parameters {:query [[:map
|
||||||
|
[:date {:decode/string string->instant
|
||||||
|
:encode/string instant->string}
|
||||||
|
:any]]]}}
|
||||||
|
:path "foo"}
|
||||||
|
{:date (js/Date. 2024 0 1 12 13 0)}))))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue