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

Commit 206ef64

Browse files
committed
test: rm unnecessary pattern args in func
1 parent 7a94f57 commit 206ef64

File tree

5 files changed

+40
-48
lines changed

5 files changed

+40
-48
lines changed

lib/mastani_server/cms/delegates/seeds.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,21 +421,21 @@ defmodule MastaniServer.CMS.Delegate.Seeds do
421421
thread = raw |> String.to_atom()
422422

423423
Enum.each(SeedsConfig.tags(thread), fn attr ->
424-
CMS.create_tag(community, thread, attr, %Accounts.User{id: bot.id})
424+
CMS.create_tag(community, thread, attr, bot)
425425
end)
426426
end
427427

428428
defp set_tags(%Community{} = community, :post, bot, :city) do
429429
Enum.each(SeedsConfig.tags(:city, :post), fn attr ->
430-
CMS.create_tag(community, :post, attr, %Accounts.User{id: bot.id})
430+
CMS.create_tag(community, :post, attr, bot)
431431
end)
432432
end
433433

434434
defp set_tags(%Community{} = community, %Thread{raw: raw}, bot, :home) do
435435
thread = raw |> String.to_atom()
436436

437437
Enum.each(SeedsConfig.tags(:home, thread), fn attr ->
438-
CMS.create_tag(community, thread, attr, %Accounts.User{id: bot.id})
438+
CMS.create_tag(community, thread, attr, bot)
439439
end)
440440
end
441441

test/mastani_server/cms/cms_test.exs

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,22 @@ defmodule MastaniServer.Test.CMS do
1919
test "create tag with valid data", ~m(community user)a do
2020
valid_attrs = mock_attrs(:tag)
2121

22-
{:ok, tag} = CMS.create_tag(community, :post, valid_attrs, %User{id: user.id})
22+
{:ok, tag} = CMS.create_tag(community, :post, valid_attrs, user)
2323
assert tag.title == valid_attrs.title
2424
end
2525

2626
test "create tag with non-exsit user fails", ~m(user)a do
2727
invalid_attrs = mock_attrs(:tag)
2828

2929
assert {:error, _} =
30-
CMS.create_tag(%Community{id: non_exsit_id()}, :post, invalid_attrs, %User{
31-
id: user.id
32-
})
30+
CMS.create_tag(%Community{id: non_exsit_id()}, :post, invalid_attrs, user)
3331
end
3432

3533
test "create tag with non-exsit community fails", ~m(user)a do
3634
invalid_attrs = mock_attrs(:tag)
3735

3836
assert {:error, _} =
39-
CMS.create_tag(%Community{id: non_exsit_id()}, :post, invalid_attrs, %User{
40-
id: user.id
41-
})
37+
CMS.create_tag(%Community{id: non_exsit_id()}, :post, invalid_attrs, user)
4238
end
4339
end
4440

@@ -49,7 +45,7 @@ defmodule MastaniServer.Test.CMS do
4945
valid_attrs = mock_attrs(:category, %{user_id: user.id})
5046
~m(title raw)a = valid_attrs
5147

52-
{:ok, category} = CMS.create_category(~m(title raw)a, %User{id: user.id})
48+
{:ok, category} = CMS.create_category(~m(title raw)a, user)
5349

5450
assert category.title == valid_attrs.title
5551
end
@@ -58,36 +54,38 @@ defmodule MastaniServer.Test.CMS do
5854
valid_attrs = mock_attrs(:category, %{user_id: user.id})
5955
~m(title raw)a = valid_attrs
6056

61-
assert {:ok, _} = CMS.create_category(~m(title raw)a, %User{id: user.id})
62-
assert {:error, _} = CMS.create_category(~m(title)a, %User{id: user.id})
57+
assert {:ok, _} = CMS.create_category(~m(title raw)a, user)
58+
assert {:error, _} = CMS.create_category(~m(title)a, user)
6359
end
6460

6561
test "update category with valid attrs", ~m(user)a do
6662
valid_attrs = mock_attrs(:category, %{user_id: user.id})
6763
~m(title raw)a = valid_attrs
6864

69-
{:ok, category} = CMS.create_category(~m(title raw)a, %User{id: user.id})
65+
{:ok, category} = CMS.create_category(~m(title raw)a, user)
7066

7167
assert category.title == valid_attrs.title
7268
{:ok, updated} = CMS.update_category(%Category{id: category.id, title: "new title"})
7369

7470
assert updated.title == "new title"
7571
end
7672

