Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit 6d20bc5

Browse files
committed
refactor(mention): mention thread clean up
1 parent 076ad21 commit 6d20bc5

File tree

11 files changed

+16
-40
lines changed

11 files changed

+16
-40
lines changed

lib/groupher_server/delivery/delegates/mention.ex

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ defmodule GroupherServer.Delivery.Delegate.Mention do
3030
batch_delete_mentions(comment, from_user)
3131
end)
3232
|> Multi.run(:batch_insert_mentions, fn _, _ ->
33-
case {0, nil} !== Repo.insert_all(Mention, atom_values_to_upcase(mentions)) do
33+
mentions = Enum.map(mentions, &atom_values_to_upcase(&1))
34+
35+
case {0, nil} !== Repo.insert_all(Mention, mentions) do
3436
true -> {:ok, :pass}
3537
false -> {:error, "insert mentions error"}
3638
end
@@ -45,7 +47,9 @@ defmodule GroupherServer.Delivery.Delegate.Mention do
4547
batch_delete_mentions(article, from_user)
4648
end)
4749
|> Multi.run(:batch_insert_mentions, fn _, _ ->
48-
case {0, nil} !== Repo.insert_all(Mention, atom_values_to_upcase(mentions)) do
50+
mentions = Enum.map(mentions, &atom_values_to_upcase(&1))
51+
52+
case {0, nil} !== Repo.insert_all(Mention, mentions) do
4953
true -> {:ok, :pass}
5054
false -> {:error, "insert mentions error"}
5155
end

test/groupher_server/cms/hooks/cite_blog_test.exs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ defmodule GroupherServer.Test.CMS.Hooks.CiteBlog do
9090
assert cited_comment.meta.citing_count == 0
9191
end
9292

93-
@tag :wip2
9493
test "can cite blog's comment in blog", ~m(community user blog blog2 blog_attrs)a do
9594
{:ok, comment} = CMS.create_comment(:blog, blog.id, mock_rich_text("hello"), user)
9695

test/groupher_server/cms/hooks/cite_job_test.exs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ defmodule GroupherServer.Test.CMS.Hooks.CiteJob do
9090
assert cited_comment.meta.citing_count == 0
9191
end
9292

93-
@tag :wip2
9493
test "can cite job's comment in job", ~m(community user job job2 job_attrs)a do
9594
{:ok, comment} = CMS.create_comment(:job, job.id, mock_rich_text("hello"), user)
9695

test/groupher_server/cms/hooks/cite_post_test.exs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ defmodule GroupherServer.Test.CMS.Hooks.CitePost do
9090
assert cited_comment.meta.citing_count == 0
9191
end
9292

93-
@tag :wip2
9493
test "can cite post's comment in post", ~m(community user post post2 post_attrs)a do
9594
{:ok, comment} = CMS.create_comment(:post, post.id, mock_rich_text("hello"), user)
9695

test/groupher_server/cms/hooks/mention_in_blog_test.exs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ defmodule GroupherServer.Test.CMS.Hooks.MentionInBlog do
4040
{:ok, result} = Delivery.fetch(:mention, user2, %{page: 1, size: 10})
4141

4242
mention = result.entries |> List.first()
43-
assert mention.type == "BLOG"
43+
assert mention.thread == "BLOG"
4444
assert mention.block_linker |> length == 2
4545
assert mention.article_id == blog.id
4646
assert mention.title == blog.title
@@ -49,7 +49,7 @@ defmodule GroupherServer.Test.CMS.Hooks.MentionInBlog do
4949
{:ok, result} = Delivery.fetch(:mention, user3, %{page: 1, size: 10})
5050

5151
mention = result.entries |> List.first()
52-
assert mention.type == "BLOG"
52+
assert mention.thread == "BLOG"
5353
assert mention.block_linker |> length == 1
5454
assert mention.article_id == blog.id
5555
assert mention.title == blog.title
@@ -67,7 +67,7 @@ defmodule GroupherServer.Test.CMS.Hooks.MentionInBlog do
6767
{:ok, result} = Delivery.fetch(:mention, user2, %{page: 1, size: 10})
6868

6969
mention = result.entries |> List.first()
70-
assert mention.type == "COMMENT"
70+
assert mention.thread == "BLOG"
7171
assert mention.comment_id == comment.id
7272
assert mention.block_linker |> length == 1
7373
assert mention.article_id == blog.id

test/groupher_server/cms/hooks/mention_in_job_test.exs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ defmodule GroupherServer.Test.CMS.Hooks.MentionInJob do
4040
{:ok, result} = Delivery.fetch(:mention, user2, %{page: 1, size: 10})
4141

4242
mention = result.entries |> List.first()
43-
assert mention.type == "JOB"
43+
assert mention.thread == "JOB"
4444
assert mention.block_linker |> length == 2
4545
assert mention.article_id == job.id
4646
assert mention.title == job.title
@@ -49,7 +49,7 @@ defmodule GroupherServer.Test.CMS.Hooks.MentionInJob do
4949
{:ok, result} = Delivery.fetch(:mention, user3, %{page: 1, size: 10})
5050

5151
mention = result.entries |> List.first()
52-
assert mention.type == "JOB"
52+
assert mention.thread == "JOB"
5353
assert mention.block_linker |> length == 1
5454
assert mention.article_id == job.id
5555
assert mention.title == job.title
@@ -67,7 +67,7 @@ defmodule GroupherServer.Test.CMS.Hooks.MentionInJob do
6767
{:ok, result} = Delivery.fetch(:mention, user2, %{page: 1, size: 10})
6868

6969
mention = result.entries |> List.first()
70-
assert mention.type == "COMMENT"
70+
assert mention.thread == "JOB"
7171
assert mention.comment_id == comment.id
7272
assert mention.block_linker |> length == 1
7373
assert mention.article_id == job.id

test/groupher_server/cms/hooks/mention_in_post_test.exs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ defmodule GroupherServer.Test.CMS.Hooks.MentionInPost do
2222
end
2323

2424
describe "[mention in post basic]" do
25+
@tag :wip
2526
test "mention multi user in post should work", ~m(user user2 user3 community post_attrs)a do
2627
body =
2728
mock_rich_text(
@@ -40,7 +41,7 @@ defmodule GroupherServer.Test.CMS.Hooks.MentionInPost do
4041
{:ok, result} = Delivery.fetch(:mention, user2, %{page: 1, size: 10})
4142

4243
mention = result.entries |> List.first()
43-
assert mention.type == "POST"
44+
assert mention.thread == "POST"
4445
assert mention.block_linker |> length == 2
4546
assert mention.article_id == post.id
4647
assert mention.title == post.title
@@ -49,7 +50,7 @@ defmodule GroupherServer.Test.CMS.Hooks.MentionInPost do
4950
{:ok, result} = Delivery.fetch(:mention, user3, %{page: 1, size: 10})
5051

5152
mention = result.entries |> List.first()
52-
assert mention.type == "POST"
53+
assert mention.thread == "POST"
5354
assert mention.block_linker |> length == 1
5455
assert mention.article_id == post.id
5556
assert mention.title == post.title
@@ -67,7 +68,7 @@ defmodule GroupherServer.Test.CMS.Hooks.MentionInPost do
6768
{:ok, result} = Delivery.fetch(:mention, user2, %{page: 1, size: 10})
6869

6970
mention = result.entries |> List.first()
70-
assert mention.type == "COMMENT"
71+
assert mention.thread == "POST"
7172
assert mention.comment_id == comment.id
7273
assert mention.block_linker |> length == 1
7374
assert mention.article_id == post.id

test/groupher_server/cms/hooks/notify_blog_test.exs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ defmodule GroupherServer.Test.CMS.Hooks.NotifyBlog do
2121
end
2222

2323
describe "[upvote notify]" do
24-
@tag :wip22
2524
test "upvote hook should work on blog", ~m(user2 blog)a do
2625
{:ok, blog} = preload_author(blog)
2726

@@ -41,7 +40,6 @@ defmodule GroupherServer.Test.CMS.Hooks.NotifyBlog do
4140
assert user_exist_in?(user2, notify.from_users)
4241
end
4342

44-
@tag :wip22
4543
test "upvote hook should work on blog comment", ~m(user2 blog comment)a do
4644
{:ok, comment} = CMS.upvote_comment(comment.id, user2)
4745
{:ok, comment} = preload_author(comment)
@@ -62,7 +60,6 @@ defmodule GroupherServer.Test.CMS.Hooks.NotifyBlog do
6260
assert user_exist_in?(user2, notify.from_users)
6361
end
6462

65-
@tag :wip22
6663
test "undo upvote hook should work on blog", ~m(user2 blog)a do
6764
{:ok, blog} = preload_author(blog)
6865

@@ -78,7 +75,6 @@ defmodule GroupherServer.Test.CMS.Hooks.NotifyBlog do
7875
assert notifications.total_count == 0
7976
end
8077

81-
@tag :wip22
8278
test "undo upvote hook should work on blog comment", ~m(user2 comment)a do
8379
{:ok, comment} = CMS.upvote_comment(comment.id, user2)
8480

@@ -97,7 +93,6 @@ defmodule GroupherServer.Test.CMS.Hooks.NotifyBlog do
9793
end
9894

9995
describe "[collect notify]" do
100-
@tag :wip22
10196
test "collect hook should work on blog", ~m(user2 blog)a do
10297
{:ok, blog} = preload_author(blog)
10398

@@ -117,7 +112,6 @@ defmodule GroupherServer.Test.CMS.Hooks.NotifyBlog do
117112
assert user_exist_in?(user2, notify.from_users)
118113
end
119114

120-
@tag :wip22
121115
test "undo collect hook should work on blog", ~m(user2 blog)a do
122116
{:ok, blog} = preload_author(blog)
123117

@@ -135,7 +129,6 @@ defmodule GroupherServer.Test.CMS.Hooks.NotifyBlog do
135129
end
136130

137131
describe "[comment notify]" do
138-
@tag :wip22
139132
test "blog author should get notify after some one comment on it", ~m(user2 blog)a do
140133
{:ok, blog} = preload_author(blog)
141134

@@ -155,7 +148,6 @@ defmodule GroupherServer.Test.CMS.Hooks.NotifyBlog do
155148
assert user_exist_in?(user2, notify.from_users)
156149
end
157150

158-
@tag :wip22
159151
test "blog comment author should get notify after some one reply it", ~m(user2 user3 blog)a do
160152
{:ok, blog} = preload_author(blog)
161153

test/groupher_server/cms/hooks/notify_job_test.exs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ defmodule GroupherServer.Test.CMS.Hooks.NotifyJob do
2121
end
2222

2323
describe "[upvote notify]" do
24-
@tag :wip22
2524
test "upvote hook should work on job", ~m(user2 job)a do
2625
{:ok, job} = preload_author(job)
2726

@@ -41,7 +40,6 @@ defmodule GroupherServer.Test.CMS.Hooks.NotifyJob do
4140
assert user_exist_in?(user2, notify.from_users)
4241
end
4342

44-
@tag :wip22
4543
test "upvote hook should work on job comment", ~m(user2 job comment)a do
4644
{:ok, comment} = CMS.upvote_comment(comment.id, user2)
4745
{:ok, comment} = preload_author(comment)
@@ -62,7 +60,6 @@ defmodule GroupherServer.Test.CMS.Hooks.NotifyJob do
6260
assert user_exist_in?(user2, notify.from_users)
6361
end
6462

65-
@tag :wip22
6663
test "undo upvote hook should work on job", ~m(user2 job)a do
6764
{:ok, job} = preload_author(job)
6865

@@ -78,7 +75,6 @@ defmodule GroupherServer.Test.CMS.Hooks.NotifyJob do
7875
assert notifications.total_count == 0
7976
end
8077

81-
@tag :wip22
8278
test "undo upvote hook should work on job comment", ~m(user2 comment)a do
8379
{:ok, comment} = CMS.upvote_comment(comment.id, user2)
8480

@@ -97,7 +93,6 @@ defmodule GroupherServer.Test.CMS.Hooks.NotifyJob do
9793
end
9894

9995
describe "[collect notify]" do
100-
@tag :wip22
10196
test "collect hook should work on job", ~m(user2 job)a do
10297
{:ok, job} = preload_author(job)
10398

@@ -117,7 +112,6 @@ defmodule GroupherServer.Test.CMS.Hooks.NotifyJob do
117112
assert user_exist_in?(user2, notify.from_users)
118113
end
119114

120-
@tag :wip22
121115
test "undo collect hook should work on job", ~m(user2 job)a do
122116
{:ok, job} = preload_author(job)
123117

@@ -135,7 +129,6 @@ defmodule GroupherServer.Test.CMS.Hooks.NotifyJob do
135129
end
136130

137131
describe "[comment notify]" do
138-
@tag :wip22
139132
test "job author should get notify after some one comment on it", ~m(user2 job)a do
140133
{:ok, job} = preload_author(job)
141134

@@ -155,7 +148,6 @@ defmodule GroupherServer.Test.CMS.Hooks.NotifyJob do
155148
assert user_exist_in?(user2, notify.from_users)
156149
end
157150

158-
@tag :wip22
159151
test "job comment author should get notify after some one reply it", ~m(user2 user3 job)a do
160152
{:ok, job} = preload_author(job)
161153

test/groupher_server/cms/hooks/notify_post_test.exs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ defmodule GroupherServer.Test.CMS.Hooks.NotifyPost do
2121
end
2222

2323
describe "[upvote notify]" do
24-
@tag :wip22
2524
test "upvote hook should work on post", ~m(user2 post)a do
2625
{:ok, post} = preload_author(post)
2726

@@ -41,7 +40,6 @@ defmodule GroupherServer.Test.CMS.Hooks.NotifyPost do
4140
assert user_exist_in?(user2, notify.from_users)
4241
end
4342

44-
@tag :wip22
4543
test "upvote hook should work on post comment", ~m(user2 post comment)a do
4644
{:ok, comment} = CMS.upvote_comment(comment.id, user2)
4745
{:ok, comment} = preload_author(comment)
@@ -62,7 +60,6 @@ defmodule GroupherServer.Test.CMS.Hooks.NotifyPost do
6260
assert user_exist_in?(user2, notify.from_users)
6361
end
6462

65-
@tag :wip22
6663
test "undo upvote hook should work on post", ~m(user2 post)a do
6764
{:ok, post} = preload_author(post)
6865

@@ -78,7 +75,6 @@ defmodule GroupherServer.Test.CMS.Hooks.NotifyPost do
7875
assert notifications.total_count == 0
7976
end
8077

81-
@tag :wip22
8278
test "undo upvote hook should work on post comment", ~m(user2 comment)a do
8379
{:ok, comment} = CMS.upvote_comment(comment.id, user2)
8480

@@ -97,7 +93,6 @@ defmodule GroupherServer.Test.CMS.Hooks.NotifyPost do
9793
end
9894

9995
describe "[collect notify]" do
100-
@tag :wip22
10196
test "collect hook should work on post", ~m(user2 post)a do
10297
{:ok, post} = preload_author(post)
10398

@@ -117,7 +112,6 @@ defmodule GroupherServer.Test.CMS.Hooks.NotifyPost do
117112
assert user_exist_in?(user2, notify.from_users)
118113
end
119114

120-
@tag :wip22
121115
test "undo collect hook should work on post", ~m(user2 post)a do
122116
{:ok, post} = preload_author(post)
123117

@@ -135,7 +129,6 @@ defmodule GroupherServer.Test.CMS.Hooks.NotifyPost do
135129
end
136130

137131
describe "[comment notify]" do
138-
@tag :wip22
139132
test "post author should get notify after some one comment on it", ~m(user2 post)a do
140133
{:ok, post} = preload_author(post)
141134

@@ -155,7 +148,6 @@ defmodule GroupherServer.Test.CMS.Hooks.NotifyPost do
155148
assert user_exist_in?(user2, notify.from_users)
156149
end
157150

158-
@tag :wip22
159151
test "post comment author should get notify after some one reply it", ~m(user2 user3 post)a do
160152
{:ok, post} = preload_author(post)
161153

0 commit comments

Comments
 (0)