@@ -76,6 +76,12 @@ defmodule JSONAPI.QueryParserTest do
76
76
assert filter [ :author ] [ :username ] == "jason"
77
77
end
78
78
79
+ test "parse_filter/2 handles nested filters two deep" do
80
+ config = struct ( Config , opts: [ filter: ~w( author.top_posts.text) ] , view: MyView )
81
+ filter = parse_filter ( config , % { "author.top_posts.text" => "some post" } ) . filter
82
+ assert filter [ :author ] [ :top_posts ] [ :text ] == "some post"
83
+ end
84
+
79
85
test "parse_filter/2 handles nested filters with overlap" do
80
86
config = struct ( Config , opts: [ filter: ~w( author.username author.id) ] , view: MyView )
81
87
filter = parse_filter ( config , % { "author.username" => "jason" , "author.id" => "123" } ) . filter
@@ -97,6 +103,7 @@ defmodule JSONAPI.QueryParserTest do
97
103
assert parse_include ( config , "author" ) . include == [ :author ]
98
104
assert parse_include ( config , "comments,author" ) . include == [ :comments , :author ]
99
105
assert parse_include ( config , "comments.user" ) . include == [ comments: :user ]
106
+ assert parse_include ( config , "comments.user.top_posts" ) . include == [ comments: [ user: :top_posts ] ]
100
107
assert parse_include ( config , "best_friends" ) . include == [ :best_friends ]
101
108
assert parse_include ( config , "author.top-posts" ) . include == [ author: :top_posts ]
102
109
assert parse_include ( config , "" ) . include == [ ]
@@ -108,6 +115,12 @@ defmodule JSONAPI.QueryParserTest do
108
115
assert parse_include ( config , "comments.user" ) . include == [ comments: :user ]
109
116
end
110
117
118
+ test "parse_include/2 succeds given valid twice-nested include specified in allowed list" do
119
+ config = struct ( Config , view: MyView , opts: [ include: ~w( comments.user.top_posts) ] )
120
+
121
+ assert parse_include ( config , "comments.user.top_posts" ) . include == [ comments: [ user: :top_posts ] ]
122
+ end
123
+
111
124
test "parse_include/2 errors with invalid includes" do
112
125
config = struct ( Config , view: MyView )
113
126
0 commit comments