add another test case with 2 relationships

This commit is contained in:
Barnabas Jovanovics 2024-02-14 14:17:05 +01:00
parent a3d0fa3ffd
commit 0f614aea15

View file

@ -1,7 +1,7 @@
defmodule FilterFieldPolicyTest do defmodule FilterFieldPolicyTest do
use AshPostgres.RepoCase, async: false use AshPostgres.RepoCase, async: false
alias AshPostgres.Test.{Api, Post, Organization} alias AshPostgres.Test.{Api, Post, Organization, User}
require Ash.Query require Ash.Query
@ -36,6 +36,10 @@ defmodule FilterFieldPolicyTest do
|> Ash.Changeset.for_create(:create, %{name: "test_org"}) |> Ash.Changeset.for_create(:create, %{name: "test_org"})
|> Api.create!() |> Api.create!()
User
|> Ash.Changeset.for_create(:create, %{organization_id: organization.id, name: "foo bar"})
|> Api.create!()
Post Post
|> Ash.Changeset.for_create(:create, %{organization_id: organization.id}) |> Ash.Changeset.for_create(:create, %{organization_id: organization.id})
|> Api.create!() |> Api.create!()
@ -46,6 +50,14 @@ defmodule FilterFieldPolicyTest do
Post Post
|> Ash.Query.do_filter(filter) |> Ash.Query.do_filter(filter)
|> Ash.Query.for_read(:allow_any) |> Ash.Query.for_read(:allow_any)
|> Api.read!(actor: %{id: "%test"}) |> Api.read!(actor: %{id: "test"})
filter = Ash.Filter.parse_input!(Post, %{organization: %{users: %{name: %{ilike: "%bar"}}}})
assert [_] =
Post
|> Ash.Query.do_filter(filter)
|> Ash.Query.for_read(:allow_any)
|> Api.read!(actor: %{id: "test"})
end end
end end