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

Commit c45bc80

Browse files
authored
test(blog): missing published test (#394)
* test(blog): missing published test * test(blog): fix thread arg && clean up
1 parent 89769f5 commit c45bc80

File tree

6 files changed

+110
-9
lines changed

6 files changed

+110
-9
lines changed

test/groupher_server/cms/comments/repo_comment_test.exs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,6 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do
404404
assert results.total_count == total_count + 1
405405
end
406406

407-
@tag :wip
408407
test "paged article comments folded flag should be false", ~m(user repo)a do
409408
total_count = 30
410409
page_number = 1

test/groupher_server_web/mutation/cms/comments/blog_comment_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ defmodule GroupherServer.Test.Mutation.Comments.BlogComment do
116116
}
117117
}
118118
"""
119-
@tag :wip
119+
120120
test "login user can upvote a exsit blog comment", ~m(blog user guest_conn user_conn)a do
121121
{:ok, comment} = CMS.create_article_comment(:blog, blog.id, "blog comment", user)
122122
variables = %{id: comment.id}
@@ -141,7 +141,7 @@ defmodule GroupherServer.Test.Mutation.Comments.BlogComment do
141141
}
142142
}
143143
"""
144-
@tag :wip
144+
145145
test "login user can undo upvote a exsit blog comment", ~m(blog user guest_conn user_conn)a do
146146
{:ok, comment} = CMS.create_article_comment(:blog, blog.id, "blog comment", user)
147147
variables = %{id: comment.id}

test/groupher_server_web/mutation/cms/comments/job_comment_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ defmodule GroupherServer.Test.Mutation.Comments.JobComment do
116116
}
117117
}
118118
"""
119-
@tag :wip
119+
120120
test "login user can upvote a exsit job comment", ~m(job user guest_conn user_conn)a do
121121
{:ok, comment} = CMS.create_article_comment(:job, job.id, "job comment", user)
122122
variables = %{id: comment.id}
@@ -141,7 +141,7 @@ defmodule GroupherServer.Test.Mutation.Comments.JobComment do
141141
}
142142
}
143143
"""
144-
@tag :wip
144+
145145
test "login user can undo upvote a exsit job comment", ~m(job user guest_conn user_conn)a do
146146
{:ok, comment} = CMS.create_article_comment(:job, job.id, "job comment", user)
147147
variables = %{id: comment.id}

test/groupher_server_web/mutation/cms/comments/post_comment_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ defmodule GroupherServer.Test.Mutation.Comments.PostComment do
116116
}
117117
}
118118
"""
119-
@tag :wip
119+
120120
test "login user can upvote a exsit post comment", ~m(post user guest_conn user_conn)a do
121121
{:ok, comment} = CMS.create_article_comment(:post, post.id, "post comment", user)
122122
variables = %{id: comment.id}
@@ -141,7 +141,7 @@ defmodule GroupherServer.Test.Mutation.Comments.PostComment do
141141
}
142142
}
143143
"""
144-
@tag :wip
144+
145145
test "login user can undo upvote a exsit post comment", ~m(post user guest_conn user_conn)a do
146146
{:ok, comment} = CMS.create_article_comment(:post, post.id, "post comment", user)
147147
variables = %{id: comment.id}

test/groupher_server_web/mutation/cms/comments/repo_comment_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ defmodule GroupherServer.Test.Mutation.Comments.RepoComment do
116116
}
117117
}
118118
"""
119-
@tag :wip
119+
120120
test "login user can upvote a exsit repo comment", ~m(repo user guest_conn user_conn)a do
121121
{:ok, comment} = CMS.create_article_comment(:repo, repo.id, "repo comment", user)
122122
variables = %{id: comment.id}
@@ -141,7 +141,7 @@ defmodule GroupherServer.Test.Mutation.Comments.RepoComment do
141141
}
142142
}
143143
"""
144-
@tag :wip
144+
145145
test "login user can undo upvote a exsit repo comment", ~m(repo user guest_conn user_conn)a do
146146
{:ok, comment} = CMS.create_article_comment(:repo, repo.id, "repo comment", user)
147147
variables = %{id: comment.id}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
defmodule GroupherServer.Test.Query.Accounts.Published.Blogs do
2+
use GroupherServer.TestTools
3+
4+
alias GroupherServer.CMS
5+
6+
@publish_count 10
7+
8+
setup do
9+
{:ok, user} = db_insert(:user)
10+
{:ok, blog} = db_insert(:blog)
11+
{:ok, community} = db_insert(:community)
12+
13+
guest_conn = simu_conn(:guest)
14+
user_conn = simu_conn(:user, user)
15+
16+
{:ok, ~m(guest_conn user_conn community blog user)a}
17+
end
18+
19+
describe "[published blogs]" do
20+
@query """
21+
query($login: String!, $filter: PagedFilter!) {
22+
pagedPublishedBlogs(login: $login, filter: $filter) {
23+
entries {
24+
id
25+
title
26+
author {
27+
id
28+
}
29+
}
30+
totalPages
31+
totalCount
32+
pageSize
33+
pageNumber
34+
}
35+
}
36+
"""
37+
38+
test "can get published blogs", ~m(guest_conn community user)a do
39+
blog_attrs = mock_attrs(:blog, %{community_id: community.id})
40+
41+
{:ok, blog} = CMS.create_article(community, :blog, blog_attrs, user)
42+
{:ok, blog2} = CMS.create_article(community, :blog, blog_attrs, user)
43+
44+
variables = %{login: user.login, filter: %{page: 1, size: 20}}
45+
results = guest_conn |> query_result(@query, variables, "pagedPublishedBlogs")
46+
47+
assert results["entries"] |> Enum.any?(&(&1["id"] == to_string(blog.id)))
48+
assert results["entries"] |> Enum.any?(&(&1["id"] == to_string(blog2.id)))
49+
end
50+
end
51+
52+
describe "[account published comments on blog]" do
53+
@query """
54+
query($login: String!, $thread: Thread, $filter: PagedFilter!) {
55+
pagedPublishedArticleComments(login: $login, thread: $thread, filter: $filter) {
56+
entries {
57+
id
58+
bodyHtml
59+
author {
60+
id
61+
}
62+
article {
63+
id
64+
title
65+
author {
66+
nickname
67+
login
68+
}
69+
}
70+
}
71+
totalPages
72+
totalCount
73+
pageSize
74+
pageNumber
75+
}
76+
}
77+
"""
78+
test "user can get paged published comments on blog", ~m(guest_conn user blog)a do
79+
pub_comments =
80+
Enum.reduce(1..@publish_count, [], fn _, acc ->
81+
{:ok, comment} = CMS.create_article_comment(:blog, blog.id, "comment", user)
82+
acc ++ [comment]
83+
end)
84+
85+
random_comment_id = pub_comments |> Enum.random() |> Map.get(:id) |> to_string
86+
87+
variables = %{login: user.login, thread: "BLOG", filter: %{page: 1, size: 20}}
88+
89+
results = guest_conn |> query_result(@query, variables, "pagedPublishedArticleComments")
90+
91+
entries = results["entries"]
92+
assert results |> is_valid_pagination?
93+
assert results["totalCount"] == @publish_count
94+
95+
assert entries |> Enum.all?(&(not is_nil(&1["article"]["author"])))
96+
97+
assert entries |> Enum.all?(&(&1["article"]["id"] == to_string(blog.id)))
98+
assert entries |> Enum.all?(&(&1["author"]["id"] == to_string(user.id)))
99+
assert entries |> Enum.any?(&(&1["id"] == random_comment_id))
100+
end
101+
end
102+
end

0 commit comments

Comments
 (0)