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

Commit f3af7dd

Browse files
committed
refactor(reactions-test): re-org wip
1 parent b015b71 commit f3af7dd

File tree

2 files changed

+72
-57
lines changed

2 files changed

+72
-57
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
defmodule GroupherServer.Test.Mutation.Upvotes.JobUpvote do
2+
@moduledoc false
3+
use GroupherServer.TestTools
4+
5+
alias GroupherServer.CMS
6+
7+
setup do
8+
{:ok, job} = db_insert(:job)
9+
{:ok, user} = db_insert(:user)
10+
11+
guest_conn = simu_conn(:guest)
12+
user_conn = simu_conn(:user, user)
13+
14+
{:ok, ~m(user_conn guest_conn job user)a}
15+
end
16+
17+
describe "[job upvote]" do
18+
@query """
19+
mutation($id: ID!, $thread: CmsThread!) {
20+
upvoteArticle(id: $id, thread: $thread) {
21+
id
22+
}
23+
}
24+
"""
25+
@tag :wip2
26+
test "login user can upvote a job", ~m(user_conn job)a do
27+
variables = %{id: job.id, thread: "JOB"}
28+
created = user_conn |> mutation_result(@query, variables, "upvoteArticle")
29+
30+
assert created["id"] == to_string(job.id)
31+
end
32+
33+
@tag :wip2
34+
test "unauth user upvote a job fails", ~m(guest_conn job)a do
35+
variables = %{id: job.id, thread: "JOB"}
36+
37+
assert guest_conn
38+
|> mutation_get_error?(@query, variables, ecode(:account_login))
39+
end
40+
41+
@query """
42+
mutation($id: ID!, $thread: CmsThread!) {
43+
undoUpvoteArticle(id: $id, thread: $thread) {
44+
id
45+
}
46+
}
47+
"""
48+
@tag :wip2
49+
test "login user can undo upvote to a job", ~m(user_conn job user)a do
50+
{:ok, _} = CMS.upvote_article(:job, job.id, user)
51+
52+
variables = %{id: job.id, thread: "JOB"}
53+
updated = user_conn |> mutation_result(@query, variables, "undoUpvoteArticle")
54+
55+
assert updated["id"] == to_string(job.id)
56+
end
57+
58+
@tag :wip2
59+
test "unauth user undo upvote a job fails", ~m(guest_conn job)a do
60+
variables = %{id: job.id, thread: "JOB"}
61+
62+
assert guest_conn
63+
|> mutation_get_error?(@query, variables, ecode(:account_login))
64+
end
65+
end
66+
end
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
defmodule GroupherServer.Test.Mutation.ArticleUpvote do
1+
defmodule GroupherServer.Test.Mutation.Upvotes.PostUpvote do
22
@moduledoc false
33
use GroupherServer.TestTools
44

55
alias GroupherServer.CMS
66

77
setup do
88
{:ok, post} = db_insert(:post)
9-
{:ok, job} = db_insert(:job)
109
{:ok, user} = db_insert(:user)
1110

1211
guest_conn = simu_conn(:guest)
1312
user_conn = simu_conn(:user, user)
1413

15-
{:ok, ~m(user_conn guest_conn post job user)a}
14+
{:ok, ~m(user_conn guest_conn post user)a}
1615
end
1716

1817
describe "[post upvote]" do
@@ -23,15 +22,15 @@ defmodule GroupherServer.Test.Mutation.ArticleUpvote do
2322
}
2423
}
2524
"""
26-
@tag :wip
25+
@tag :wip2
2726
test "login user can upvote a post", ~m(user_conn post)a do
2827
variables = %{id: post.id, thread: "POST"}
2928
created = user_conn |> mutation_result(@query, variables, "upvoteArticle")
3029

3130
assert created["id"] == to_string(post.id)
3231
end
3332

34-
@tag :wip
33+
@tag :wip2
3534
test "unauth user upvote a post fails", ~m(guest_conn post)a do
3635
variables = %{id: post.id, thread: "POST"}
3736

@@ -46,7 +45,7 @@ defmodule GroupherServer.Test.Mutation.ArticleUpvote do
4645
}
4746
}
4847
"""
49-
@tag :wip
48+
@tag :wip2
5049
test "login user can undo upvote to a post", ~m(user_conn post user)a do
5150
{:ok, _} = CMS.upvote_article(:post, post.id, user)
5251

@@ -56,62 +55,12 @@ defmodule GroupherServer.Test.Mutation.ArticleUpvote do
5655
assert updated["id"] == to_string(post.id)
5756
end
5857

59-
@tag :wip
58+
@tag :wip2
6059
test "unauth user undo upvote a post fails", ~m(guest_conn post)a do
6160
variables = %{id: post.id, thread: "POST"}
6261

6362
assert guest_conn
6463
|> mutation_get_error?(@query, variables, ecode(:account_login))
6564
end
6665
end
67-
68-
describe "[job upvote]" do
69-
@query """
70-
mutation($id: ID!, $thread: CmsThread!) {
71-
upvoteArticle(id: $id, thread: $thread) {
72-
id
73-
}
74-
}
75-
"""
76-
@tag :wip
77-
test "login user can upvote a job", ~m(user_conn job)a do
78-
variables = %{id: job.id, thread: "JOB"}
79-
created = user_conn |> mutation_result(@query, variables, "upvoteArticle")
80-
81-
assert created["id"] == to_string(job.id)
82-
end
83-
84-
@tag :wip
85-
test "unauth user upvote a job fails", ~m(guest_conn job)a do
86-
variables = %{id: job.id, thread: "JOB"}
87-
88-
assert guest_conn
89-
|> mutation_get_error?(@query, variables, ecode(:account_login))
90-
end
91-
92-
@query """
93-
mutation($id: ID!, $thread: CmsThread!) {
94-
undoUpvoteArticle(id: $id, thread: $thread) {
95-
id
96-
}
97-
}
98-
"""
99-
@tag :wip
100-
test "login user can undo upvote to a job", ~m(user_conn job user)a do
101-
{:ok, _} = CMS.upvote_article(:job, job.id, user)
102-
103-
variables = %{id: job.id, thread: "JOB"}
104-
updated = user_conn |> mutation_result(@query, variables, "undoUpvoteArticle")
105-
106-
assert updated["id"] == to_string(job.id)
107-
end
108-
109-
@tag :wip
110-
test "unauth user undo upvote a job fails", ~m(guest_conn job)a do
111-
variables = %{id: job.id, thread: "JOB"}
112-
113-
assert guest_conn
114-
|> mutation_get_error?(@query, variables, ecode(:account_login))
115-
end
116-
end
11766
end

0 commit comments

Comments
 (0)