@@ -5,13 +5,11 @@ defmodule GroupherServer.Test.CMS.AbuseReports.PostReport do
55
66 alias Helper.ORM
77 alias GroupherServer.CMS
8-
9- alias CMS.AbuseReport
8+ # alias CMS.AbuseReport
109
1110 setup do
1211 { :ok , user } = db_insert ( :user )
1312 { :ok , user2 } = db_insert ( :user )
14- { :ok , post } = db_insert ( :post )
1513
1614 { :ok , community } = db_insert ( :community )
1715 post_attrs = mock_attrs ( :post , % { community_id: community . id } )
@@ -23,7 +21,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.PostReport do
2321 @ tag :wip2
2422 test "report a post should have a abuse report record" , ~m( community user post_attrs) a do
2523 { :ok , post } = CMS . create_content ( community , :post , post_attrs , user )
26- { :ok , report } = CMS . report_article ( :post , post . id , "reason" , "attr_info" , user )
24+ { :ok , _report } = CMS . report_article ( :post , post . id , "reason" , "attr_info" , user )
2725
2826 { :ok , all_reports } = CMS . list_reports ( :post , post . id , % { page: 1 , size: 20 } )
2927
@@ -40,14 +38,50 @@ defmodule GroupherServer.Test.CMS.AbuseReports.PostReport do
4038 assert post . meta . reported_count == 1
4139 end
4240
43- @ tag :wip
41+ @ tag :wip2
42+ test "can undo a report" , ~m( community user post_attrs) a do
43+ { :ok , post } = CMS . create_content ( community , :post , post_attrs , user )
44+ { :ok , _report } = CMS . report_article ( :post , post . id , "reason" , "attr_info" , user )
45+ { :ok , _report } = CMS . undo_report_article ( :post , post . id , user )
46+
47+ { :ok , all_reports } = CMS . list_reports ( :post , post . id , % { page: 1 , size: 20 } )
48+ assert all_reports . total_count == 0
49+ end
50+
51+ @ tag :wip2
52+ test "can undo a report with other user report it too" ,
53+ ~m( community user user2 post_attrs) a do
54+ { :ok , post } = CMS . create_content ( community , :post , post_attrs , user )
55+ { :ok , _report } = CMS . report_article ( :post , post . id , "reason" , "attr_info" , user )
56+ { :ok , _report } = CMS . report_article ( :post , post . id , "reason" , "attr_info" , user2 )
57+
58+ { :ok , all_reports } = CMS . list_reports ( :post , post . id , % { page: 1 , size: 20 } )
59+ assert all_reports . total_count == 1
60+
61+ report = all_reports . entries |> List . first ( )
62+ assert report . report_cases |> length == 2
63+ assert Enum . any? ( report . report_cases , & ( & 1 . user . login == user . login ) )
64+ assert Enum . any? ( report . report_cases , & ( & 1 . user . login == user2 . login ) )
65+
66+ { :ok , _report } = CMS . undo_report_article ( :post , post . id , user )
67+
68+ { :ok , all_reports } = CMS . list_reports ( :post , post . id , % { page: 1 , size: 20 } )
69+ assert all_reports . total_count == 1
70+
71+ report = all_reports . entries |> List . first ( )
72+ assert report . report_cases |> length == 1
73+ assert Enum . any? ( report . report_cases , & ( & 1 . user . login == user2 . login ) )
74+ end
75+
76+ @ tag :wip2
4477 test "different user report a comment should have same report with different report cases" ,
45- ~m( user user2 post) a do
46- { :ok , comment } = CMS . create_article_comment ( :post , post . id , "commment" , user )
47- { :ok , _ } = CMS . report_article_comment ( comment . id , user )
48- { :ok , _ } = CMS . report_article_comment ( comment . id , user2 )
78+ ~m( community user user2 post_attrs) a do
79+ { :ok , post } = CMS . create_content ( community , :post , post_attrs , user )
80+
81+ { :ok , _report } = CMS . report_article ( :post , post . id , "reason" , "attr_info" , user )
82+ { :ok , _report } = CMS . report_article ( :post , post . id , "reason2" , "attr_info 2" , user2 )
4983
50- { :ok , all_reports } = CMS . list_reports ( :article_comment , comment . id , % { page: 1 , size: 20 } )
84+ { :ok , all_reports } = CMS . list_reports ( :post , post . id , % { page: 1 , size: 20 } )
5185
5286 report = List . first ( all_reports . entries )
5387 report_cases = report . report_cases
@@ -60,11 +94,12 @@ defmodule GroupherServer.Test.CMS.AbuseReports.PostReport do
6094 assert List . last ( report_cases ) . user . login == user2 . login
6195 end
6296
63- @ tag :wip
64- test "same user can not report a comment twice" , ~m( user post) a do
65- { :ok , comment } = CMS . create_article_comment ( :post , post . id , "commment" , user )
66- { :ok , comment } = CMS . report_article_comment ( comment . id , user )
67- assert { :error , _ } = CMS . report_article_comment ( comment . id , user )
97+ @ tag :wip2
98+ test "same user can not report a comment twice" , ~m( community post_attrs user) a do
99+ { :ok , post } = CMS . create_content ( community , :post , post_attrs , user )
100+
101+ { :ok , _report } = CMS . report_article ( :post , post . id , "reason" , "attr_info" , user )
102+ assert { :error , _report } = CMS . report_article ( :post , post . id , "reason" , "attr_info" , user )
68103 end
69104 end
70105end
0 commit comments