@@ -6,6 +6,8 @@ defmodule GroupherServer.Test.Mutation.Articles.Blog do
66
77 alias CMS.Model.Blog
88
9+ @ rss mock_rss_addr ( )
10+
911 setup do
1012 { :ok , user } = db_insert ( :user )
1113 { :ok , community } = db_insert ( :community )
@@ -24,18 +26,19 @@ defmodule GroupherServer.Test.Mutation.Articles.Blog do
2426 @ create_blog_query """
2527 mutation (
2628 $title: String!,
27- $body : String,
29+ $rss : String! ,
2830 $communityId: ID!,
2931 $articleTags: [Id]
3032 ) {
3133 createBlog(
3234 title: $title,
33- body : $body ,
35+ rss : $rss ,
3436 communityId: $communityId,
3537 articleTags: $articleTags
3638 ) {
3739 id
3840 title
41+ digest
3942 document {
4043 bodyHtml
4144 }
@@ -49,13 +52,14 @@ defmodule GroupherServer.Test.Mutation.Articles.Blog do
4952 }
5053 }
5154 """
55+ @ tag :wip
5256 test "create blog with valid attrs and make sure author exsit" do
5357 { :ok , user } = db_insert ( :user )
5458 user_conn = simu_conn ( :user , user )
5559
5660 { :ok , community } = db_insert ( :community )
57- blog_attr = mock_attrs ( :blog )
58-
61+ blog_attr = mock_attrs ( :blog ) |> Map . merge ( % { rss: @ rss } )
62+ # IO.inspect(blog_attr, label: "# blog_attr -> ")
5963 variables = blog_attr |> Map . merge ( % { communityId: community . id } ) |> camelize_map_key
6064
6165 created = user_conn |> mutation_result ( @ create_blog_query , variables , "createBlog" )
@@ -64,10 +68,26 @@ defmodule GroupherServer.Test.Mutation.Articles.Blog do
6468
6569 assert created [ "id" ] == to_string ( found . id )
6670 assert created [ "originalCommunity" ] [ "id" ] == to_string ( community . id )
67-
6871 assert created [ "id" ] == to_string ( found . id )
6972 end
7073
74+ @ tag :wip
75+ test "create blog with non-exsit title fails" do
76+ { :ok , user } = db_insert ( :user )
77+ user_conn = simu_conn ( :user , user )
78+
79+ { :ok , community } = db_insert ( :community )
80+ blog_attr = mock_attrs ( :blog ) |> Map . merge ( % { rss: @ rss } )
81+
82+ variables =
83+ blog_attr
84+ |> Map . merge ( % { communityId: community . id , title: "non-exsit" } )
85+ |> camelize_map_key
86+
87+ assert user_conn
88+ |> mutation_get_error? ( @ create_blog_query , variables , ecode ( :invalid_blog_title ) )
89+ end
90+
7191 test "create blog with valid tags id list" , ~m( user_conn user community) a do
7292 article_tag_attrs = mock_attrs ( :article_tag )
7393 { :ok , article_tag } = CMS . create_article_tag ( community , :blog , article_tag_attrs , user )
@@ -99,100 +119,20 @@ defmodule GroupherServer.Test.Mutation.Articles.Blog do
99119 assert not String . contains? ( body_html , "script" )
100120 end
101121
102- test "create blog should excape xss attracts 2" do
103- { :ok , user } = db_insert ( :user )
104- user_conn = simu_conn ( :user , user )
105-
106- { :ok , community } = db_insert ( :community )
107-
108- blog_attr = mock_attrs ( :blog , % { body: mock_xss_string ( :safe ) } )
109- variables = blog_attr |> Map . merge ( % { communityId: community . id } ) |> camelize_map_key
110- result = user_conn |> mutation_result ( @ create_blog_query , variables , "createBlog" )
111- { :ok , blog } = ORM . find ( Blog , result [ "id" ] , preload: :document )
112- body_html = blog |> get_in ( [ :document , :body_html ] )
113-
114- assert String . contains? ( body_html , "<script>blackmail</script>" )
115- end
116-
117- @ query """
118- mutation($id: ID!, $title: String, $body: String, $articleTags: [Ids]){
119- updateBlog(id: $id, title: $title, body: $body, articleTags: $articleTags) {
120- id
121- title
122- document {
123- bodyHtml
124- }
125- articleTags {
126- id
127- }
128- }
129- }
130- """
131- test "update a blog without login user fails" , ~m( guest_conn blog) a do
132- unique_num = System . unique_integer ( [ :positive , :monotonic ] )
133-
134- variables = % {
135- id: blog . id ,
136- title: "updated title #{ unique_num } " ,
137- body: mock_rich_text ( "updated body #{ unique_num } " )
138- }
139-
140- assert guest_conn |> mutation_get_error? ( @ query , variables , ecode ( :account_login ) )
141- end
142-
143- test "blog can be update by owner" , ~m( owner_conn blog) a do
144- unique_num = System . unique_integer ( [ :positive , :monotonic ] )
145-
146- variables = % {
147- id: blog . id ,
148- title: "updated title #{ unique_num } " ,
149- body: mock_rich_text ( "updated body #{ unique_num } " )
150- }
122+ # test "create blog should excape xss attracts" do
123+ # {:ok, user} = db_insert(:user)
124+ # user_conn = simu_conn(:user, user)
151125
152- result = owner_conn |> mutation_result ( @ query , variables , "updateBlog" )
126+ # {:ok, community} = db_insert(:community )
153127
154- assert result [ "title" ] == variables . title
128+ # blog_attr = mock_attrs(:blog, %{body: mock_xss_string(:safe)})
129+ # variables = blog_attr |> Map.merge(%{communityId: community.id}) |> camelize_map_key
130+ # result = user_conn |> mutation_result(@create_blog_query, variables, "createBlog")
131+ # {:ok, blog} = ORM.find(Blog, result["id"], preload: :document)
132+ # body_html = blog |> get_in([:document, :body_html])
155133
156- assert result
157- |> get_in ( [ "document" , "bodyHtml" ] )
158- |> String . contains? ( ~s( updated body #{ unique_num } ) )
159- end
160-
161- test "login user with auth passport update a blog" , ~m( blog) a do
162- blog = blog |> Repo . preload ( :communities )
163-
164- blog_communities_0 = blog . communities |> List . first ( ) |> Map . get ( :title )
165- passport_rules = % { blog_communities_0 => % { "blog.edit" => true } }
166- rule_conn = simu_conn ( :user , cms: passport_rules )
167-
168- unique_num = System . unique_integer ( [ :positive , :monotonic ] )
169-
170- variables = % {
171- id: blog . id ,
172- title: "updated title #{ unique_num } " ,
173- body: mock_rich_text ( "updated body #{ unique_num } " )
174- }
175-
176- updated = rule_conn |> mutation_result ( @ query , variables , "updateBlog" )
177-
178- assert updated [ "id" ] == to_string ( blog . id )
179- end
180-
181- test "unauth user update blog fails" , ~m( user_conn guest_conn blog) a do
182- unique_num = System . unique_integer ( [ :positive , :monotonic ] )
183-
184- variables = % {
185- id: blog . id ,
186- title: "updated title #{ unique_num } " ,
187- body: mock_rich_text ( "updated body #{ unique_num } " )
188- }
189-
190- rule_conn = simu_conn ( :user , cms: % { "what.ever" => true } )
191-
192- assert user_conn |> mutation_get_error? ( @ query , variables , ecode ( :passport ) )
193- assert guest_conn |> mutation_get_error? ( @ query , variables , ecode ( :account_login ) )
194- assert rule_conn |> mutation_get_error? ( @ query , variables , ecode ( :passport ) )
195- end
134+ # assert String.contains?(body_html, "<script>blackmail</script>")
135+ # end
196136
197137 @ query """
198138 mutation($id: ID!){
0 commit comments