2019-12-05 03:58:20 +13:00
|
|
|
defmodule AshPostgresTest do
|
2022-12-01 14:59:18 +13:00
|
|
|
use AshPostgres.RepoCase, async: false
|
2022-12-01 14:51:06 +13:00
|
|
|
|
|
|
|
test "transaction metadata is given to on_transaction_begin" do
|
|
|
|
AshPostgres.Test.Post
|
2024-03-28 09:52:28 +13:00
|
|
|
|> Ash.Changeset.for_create(:create, %{title: "title"})
|
|
|
|
|> Ash.create!()
|
2022-12-01 14:51:06 +13:00
|
|
|
|
|
|
|
assert_receive %{
|
|
|
|
type: :create,
|
|
|
|
metadata: %{action: :create, actor: nil, resource: AshPostgres.Test.Post}
|
|
|
|
}
|
|
|
|
end
|
2024-02-15 07:56:58 +13:00
|
|
|
|
2024-05-17 01:39:47 +12: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)
|
2024-05-17 01:39:47 +12:00
|
|
|
|> Ash.create!()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test "filter policies are applied in update" do
|
2024-02-15 07:56:58 +13:00
|
|
|
post =
|
|
|
|
AshPostgres.Test.Post
|
2024-03-28 09:52:28 +13:00
|
|
|
|> Ash.Changeset.for_create(:create, %{title: "good"})
|
|
|
|
|> Ash.create!()
|
2024-02-15 07:56:58 +13:00
|
|
|
|
2024-02-15 11:54:28 +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,
|
2024-04-02 06:58:44 +13:00
|
|
|
actor: nil,
|
2024-02-16 04:54:20 +13:00
|
|
|
actor: %{id: Ash.UUID.generate()}
|
|
|
|
)
|
2024-04-02 06:58:44 +13:00
|
|
|
|> Ash.update!(
|
|
|
|
authorize?: true,
|
|
|
|
actor: nil
|
|
|
|
)
|
2024-02-15 11:54:28 +13:00
|
|
|
|> Map.get(:title)
|
|
|
|
end
|
2024-02-15 07:56:58 +13:00
|
|
|
end
|
2019-10-07 09:36:18 +13:00
|
|
|
end
|