1- defmodule GroupherServer.Test.Mutation.Articles .Post do
1+ defmodule GroupherServer.Test.Mutation.ArticleCommunity .Post do
22 use GroupherServer.TestTools
33
4- alias Helper . { ORM , Utils }
5- alias GroupherServer . { CMS , Delivery }
4+ alias Helper.ORM
5+ alias GroupherServer.CMS
66
77 setup do
88 { :ok , post } = db_insert ( :post )
@@ -122,7 +122,7 @@ defmodule GroupherServer.Test.Mutation.Articles.Post do
122122 }
123123 }
124124 """
125- test "auth user can set a community to post " , ~m( post) a do
125+ test "auth user can mirror a post to other community " , ~m( post) a do
126126 passport_rules = % { "post.community.mirror" => true }
127127 rule_conn = simu_conn ( :user , cms: passport_rules )
128128
@@ -135,7 +135,7 @@ defmodule GroupherServer.Test.Mutation.Articles.Post do
135135 assert community . id in assoc_communities
136136 end
137137
138- test "unauth user set a community to post fails " , ~m( user_conn guest_conn post) a do
138+ test "unauth user cannot mirror a post to a community " , ~m( user_conn guest_conn post) a do
139139 { :ok , community } = db_insert ( :community )
140140 variables = % { id: post . id , communityId: community . id }
141141 rule_conn = simu_conn ( :user , cms: % { "what.ever" => true } )
@@ -150,7 +150,7 @@ defmodule GroupherServer.Test.Mutation.Articles.Post do
150150 |> mutation_get_error? ( @ mirror_article_query , variables , ecode ( :passport ) )
151151 end
152152
153- test "auth user can set multi community to a post " , ~m( post) a do
153+ test "auth user can mirror multi post to other communities " , ~m( post) a do
154154 passport_rules = % { "post.community.mirror" => true }
155155 rule_conn = simu_conn ( :user , cms: passport_rules )
156156
@@ -178,7 +178,7 @@ defmodule GroupherServer.Test.Mutation.Articles.Post do
178178 }
179179 """
180180 @ tag :wip2
181- test "auth user can unset community from a post " , ~m( post) a do
181+ test "auth user can unmirror post to a community " , ~m( post) a do
182182 passport_rules = % { "post.community.mirror" => true }
183183 rule_conn = simu_conn ( :user , cms: passport_rules )
184184
@@ -206,5 +206,42 @@ defmodule GroupherServer.Test.Mutation.Articles.Post do
206206 assert community . id not in assoc_communities
207207 assert community2 . id in assoc_communities
208208 end
209+
210+ @ move_article_query """
211+ mutation($id: ID!, $communityId: ID!) {
212+ moveArticle(id: $id, communityId: $communityId) {
213+ id
214+ }
215+ }
216+ """
217+ @ tag :wip2
218+ test "auth user can move post to other community" , ~m( post) a do
219+ passport_rules = % { "post.community.mirror" => true }
220+ rule_conn = simu_conn ( :user , cms: passport_rules )
221+
222+ { :ok , community } = db_insert ( :community )
223+ { :ok , community2 } = db_insert ( :community )
224+
225+ variables = % { id: post . id , communityId: community . id }
226+ rule_conn |> mutation_result ( @ mirror_article_query , variables , "mirrorArticle" )
227+ { :ok , found } = ORM . find ( CMS.Post , post . id , preload: [ :original_community , :communities ] )
228+ assoc_communities = found . communities |> Enum . map ( & & 1 . id )
229+ assert community . id in assoc_communities
230+
231+ passport_rules = % { "post.community.move" => true }
232+ rule_conn = simu_conn ( :user , cms: passport_rules )
233+
234+ pre_original_community_id = found . original_community . id
235+
236+ variables = % { id: post . id , communityId: community2 . id }
237+ rule_conn |> mutation_result ( @ move_article_query , variables , "moveArticle" )
238+ { :ok , found } = ORM . find ( CMS.Post , post . id , preload: [ :original_community , :communities ] )
239+ assoc_communities = found . communities |> Enum . map ( & & 1 . id )
240+ assert pre_original_community_id not in assoc_communities
241+ assert community2 . id in assoc_communities
242+ assert community2 . id == found . original_community_id
243+
244+ assert found . original_community . id == community2 . id
245+ end
209246 end
210247end
0 commit comments