73+
@tag :wip
7774
test "update title to existing title fails", ~m(user)a do
7875
valid_attrs = mock_attrs(:category, %{user_id: user.id})
7976
~m(title raw)a = valid_attrs
8077

81-
{:ok, category} = CMS.create_category(~m(title raw)a, %User{id: user.id})
78+
{:ok, category} = CMS.create_category(~m(title raw)a, user)
8279

8380
new_category_attrs = %{title: "category2 title", raw: "category2 title"}
84-
{:ok, category2} = CMS.create_category(new_category_attrs, %User{id: user.id})
81+
{:ok, category2} = CMS.create_category(new_category_attrs, user)
8582

8683
{:error, _} = CMS.update_category(%Category{id: category.id, title: category2.title})
8784
end
8885

86+
@tag :wip
8987
test "can set a category to a community", ~m(community category)a do
90-
{:ok, _} = CMS.set_category(%Community{id: community.id}, %Category{id: category.id})
88+
{:ok, _} = CMS.set_category(community, category)
9189

9290
{:ok, found_community} = ORM.find(Community, community.id, preload: :categories)
9391
{:ok, found_category} = ORM.find(Category, category.id, preload: :communities)
@@ -99,10 +97,10 @@ defmodule MastaniServer.Test.CMS do
9997
assert community.id in assoc_communities
10098
end
10199

100+
@tag :wip
102101
test "can unset a category to a community", ~m(community category)a do
103-
{:ok, _} = CMS.set_category(%Community{id: community.id}, %Category{id: category.id})
104-
105-
CMS.unset_category(%Community{id: community.id}, %Category{id: category.id})
102+
{:ok, _} = CMS.set_category(community, category)
103+
CMS.unset_category(community, category)
106104

107105
{:ok, found_community} = ORM.find(Community, community.id, preload: :categories)
108106
{:ok, found_category} = ORM.find(Category, category.id, preload: :communities)
@@ -169,14 +167,12 @@ defmodule MastaniServer.Test.CMS do
169167
assert {:error, _error} = CMS.create_thread(~m(title raw)a)
170168
end
171169

170+
@tag :wip
172171
test "can set a thread to community", ~m(community)a do
173172
title = "POST"
174173
raw = title
175174
{:ok, thread} = CMS.create_thread(~m(title raw)a)
176-
thread_id = thread.id
177-
community_id = community.id
178-
179-
{:ok, ret_community} = CMS.set_thread(%Community{id: community_id}, %Thread{id: thread_id})
175+
{:ok, ret_community} = CMS.set_thread(community, thread)
180176

181177
assert ret_community.id == community.id
182178
end
@@ -185,6 +181,7 @@ defmodule MastaniServer.Test.CMS do
185181
describe "[cms community editors]" do
186182
alias CMS.{Community, CommunityEditor}
187183

184+
@tag :wip
188185
test "can add editor to a community, editor has default passport", ~m(user community)a do
189186
title = "chief editor"
190187

@@ -193,7 +190,7 @@ defmodule MastaniServer.Test.CMS do
193190
related_rules = Certification.passport_rules(cms: title)
194191

195192
{:ok, editor} = CommunityEditor |> ORM.find_by(user_id: user.id)
196-
{:ok, user_passport} = CMS.get_passport(%User{id: user.id})
193+
{:ok, user_passport} = CMS.get_passport(user)
197194

198195
assert editor.user_id == user.id
199196
assert editor.community_id == community.id

