Skip to content

Commit 14fd876

Browse files
committed
feat(social): adds wireout model/adapter/controller/tests
1 parent bd3840c commit 14fd876

File tree

8 files changed

+169
-2
lines changed

8 files changed

+169
-2
lines changed

src/codes/clj/docs/backend/adapters/social.clj

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@
3333
:avatar-url avatar-url
3434
:created-at created-at})
3535

36+
(defn author-interaction->model->wire
37+
{:malli/schema [:=> [:cat [:sequential schemas.model.social/Author+Interactions]]
38+
[:sequential schemas.wire.out.social/Author+Interactions]]}
39+
[author+interactions]
40+
(->> author+interactions
41+
(map (fn [{:author/keys [interactions] :as author}]
42+
(assoc (author->model->wire author)
43+
:interactions interactions)))
44+
(sort-by :interactions #(compare %2 %1))))
45+
3646
(defn editor->model->wire
3747
{:malli/schema [:=> [:cat schemas.model.social/Editor] schemas.wire.social/Editor]}
3848
[{:editor/keys [edited-at] :as author}]
@@ -129,3 +139,22 @@
129139
(enc/assoc-some
130140
(author->model->wire author)
131141
:socials (map social->model->wire socials)))
142+
143+
(defn any-social->model->wire
144+
{:malli/schema [:=> [:cat [:sequential schemas.model.social/AnySocial]]
145+
[:maybe [:sequential schemas.wire.out.social/AnySocial]]]}
146+
[any-socials]
147+
(let [notes (->> any-socials
148+
(filter #(:note/note-id %))
149+
(map note->model->wire))
150+
examples (->> any-socials
151+
(filter #(:example/example-id %))
152+
(map example->model->wire))
153+
see-alsos (->> any-socials
154+
(filter #(:see-also/see-also-id %))
155+
(map see-also->model->wire))]
156+
(->> (concat
157+
(seq notes)
158+
(seq examples)
159+
(seq see-alsos))
160+
(sort-by :created-at #(compare %2 %1)))))

src/codes/clj/docs/backend/controllers/social.clj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,15 @@
8686
[:maybe schemas.model.social/Social]]}
8787
[definition-id {:keys [database]}]
8888
(db.postgres/get-by-definition definition-id database))
89+
90+
(defn get-top-authors
91+
{:malli/schema [:=> [:cat :int schemas.types/Components]
92+
[:maybe [:sequential schemas.model.social/Author+Interactions]]]}
93+
[limit {:keys [database]}]
94+
(db.postgres/get-top-authors limit database))
95+
96+
(defn get-latest-interactions
97+
{:malli/schema [:=> [:cat :int schemas.types/Components]
98+
[:maybe [:sequential schemas.model.social/AnySocial]]]}
99+
[limit {:keys [database]}]
100+
(db.postgres/get-latest-interactions limit database))

src/codes/clj/docs/backend/ports/http_in/social.clj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,19 @@
155155
:notes []
156156
:examples []
157157
:see-alsos []})})
158+
159+
(defn get-top-authors
160+
[{{{:keys [limit]} :query} :parameters
161+
components :components}]
162+
{:status 200
163+
:body (-> (or limit 10)
164+
(controllers.social/get-top-authors components)
165+
adapters.social/author-interaction->model->wire)})
166+
167+
(defn get-latest-interactions
168+
[{{{:keys [limit]} :query} :parameters
169+
components :components}]
170+
{:status 200
171+
:body (-> (or limit 10)
172+
(controllers.social/get-latest-interactions components)
173+
adapters.social/any-social->model->wire)})

src/codes/clj/docs/backend/routes.clj

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,24 @@
169169
:responses {200 {:body schemas.wire.out.social/Social}
170170
404 {:body :string}
171171
500 {:body :string}}
172-
:handler ports.http-in.social/get-by-definition}}]]]
172+
:handler ports.http-in.social/get-by-definition}}]]
173+
174+
["/query"
175+
["/top-authors"
176+
{:get {:summary "get top contributing author list"
177+
:parameters {:query [:map [:limit {:optional true} :int]]}
178+
:responses {200 {:body [:sequential schemas.wire.out.social/Author+Interactions]}
179+
404 {:body :string}
180+
500 {:body :string}}
181+
:handler ports.http-in.social/get-top-authors}}]
182+
183+
["/latest-interactions"
184+
{:get {:summary "get latest social interactions list"
185+
:parameters {:query [:map [:limit {:optional true} :int]]}
186+
:responses {200 {:body [:sequential schemas.wire.out.social/AnySocial]}
187+
404 {:body :string}
188+
500 {:body :string}}
189+
:handler ports.http-in.social/get-latest-interactions}}]]]
173190

174191
["/document"
175192
{:swagger {:tags ["document"]}}

src/codes/clj/docs/backend/schemas/model/social.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,4 @@
118118
(mu/assoc Author [:author/socials {:optional true}] [:sequential Social]))
119119

120120
(def Author+Interactions
121-
(mu/assoc Author [:author/interactions {:optional true}] :int))
121+
(mu/assoc Author :author/interactions :int))

src/codes/clj/docs/backend/schemas/wire/out/social.clj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,11 @@
3333
[:examples [:sequential Example]]
3434
[:see-alsos [:sequential SeeAlso]]])
3535

36+
(def AnySocial
37+
[:or Example Note SeeAlso])
38+
3639
(def Author+Socials
3740
(mu/assoc Author [:socials {:optional true}] [:sequential Social]))
41+
42+
(def Author+Interactions
43+
(mu/assoc Author :interactions :int))

test/integration/codes/clj/docs/backend/social_test.clj

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,31 @@
158158
(state-flow.server/request! {:method :get
159159
:uri "/api/social/author/delboni/github"})))
160160

161+
(flow "should return top authors"
162+
(match? {:status 200
163+
:body [{:author-id string?
164+
:login "delboni"
165+
:account-source "github"
166+
:avatar-url "https://my.pic/me.jpg"
167+
:created-at string?
168+
:interactions 1}]}
169+
(state-flow.server/request! {:method :get
170+
:uri "/api/social/query/top-authors"})))
171+
172+
(flow "should return latest interactions"
173+
(match? {:status 200
174+
:body [{:note-id string?
175+
:definition-id "clojure.core/disj"
176+
:body "my edited note about this function."
177+
:created-at string?
178+
:author {:author-id string?
179+
:login "delboni"
180+
:account-source "github"
181+
:avatar-url "https://my.pic/me.jpg"
182+
:created-at string?}}]}
183+
(state-flow.server/request! {:method :get
184+
:uri "/api/social/query/latest-interactions"})))
185+
161186
(flow "should not be able to delete if not allowed"
162187
(match? {:status 403
163188
:body "You not allowed to delete this note."}
@@ -246,6 +271,26 @@
246271
(state-flow.server/request! {:method :get
247272
:uri "/api/social/author/delboni/github"})))
248273

274+
(flow "should return top authors"
275+
(match? {:status 200
276+
:body [{:author-id string?
277+
:login "delboni"
278+
:account-source "github"
279+
:avatar-url "https://my.pic/me.jpg"
280+
:created-at string?
281+
:interactions 1}]}
282+
(state-flow.server/request! {:method :get
283+
:uri "/api/social/query/top-authors"})))
284+
285+
(flow "should return latest interactions"
286+
(match? {:status 200
287+
:body [{:see-also-id see-also-id
288+
:definition-id "clojure.core/disj"
289+
:definition-id-to "clojure.core/dissoc"
290+
:created-at string?}]}
291+
(state-flow.server/request! {:method :get
292+
:uri "/api/social/query/latest-interactions"})))
293+
249294
(flow "should not be able to delete if not allowed"
250295
(match? {:status 403
251296
:body "You not allowed to delete this see also."}
@@ -386,6 +431,38 @@
386431
(state-flow.server/request! {:method :get
387432
:uri "/api/social/author/delboni/github"})))
388433

434+
(flow "should return top authors"
435+
(match? {:status 200
436+
:body [{:author-id string?
437+
:login "delboni"
438+
:account-source "github"
439+
:avatar-url "https://my.pic/me.jpg"
440+
:created-at string?
441+
:interactions 2}]}
442+
(state-flow.server/request! {:method :get
443+
:uri "/api/social/query/top-authors"})))
444+
445+
(flow "should return latest interactions"
446+
(match? {:status 200
447+
:body [{:example-id example-id
448+
:definition-id "clojure.core/disj"
449+
:body "my edited example about this function."
450+
:created-at string?
451+
:editors [{:author-id string?
452+
:login "delboni"
453+
:account-source "github"
454+
:avatar-url "https://my.pic/me.jpg"
455+
:created-at string?
456+
:edited-at string?}
457+
{:author-id string?
458+
:login "delboni"
459+
:account-source "github"
460+
:avatar-url "https://my.pic/me.jpg"
461+
:created-at string?
462+
:edited-at string?}]}]}
463+
(state-flow.server/request! {:method :get
464+
:uri "/api/social/query/latest-interactions"})))
465+
389466
(flow "delete example revision part 1"
390467
(state-flow.server/request! {:method :delete
391468
:headers {"authorization" (str "Bearer " token)}

test/unit/codes/clj/docs/backend/adapters/social_test.clj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
(m/validate schemas.wire.social/Author
2929
(adapters.social/author->model->wire author))))
3030

31+
(defspec author-interaction->model->wire-test 50
32+
(properties/for-all [author+interaction (mg/generator schemas.model.social/Author+Interactions)]
33+
(m/validate [:sequential schemas.wire.out.social/Author+Interactions]
34+
(adapters.social/author-interaction->model->wire [author+interaction]))))
35+
3136
(defspec editor->model->wire-test 50
3237
(properties/for-all [editor (mg/generator schemas.model.social/Editor)]
3338
(m/validate schemas.wire.social/Editor
@@ -87,3 +92,8 @@
8792
(properties/for-all [author+socials (mg/generator schemas.model.social/Author+Socials)]
8893
(m/validate schemas.wire.out.social/Author+Socials
8994
(adapters.social/author+socials->model->wire author+socials))))
95+
96+
(defspec any-social->model->wire-test 50
97+
(properties/for-all [any-social (mg/generator schemas.model.social/AnySocial)]
98+
(m/validate [:sequential schemas.wire.out.social/AnySocial]
99+
(adapters.social/any-social->model->wire [any-social]))))

0 commit comments

Comments
 (0)