Skip to content

Commit

Permalink
chore: add failing test for nested error rendering (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
rbino authored Apr 5, 2024
1 parent c954da8 commit 73863a0
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion test/acceptance/post_test.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
defmodule Test.Acceptance.PostTest do
use ExUnit.Case, async: true

defmodule Review do
use Ash.Resource,
domain: Test.Acceptance.PostTest.Domain,
data_layer: :embedded

actions do
default_accept(:*)
defaults([:read, :create, :update, :destroy])
end

attributes do
attribute(:reviewer, :string, public?: true)
attribute(:rating, :integer, public?: true)
end
end

defmodule Author do
use Ash.Resource,
domain: Test.Acceptance.PostTest.Domain,
Expand Down Expand Up @@ -87,7 +103,7 @@ defmodule Test.Acceptance.PostTest do

create :create do
primary? true
accept([:id, :name, :hidden])
accept([:id, :name, :hidden, :review])

argument(:author, :map)

Expand Down Expand Up @@ -115,6 +131,8 @@ defmodule Test.Acceptance.PostTest do
match: ~r/[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/
]
)

attribute(:review, Test.Acceptance.PostTest.Review, public?: true)
end

relationships do
Expand Down Expand Up @@ -190,6 +208,31 @@ defmodule Test.Acceptance.PostTest do
|> assert_attribute_equals("email", nil)
|> assert_attribute_equals("name_twice", "Post 1-Post 1")
end

test "nested errors have the correct source pointer" do

Check failure on line 212 in test/acceptance/post_test.exs

View workflow job for this annotation

GitHub Actions / ash-ci / mix test

test post nested errors have the correct source pointer (Test.Acceptance.PostTest)
id = Ecto.UUID.generate()

response =
Domain
|> post("/posts", %{
data: %{
type: "post",
attributes: %{
id: id,
name: "Hello",
review: %{
reviewer: "foo",
rating: "bar"
}
}
}
})

# response is a Plug.
assert %{"errors" => [error]} = response.resp_body
assert error["code"] == "invalid_attribute"
assert error["source"] == %{"pointer" => "/data/attributes/review/rating"}
end
end

describe "post with upsert" do
Expand Down

0 comments on commit 73863a0

Please sign in to comment.