mirror of
https://github.com/penpot/penpot.git
synced 2025-01-09 00:10:11 -05:00
cacee40d11
this allows almost all api operations to success usin application/json encoding with the exception of the update-file, which we need to approach a bit differently; the reason update-file is different, is because the operations vector is right now defined without the context of shape type, so we are just unable to properly parse the value to correct type using the schema decoding mechanism
41 lines
1.5 KiB
Clojure
41 lines
1.5 KiB
Clojure
;; This Source Code Form is subject to the terms of the Mozilla Public
|
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
;;
|
|
;; Copyright (c) KALEIDOS INC
|
|
|
|
(ns common-tests.schema-test
|
|
(:require
|
|
[app.common.schema :as sm]
|
|
[app.common.schema.generators :as sg]
|
|
[clojure.test :as t]))
|
|
|
|
(t/deftest test-set-of-email
|
|
(t/testing "decoding"
|
|
(let [candidate1 "a@b.com a@c.net"
|
|
schema [::sm/set ::sm/email]
|
|
result1 (sm/decode schema candidate1 sm/string-transformer)
|
|
result2 (sm/decode schema candidate1 sm/json-transformer)]
|
|
(t/is (= result1 #{"a@b.com" "a@c.net"}))
|
|
(t/is (= result2 #{"a@b.com" "a@c.net"}))))
|
|
|
|
(t/testing "encoding"
|
|
(let [candidate #{"a@b.com" "a@c.net"}
|
|
schema [::sm/set ::sm/email]
|
|
result1 (sm/encode schema candidate sm/string-transformer)
|
|
result2 (sm/decode schema candidate sm/json-transformer)]
|
|
(t/is (= result1 "a@b.com, a@c.net"))
|
|
(t/is (= result2 candidate))))
|
|
|
|
(t/testing "validate"
|
|
(let [candidate #{"a@b.com" "a@c.net"}
|
|
schema [::sm/set ::sm/email]]
|
|
|
|
(t/is (true? (sm/validate schema candidate)))
|
|
(t/is (true? (sm/validate schema #{})))
|
|
(t/is (false? (sm/validate schema #{"a"})))))
|
|
|
|
(t/testing "generate"
|
|
(let [schema [::sm/set ::sm/email]
|
|
value (sg/generate schema)]
|
|
(t/is (true? (sm/validate schema (sg/generate schema)))))))
|