more specs.

This commit is contained in:
Bryce Covert
2018-04-09 16:27:03 -07:00
parent f7dea19d2e
commit 5e7add409f
25 changed files with 246 additions and 209 deletions

View File

@@ -0,0 +1,22 @@
(ns auto-ap.entities.companies
(:require [clojure.spec.alpha :as s]
[clojure.string :as str]))
(def email-regex #"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,63}$")
(s/def ::id int)
(s/def ::identifier (s/nilable string?))
(s/def ::required-identifier (s/and string?
#(not (str/blank? %))))
(s/def ::name ::required-identifier)
(s/def ::email (s/nilable (s/and string? (s/or :is-email #(re-matches email-regex %)
:is-empty #(= % "")))))
(s/def ::company (s/keys :req [::name]
:opt [::email
::id]))
(def company-spec (apply hash-map (drop 1 (s/form ::company))))
(def all-keys (concat (:req company-spec) (:opt company-spec)))