Skip to content

Commit b022659

Browse files
committed
Add requested more deeply nested tests
1 parent 9c5aa26 commit b022659

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

test/jsonapi/plugs/query_parser_test.exs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ defmodule JSONAPI.QueryParserTest do
7676
assert filter[:author][:username] == "jason"
7777
end
7878

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+
7985
test "parse_filter/2 handles nested filters with overlap" do
8086
config = struct(Config, opts: [filter: ~w(author.username author.id)], view: MyView)
8187
filter = parse_filter(config, %{"author.username" => "jason", "author.id" => "123"}).filter
@@ -97,6 +103,7 @@ defmodule JSONAPI.QueryParserTest do
97103
assert parse_include(config, "author").include == [:author]
98104
assert parse_include(config, "comments,author").include == [:comments, :author]
99105
assert parse_include(config, "comments.user").include == [comments: :user]
106+
assert parse_include(config, "comments.user.top_posts").include == [comments: [user: :top_posts]]
100107
assert parse_include(config, "best_friends").include == [:best_friends]
101108
assert parse_include(config, "author.top-posts").include == [author: :top_posts]
102109
assert parse_include(config, "").include == []
@@ -108,6 +115,12 @@ defmodule JSONAPI.QueryParserTest do
108115
assert parse_include(config, "comments.user").include == [comments: :user]
109116
end
110117

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+
111124
test "parse_include/2 errors with invalid includes" do
112125
config = struct(Config, view: MyView)
113126

0 commit comments

Comments
 (0)