@@ -46,6 +46,7 @@ defmodule GroupherServer.Test.Query.PagedArticles.PagedPosts do
46
46
entries {
47
47
id
48
48
communities {
49
+ id
49
50
raw
50
51
}
51
52
articleTags {
@@ -59,7 +60,6 @@ defmodule GroupherServer.Test.Query.PagedArticles.PagedPosts do
59
60
}
60
61
}
61
62
"""
62
-
63
63
test "should get pagination info" , ~m( guest_conn) a do
64
64
variables = % { filter: % { page: 1 , size: 10 } }
65
65
results = guest_conn |> query_result ( @ query , variables , "pagedPosts" )
@@ -70,6 +70,39 @@ defmodule GroupherServer.Test.Query.PagedArticles.PagedPosts do
70
70
assert results [ "entries" ] |> List . first ( ) |> Map . get ( "articleTags" ) |> is_list
71
71
end
72
72
73
+ test "support article_tag filter" , ~m( guest_conn user) a do
74
+ { :ok , community } = db_insert ( :community )
75
+ post_attrs = mock_attrs ( :post , % { community_id: community . id } )
76
+ { :ok , post } = CMS . create_article ( community , :post , post_attrs , user )
77
+
78
+ article_tag_attrs = mock_attrs ( :article_tag )
79
+ { :ok , article_tag } = CMS . create_article_tag ( community , :post , article_tag_attrs , user )
80
+ { :ok , _ } = CMS . set_article_tag ( :post , post . id , article_tag . id )
81
+
82
+ variables = % { filter: % { page: 1 , size: 10 , article_tag: article_tag . title } }
83
+ results = guest_conn |> query_result ( @ query , variables , "pagedPosts" )
84
+
85
+ post = results [ "entries" ] |> List . first ( )
86
+ assert results [ "totalCount" ] == 1
87
+ assert exist_in? ( article_tag , post [ "articleTags" ] , :string_key )
88
+ end
89
+
90
+ test "support community filter" , ~m( guest_conn user) a do
91
+ { :ok , community } = db_insert ( :community )
92
+
93
+ post_attrs = mock_attrs ( :post , % { community_id: community . id } )
94
+ { :ok , _post } = CMS . create_article ( community , :post , post_attrs , user )
95
+ post_attrs2 = mock_attrs ( :post , % { community_id: community . id } )
96
+ { :ok , _post } = CMS . create_article ( community , :post , post_attrs2 , user )
97
+
98
+ variables = % { filter: % { page: 1 , size: 10 , community: community . raw } }
99
+ results = guest_conn |> query_result ( @ query , variables , "pagedPosts" )
100
+
101
+ post = results [ "entries" ] |> List . first ( )
102
+ assert results [ "totalCount" ] == 2
103
+ assert exist_in? ( % { id: to_string ( community . id ) } , post [ "communities" ] , :string_key )
104
+ end
105
+
73
106
test "request large size fails" , ~m( guest_conn) a do
74
107
variables = % { filter: % { page: 1 , size: 200 } }
75
108
assert guest_conn |> query_get_error? ( @ query , variables , ecode ( :pagination ) )
0 commit comments