@@ -6,6 +6,8 @@ defmodule GroupherServer.Test.Mutation.Articles.Blog do
6
6
7
7
alias CMS.Model.Blog
8
8
9
+ @ rss mock_rss_addr ( )
10
+
9
11
setup do
10
12
{ :ok , user } = db_insert ( :user )
11
13
{ :ok , community } = db_insert ( :community )
@@ -24,18 +26,19 @@ defmodule GroupherServer.Test.Mutation.Articles.Blog do
24
26
@ create_blog_query """
25
27
mutation (
26
28
$title: String!,
27
- $body : String,
29
+ $rss : String! ,
28
30
$communityId: ID!,
29
31
$articleTags: [Id]
30
32
) {
31
33
createBlog(
32
34
title: $title,
33
- body : $body ,
35
+ rss : $rss ,
34
36
communityId: $communityId,
35
37
articleTags: $articleTags
36
38
) {
37
39
id
38
40
title
41
+ digest
39
42
document {
40
43
bodyHtml
41
44
}
@@ -49,13 +52,14 @@ defmodule GroupherServer.Test.Mutation.Articles.Blog do
49
52
}
50
53
}
51
54
"""
55
+ @ tag :wip
52
56
test "create blog with valid attrs and make sure author exsit" do
53
57
{ :ok , user } = db_insert ( :user )
54
58
user_conn = simu_conn ( :user , user )
55
59
56
60
{ :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 -> ")
59
63
variables = blog_attr |> Map . merge ( % { communityId: community . id } ) |> camelize_map_key
60
64
61
65
created = user_conn |> mutation_result ( @ create_blog_query , variables , "createBlog" )
@@ -64,10 +68,26 @@ defmodule GroupherServer.Test.Mutation.Articles.Blog do
64
68
65
69
assert created [ "id" ] == to_string ( found . id )
66
70
assert created [ "originalCommunity" ] [ "id" ] == to_string ( community . id )
67
-
68
71
assert created [ "id" ] == to_string ( found . id )
69
72
end
70
73
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
+
71
91
test "create blog with valid tags id list" , ~m( user_conn user community) a do
72
92
article_tag_attrs = mock_attrs ( :article_tag )
73
93
{ :ok , article_tag } = CMS . create_article_tag ( community , :blog , article_tag_attrs , user )
@@ -99,100 +119,20 @@ defmodule GroupherServer.Test.Mutation.Articles.Blog do
99
119
assert not String . contains? ( body_html , "script" )
100
120
end
101
121
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)
151
125
152
- result = owner_conn |> mutation_result ( @ query , variables , "updateBlog" )
126
+ # {:ok, community} = db_insert(:community )
153
127
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])
155
133
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
196
136
197
137
@ query """
198
138
mutation($id: ID!){
0 commit comments