test/mastani_server_web/mutation/cms/cms_test.exs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,8 +541,9 @@ defmodule MastaniServer.Test.Mutation.CMS.Basic do
541541
}
542542
}
543543
"""
544+
@tag :wip
544545
test "auth user can remove thread from community", ~m(user community thread)a do
545-
CMS.set_thread(%Community{id: community.id}, %Thread{id: thread.id})
546+
CMS.set_thread(community, thread)
546547
{:ok, found_community} = Community |> ORM.find(community.id, preload: :threads)
547548

548549
assert found_community.threads |> Enum.any?(&(&1.thread_id == thread.id))

test/mastani_server_web/mutation/cms/job_test.exs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,12 @@ defmodule MastaniServer.Test.Mutation.Job do
180180
assert updated["salary"] == variables.salary
181181
end
182182

183+
@tag :wip
183184
test "job can be update along with tags(city)", ~m(owner_conn user job)a do
184185
unique_num = System.unique_integer([:positive, :monotonic])
185186

186187
{:ok, community} = db_insert(:community)
187-
{:ok, tag} = CMS.create_tag(%CMS.Community{id: community.id}, :job, mock_attrs(:tag), user)
188+
{:ok, tag} = CMS.create_tag(community, :job, mock_attrs(:tag), user)
188189

189190
variables = %{
190191
id: job.id,
@@ -204,10 +205,8 @@ defmodule MastaniServer.Test.Mutation.Job do
204205

205206
{:ok, community} = db_insert(:community)
206207
{:ok, community2} = db_insert(:community)
207-
{:ok, tag} = CMS.create_tag(%CMS.Community{id: community.id}, :job, mock_attrs(:tag), user)
208-
209-
{:ok, tag2} =
210-
CMS.create_tag(%CMS.Community{id: community2.id}, :job, mock_attrs(:tag), user)
208+
{:ok, tag} = CMS.create_tag(community, :job, mock_attrs(:tag), user)
209+
{:ok, tag2} = CMS.create_tag(community2, :job, mock_attrs(:tag), user)
211210

212211
{:ok, _} = CMS.set_tag(:job, tag2, job.id)
213212

test/mastani_server_web/query/cms/cms_test.exs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ defmodule MastaniServer.Test.Query.CMS.Basic do
4141
assert results["id"] == aka_results["id"]
4242
end
4343

44+
@tag :wip
4445
test "can get threads count ", ~m(community guest_conn)a do
4546
{:ok, threads} = db_insert_multi(:thread, 5)
4647

47-
Enum.map(threads, fn t ->
48-
CMS.set_thread(%Community{id: community.id}, %Thread{id: t.id})
48+
Enum.map(threads, fn thread ->
49+
CMS.set_thread(community, thread)
4950
end)
5051

5152
variables = %{raw: community.raw}
@@ -54,29 +55,26 @@ defmodule MastaniServer.Test.Query.CMS.Basic do
5455
assert results["threadsCount"] == 5
5556
end
5657

58+
@tag :wip
5759
test "can get tags count ", ~m(community guest_conn user)a do
5860
{:ok, _tags} = db_insert_multi(:tag, 5)
5961

60-
CMS.create_tag(%Community{id: community.id}, :post, mock_attrs(:tag), %User{
61-
id: user.id
62-
})
63-
64-
CMS.create_tag(%Community{id: community.id}, :post, mock_attrs(:tag), %User{
65-
id: user.id
66-
})
62+
CMS.create_tag(community, :post, mock_attrs(:tag), user)
63+
CMS.create_tag(community, :post, mock_attrs(:tag), user)
6764

6865
variables = %{raw: community.raw}
6966
results = guest_conn |> query_result(@query, variables, "community")
7067

7168
assert results["tagsCount"] == 2
7269
end
7370

71+
@tag :wip
7472
test "guest use get community threads with default asc sort index",
7573
~m(guest_conn community)a do
7674
{:ok, threads} = db_insert_multi(:thread, 5)
7775

78-
Enum.map(threads, fn t ->
79-
CMS.set_thread(%Community{id: community.id}, %Thread{id: t.id})
76+
Enum.map(threads, fn thead ->
77+
CMS.set_thread(community, thread)
8078
end)
8179

8280
variables = %{id: community.id}
@@ -287,13 +285,12 @@ defmodule MastaniServer.Test.Query.CMS.Basic do
287285
}
288286
}
289287
"""
288+
@tag :wip
290289
test "guest user can get paged tags", ~m(guest_conn community user)a do
291290
variables = %{filter: %{page: 1, size: 10}}
292291

293292
valid_attrs = mock_attrs(:tag, %{user_id: user.id})
294-
295-
{:ok, _} =
296-
CMS.create_tag(%Community{id: community.id}, :post, valid_attrs, %User{id: user.id})
293+
{:ok, _} = CMS.create_tag(community, :post, valid_attrs, user)
297294

298295
results = guest_conn |> query_result(@query, variables, "tags")
299296

@@ -345,9 +342,7 @@ defmodule MastaniServer.Test.Query.CMS.Basic do
345342

346343
test "user can get partial tags by default index topic", ~m(guest_conn community user)a do
347344
valid_attrs = mock_attrs(:tag)
348-
349-
{:ok, _tag} =
350-
CMS.create_tag(%Community{id: community.id}, :post, valid_attrs, %User{id: user.id})
345+
{:ok, _tag} = CMS.create_tag(community, :post, valid_attrs, user)
351346

352347
variables = %{thread: "POST", communityId: community.id, topic: "posts"}
353348
results = guest_conn |> query_result(@query, variables, "partialTags")

0 commit comments

Comments
 (0)