-
Notifications
You must be signed in to change notification settings - Fork 0
/
articles.cljc
63 lines (53 loc) · 2.23 KB
/
articles.cljc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
(ns andrewslai.cljc.specs.articles
(:require
#?@(:clj [[clojure.spec.alpha :as s]
[clojure.test.check.generators :as gen]
[spec-tools.spec :as spec]]
:cljs [[cljs.spec.alpha :as s]
[clojure.test.check.generators :as gen]
[spec-tools.spec :as spec]])))
(def timestamp (s/or :date spec/inst? :string spec/string?))
(s/def :andrewslai.article/id spec/integer?)
(s/def :andrewslai.article/article-name spec/string?)
(s/def :andrewslai.article/title spec/string?)
(s/def :andrewslai.article/article-tags spec/string?)
(s/def :andrewslai.article/article-url spec/string?)
(s/def :andrewslai.article/author spec/string?)
(s/def :andrewslai.article/content spec/string?)
(s/def :andrewslai.article/article
(s/keys :req-un [:andrewslai.article/article-tags
:andrewslai.article/author
:andrewslai.article/article-url]
:opt-un [:andrewslai.article/id
:andrewslai.article/content
:andrewslai.article/title]))
(s/def :andrewslai.branch/id spec/string?)
(s/def :andrewslai.branch/branch-id spec/string?)
(s/def :andrewslai.branch/article-id spec/string?)
(s/def :andrewslai.branch/published-at timestamp)
(s/def :andrewslai.branch/branch-name spec/string?)
(s/def :andrewslai.branch/created-at timestamp)
(s/def :andrewslai.branch/modified-at timestamp)
(s/def :andrewslai.article/article-branch
(s/keys :req-un [:andrewslai.branch/branch-name]
:opt-un [:andrewslai.branch/article-id
:andrewslai.branch/published-at
:andrewslai.branch/branch-id
:andrewslai.article/author
:andrewslai.article/article-url
:andrewslai.article/article-tags]))
(s/def :andrewslai.article/articles
(s/coll-of :andrewslai.article/article))
(def example-article
{:id 4
:article-tags "about",
:article-url "my-fourth-article",
:author "Andrew Lai",
:content "<p>Content from 4</p>"
:timestamp "2020-10-28T02:55:27Z",
:title "My fourth article"})
(comment
;; Example data for article spec
(gen/sample :andrewslai.article/article)
(s/valid? :andrewslai.article/article example-article)
)