Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commitb771a0d

Browse files
committed
chore: tests
1 parentf2dd9e4 commitb771a0d

File tree

26 files changed

+5014
-0
lines changed

26 files changed

+5014
-0
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
defmoduleGroupherServer.Test.Accounts.Published.Drinkdo
2+
useGroupherServer.TestTools
3+
4+
aliasGroupherServer.{Accounts,CMS}
5+
aliasAccounts.Model.User
6+
aliasHelper.ORM
7+
8+
@publish_count10
9+
10+
setupdo
11+
{:ok,user}=db_insert(:user)
12+
{:ok,user2}=db_insert(:user)
13+
{:ok,drink}=db_insert(:drink)
14+
{:ok,community}=db_insert(:community)
15+
{:ok,community2}=db_insert(:community)
16+
17+
{:ok,~m(user user2 drink community community2)a}
18+
end
19+
20+
describe"[publised drinks]"do
21+
test"create drink should update user published meta",~m(community user)ado
22+
drink_attrs=mock_attrs(:drink,%{community_id:community.id})
23+
{:ok,_drink}=CMS.create_article(community,:drink,drink_attrs,user)
24+
{:ok,_drink}=CMS.create_article(community,:drink,drink_attrs,user)
25+
26+
{:ok,user}=ORM.find(User,user.id)
27+
assertuser.meta.published_drinks_count==2
28+
end
29+
30+
test"fresh user get empty paged published drinks",~m(user)ado
31+
{:ok,results}=Accounts.paged_published_articles(user,:drink,%{page:1,size:20})
32+
33+
assertresults|>is_valid_pagination?(:raw)
34+
assertresults.total_count==0
35+
end
36+
37+
test"user can get paged published drinks",~m(user user2 community community2)ado
38+
pub_drinks=
39+
Enum.reduce(1..@publish_count,[],fn_,acc->
40+
drink_attrs=mock_attrs(:drink,%{community_id:community.id})
41+
{:ok,drink}=CMS.create_article(community,:drink,drink_attrs,user)
42+
43+
acc++[drink]
44+
end)
45+
46+
pub_drinks2=
47+
Enum.reduce(1..@publish_count,[],fn_,acc->
48+
drink_attrs=mock_attrs(:drink,%{community_id:community2.id})
49+
{:ok,drink}=CMS.create_article(community,:drink,drink_attrs,user)
50+
51+
acc++[drink]
52+
end)
53+
54+
# unrelated other user
55+
Enum.reduce(1..5,[],fn_,acc->
56+
drink_attrs=mock_attrs(:drink,%{community_id:community.id})
57+
{:ok,drink}=CMS.create_article(community,:drink,drink_attrs,user2)
58+
59+
acc++[drink]
60+
end)
61+
62+
{:ok,results}=Accounts.paged_published_articles(user,:drink,%{page:1,size:20})
63+
64+
assertresults|>is_valid_pagination?(:raw)
65+
assertresults.total_count==@publish_count*2
66+
67+
random_drink_id=pub_drinks|>Enum.random()|>Map.get(:id)
68+
random_drink_id2=pub_drinks2|>Enum.random()|>Map.get(:id)
69+
assertresults.entries|>Enum.any?(&(&1.id==random_drink_id))
70+
assertresults.entries|>Enum.any?(&(&1.id==random_drink_id2))
71+
end
72+
end
73+
74+
describe"[publised drink comments]"do
75+
test"can get published article comments",~m(drink user)ado
76+
total_count=10
77+
78+
Enum.reduce(1..total_count,[],fn_,acc->
79+
{:ok,comment}=CMS.create_comment(:drink,drink.id,mock_comment(),user)
80+
acc++[comment]
81+
end)
82+
83+
filter=%{page:1,size:20}
84+
{:ok,articles}=Accounts.paged_published_comments(user,:drink,filter)
85+
86+
entries=articles.entries
87+
article=entries|>List.first()
88+
89+
assertarticle.article.id==drink.id
90+
assertarticle.article.title==drink.title
91+
end
92+
end
93+
end
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
defmoduleGroupherServer.Test.CMS.AbuseReports.DrinkReportdo
2+
@moduledocfalse
3+
4+
useGroupherServer.TestTools
5+
6+
aliasHelper.ORM
7+
aliasGroupherServer.CMS
8+
aliasCMS.Model.Drink
9+
10+
setupdo
11+
{:ok,user}=db_insert(:user)
12+
{:ok,user2}=db_insert(:user)
13+
14+
{:ok,community}=db_insert(:community)
15+
drink_attrs=mock_attrs(:drink,%{community_id:community.id})
16+
17+
{:ok,~m(user user2 community drink_attrs)a}
18+
end
19+
20+
describe"[article drink report/unreport]"do
21+
test"list article reports should work",~m(community user user2 drink_attrs)ado
22+
{:ok,drink}=CMS.create_article(community,:drink,drink_attrs,user)
23+
{:ok,_report}=CMS.report_article(:drink,drink.id,"reason","attr_info",user)
24+
{:ok,_report}=CMS.report_article(:drink,drink.id,"reason","attr_info",user2)
25+
26+
filter=%{content_type::drink,content_id:drink.id,page:1,size:20}
27+
{:ok,all_reports}=CMS.paged_reports(filter)
28+
29+
report=all_reports.entries|>List.first()
30+
assertreport.article.id==drink.id
31+
assertreport.article.thread=="DRINK"
32+
end
33+
34+
test"report a drink should have a abuse report record",~m(community user drink_attrs)ado
35+
{:ok,drink}=CMS.create_article(community,:drink,drink_attrs,user)
36+
{:ok,_report}=CMS.report_article(:drink,drink.id,"reason","attr_info",user)
37+
38+
filter=%{content_type::drink,content_id:drink.id,page:1,size:20}
39+
{:ok,all_reports}=CMS.paged_reports(filter)
40+
41+
report=List.first(all_reports.entries)
42+
report_cases=report.report_cases
43+
44+
assertreport.article.id==drink.id
45+
assertall_reports.total_count==1
46+
assertreport.report_cases_count==1
47+
assertList.first(report_cases).user.login==user.login
48+
49+
{:ok,drink}=ORM.find(Drink,drink.id)
50+
assertdrink.meta.reported_count==1
51+
assertuser.idindrink.meta.reported_user_ids
52+
end
53+
54+
test"can undo a report",~m(community user drink_attrs)ado
55+
{:ok,drink}=CMS.create_article(community,:drink,drink_attrs,user)
56+
{:ok,_report}=CMS.report_article(:drink,drink.id,"reason","attr_info",user)
57+
{:ok,_report}=CMS.undo_report_article(:drink,drink.id,user)
58+
59+
filter=%{content_type::drink,content_id:drink.id,page:1,size:20}
60+
{:ok,all_reports}=CMS.paged_reports(filter)
61+
assertall_reports.total_count==0
62+
63+
{:ok,drink}=ORM.find(Drink,drink.id)
64+
assertuser.idnot indrink.meta.reported_user_ids
65+
end
66+
67+
test"can undo a existed report",~m(community user user2 drink_attrs)ado
68+
{:ok,drink}=CMS.create_article(community,:drink,drink_attrs,user)
69+
{:ok,_report}=CMS.report_article(:drink,drink.id,"reason","attr_info",user)
70+
{:ok,_report}=CMS.report_article(:drink,drink.id,"reason","attr_info",user2)
71+
{:ok,_report}=CMS.undo_report_article(:drink,drink.id,user)
72+
73+
filter=%{content_type::drink,content_id:drink.id,page:1,size:20}
74+
{:ok,all_reports}=CMS.paged_reports(filter)
75+
assertall_reports.total_count==1
76+
77+
{:ok,drink}=ORM.find(Drink,drink.id)
78+
79+
assertuser2.idindrink.meta.reported_user_ids
80+
assertuser.idnot indrink.meta.reported_user_ids
81+
end
82+
83+
test"can undo a report with other user report it too",
84+
~m(community user user2 drink_attrs)ado
85+
{:ok,drink}=CMS.create_article(community,:drink,drink_attrs,user)
86+
{:ok,_report}=CMS.report_article(:drink,drink.id,"reason","attr_info",user)
87+
{:ok,_report}=CMS.report_article(:drink,drink.id,"reason","attr_info",user2)
88+
89+
filter=%{content_type::drink,content_id:drink.id,page:1,size:20}
90+
{:ok,all_reports}=CMS.paged_reports(filter)
91+
assertall_reports.total_count==1
92+
93+
report=all_reports.entries|>List.first()
94+
assertreport.report_cases|>length==2
95+
assertEnum.any?(report.report_cases,&(&1.user.login==user.login))
96+
assertEnum.any?(report.report_cases,&(&1.user.login==user2.login))
97+
98+
{:ok,_report}=CMS.undo_report_article(:drink,drink.id,user)
99+
100+
filter=%{content_type::drink,content_id:drink.id,page:1,size:20}
101+
{:ok,all_reports}=CMS.paged_reports(filter)
102+
assertall_reports.total_count==1
103+
104+
report=all_reports.entries|>List.first()
105+
assertreport.report_cases|>length==1
106+
assertEnum.any?(report.report_cases,&(&1.user.login==user2.login))
107+
end
108+
109+
test"different user report a comment should have same report with different report cases",
110+
~m(community user user2 drink_attrs)ado
111+
{:ok,drink}=CMS.create_article(community,:drink,drink_attrs,user)
112+
113+
{:ok,_report}=CMS.report_article(:drink,drink.id,"reason","attr_info",user)
114+
{:ok,_report}=CMS.report_article(:drink,drink.id,"reason2","attr_info 2",user2)
115+
116+
filter=%{content_type::drink,content_id:drink.id,page:1,size:20}
117+
{:ok,all_reports}=CMS.paged_reports(filter)
118+
119+
report=List.first(all_reports.entries)
120+
report_cases=report.report_cases
121+
122+
assertall_reports.total_count==1
123+
assertlength(report_cases)==2
124+
assertreport.report_cases_count==2
125+
126+
assertList.first(report_cases).user.login==user.login
127+
assertList.last(report_cases).user.login==user2.login
128+
end
129+
130+
test"same user can not report a comment twice",~m(community drink_attrs user)ado
131+
{:ok,drink}=CMS.create_article(community,:drink,drink_attrs,user)
132+
133+
{:ok,_report}=CMS.report_article(:drink,drink.id,"reason","attr_info",user)
134+
assert{:error,_report}=CMS.report_article(:drink,drink.id,"reason","attr_info",user)
135+
end
136+
end
137+
end
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
defmoduleGroupherServer.Test.CMS.ArticleCommunity.Drinkdo
2+
useGroupherServer.TestTools
3+
4+
aliasHelper.ORM
5+
aliasGroupherServer.CMS
6+
aliasCMS.Model.Drink
7+
8+
setupdo
9+
{:ok,user}=db_insert(:user)
10+
{:ok,user2}=db_insert(:user)
11+
{:ok,drink}=db_insert(:drink)
12+
{:ok,community}=db_insert(:community)
13+
{:ok,community2}=db_insert(:community)
14+
{:ok,community3}=db_insert(:community)
15+
16+
drink_attrs=mock_attrs(:drink,%{community_id:community.id})
17+
18+
{:ok,~m(user user2 community community2 community3 drink drink_attrs)a}
19+
end
20+
21+
describe"[article mirror/move]"do
22+
test"created drink has origial community info",~m(user community drink_attrs)ado
23+
{:ok,drink}=CMS.create_article(community,:drink,drink_attrs,user)
24+
{:ok,drink}=ORM.find(Drink,drink.id,preload::original_community)
25+
26+
assertdrink.original_community_id==community.id
27+
end
28+
29+
test"drink can be move to other community",~m(user community community2 drink_attrs)ado
30+
{:ok,drink}=CMS.create_article(community,:drink,drink_attrs,user)
31+
assertdrink.original_community_id==community.id
32+
33+
{:ok,_}=CMS.move_article(:drink,drink.id,community2.id)
34+
{:ok,drink}=ORM.find(Drink,drink.id,preload:[:original_community,:communities])
35+
36+
assertdrink.original_community.id==community2.id
37+
assertnotis_nil(Enum.find(drink.communities,&(&1.id==community2.id)))
38+
end
39+
40+
test"drink can be mirror to other community",~m(user community community2 drink_attrs)ado
41+
{:ok,drink}=CMS.create_article(community,:drink,drink_attrs,user)
42+
43+
{:ok,drink}=ORM.find(Drink,drink.id,preload::communities)
44+
assertdrink.communities|>length==1
45+
46+
assertnotis_nil(Enum.find(drink.communities,&(&1.id==community.id)))
47+
48+
{:ok,_}=CMS.mirror_article(:drink,drink.id,community2.id)
49+
50+
{:ok,drink}=ORM.find(Drink,drink.id,preload::communities)
51+
assertdrink.communities|>length==2
52+
assertnotis_nil(Enum.find(drink.communities,&(&1.id==community.id)))
53+
assertnotis_nil(Enum.find(drink.communities,&(&1.id==community2.id)))
54+
end
55+
56+
test"drink can be unmirror from community",
57+
~m(user community community2 community3 drink_attrs)ado
58+
{:ok,drink}=CMS.create_article(community,:drink,drink_attrs,user)
59+
{:ok,_}=CMS.mirror_article(:drink,drink.id,community2.id)
60+
{:ok,_}=CMS.mirror_article(:drink,drink.id,community3.id)
61+
62+
{:ok,drink}=ORM.find(Drink,drink.id,preload::communities)
63+
assertdrink.communities|>length==3
64+
65+
{:ok,_}=CMS.unmirror_article(:drink,drink.id,community3.id)
66+
{:ok,drink}=ORM.find(Drink,drink.id,preload::communities)
67+
assertdrink.communities|>length==2
68+
69+
assertis_nil(Enum.find(drink.communities,&(&1.id==community3.id)))
70+
end
71+
72+
test"drink can not unmirror from original community",
73+
~m(user community community2 community3 drink_attrs)ado
74+
{:ok,drink}=CMS.create_article(community,:drink,drink_attrs,user)
75+
{:ok,_}=CMS.mirror_article(:drink,drink.id,community2.id)
76+
{:ok,_}=CMS.mirror_article(:drink,drink.id,community3.id)
77+
78+
{:ok,drink}=ORM.find(Drink,drink.id,preload::communities)
79+
assertdrink.communities|>length==3
80+
81+
{:error,reason}=CMS.unmirror_article(:drink,drink.id,community.id)
82+
assertreason|>is_error?(:mirror_article)
83+
end
84+
end
85+
end

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp