add test that shows problem with new auth field clean up (#153)

This commit is contained in:
Barnabas Jovanovics 2024-05-13 14:18:15 +02:00 committed by GitHub
parent beaec883c1
commit 73e6974ea7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 74 additions and 0 deletions

View file

@ -171,6 +171,50 @@ defmodule AliasTest do
} = result
end
test "calculation alias works correctly for forbidden field" do
post =
AshGraphql.Test.Post
|> Ash.Changeset.for_create(:create,
text: "foo",
text1: "hello",
text2: "world",
published: true,
score: 9.8
)
|> Ash.create!()
resp =
"""
query Post($id: ID!) {
getPost(id: $id) {
private_calc: private_calculation {
nestedEmbed {
name
}
}
}
}
"""
|> Absinthe.run(AshGraphql.Test.Schema,
variables: %{
"id" => post.id
}
)
assert {:ok, result} = resp
assert Map.has_key?(result, :errors)
assert %{
errors: [
%{
code: "forbidden_field"
}
]
} =
result
end
test "aggregate alias works correctly" do
post =
AshGraphql.Test.Post

View file

@ -110,6 +110,16 @@ defmodule AshGraphql.Test.Post do
end
end
field_policies do
field_policy :* do
authorize_if(always())
end
field_policy [:private_calculation, :private_attribute] do
forbid_if(always())
end
end
graphql do
type :post
@ -364,6 +374,11 @@ defmodule AshGraphql.Test.Post do
attribute(:embed_union_unnested, AshGraphql.Types.EmbedUnionNewTypeUnnested, public?: true)
attribute(:string_new_type, AshGraphql.Types.StringNewType, public?: true)
attribute(:private_attribute, :boolean) do
default(true)
public?(true)
end
attribute :required_string, :string do
allow_nil? false
default("test")
@ -375,6 +390,21 @@ defmodule AshGraphql.Test.Post do
calculations do
calculate(:static_calculation, :string, AshGraphql.Test.StaticCalculation, public?: true)
calculate(:private_calculation, AshGraphql.Test.Embed, fn records, _ ->
records
|> Enum.map(fn
%{private_attribute: true} ->
%AshGraphql.Test.Embed{}
%{private_attribute: true} ->
nil
end)
end) do
public?(true)
load(:private_attribute)
end
calculate(:full_text, :string, FullTextCalculation, public?: true)
calculate(:text_1_and_2, :string, expr(text1 <> ^arg(:separator) <> text2)) do