ash_postgres/test/ash_postgres_test.exs

44 lines
1.1 KiB
Elixir
Raw Normal View History

2019-12-05 03:58:20 +13:00
defmodule AshPostgresTest do
2022-12-01 14:59:18 +13:00
use AshPostgres.RepoCase, async: false
test "transaction metadata is given to on_transaction_begin" do
AshPostgres.Test.Post
|> Ash.Changeset.for_create(:create, %{title: "title"})
|> Ash.create!()
assert_receive %{
type: :create,
metadata: %{action: :create, actor: nil, resource: AshPostgres.Test.Post}
}
end
2024-02-15 07:56:58 +13:00
test "filter policies are applied in create" do
assert_raise Ash.Error.Forbidden, fn ->
AshPostgres.Test.Post
2024-05-17 02:53:19 +12:00
|> Ash.Changeset.for_create(:create, %{title: "worst"}, authorize?: true)
|> Ash.create!()
end
end
test "filter policies are applied in update" do
2024-02-15 07:56:58 +13:00
post =
AshPostgres.Test.Post
|> Ash.Changeset.for_create(:create, %{title: "good"})
|> Ash.create!()
2024-02-15 07:56:58 +13:00
assert_raise Ash.Error.Forbidden, fn ->
post
2024-02-16 04:54:20 +13:00
|> Ash.Changeset.for_update(:update, %{title: "bad"},
authorize?: true,
actor: nil,
2024-02-16 04:54:20 +13:00
actor: %{id: Ash.UUID.generate()}
)
|> Ash.update!(
authorize?: true,
actor: nil
)
|> Map.get(:title)
end
2024-02-15 07:56:58 +13:00
end
2019-10-07 09:36:18 +13:00
end