ash_postgres/test/bulk_destroy_test.exs
Zach Daniel b018262637 test: add new test verifying batch destroy behavior
chore: add sobelow warning skip
2024-02-01 13:09:06 -05:00

40 lines
1 KiB
Elixir

defmodule AshPostgres.BulkDestroyTest do
use AshPostgres.RepoCase, async: false
alias AshPostgres.Test.{Api, Post}
require Ash.Expr
require Ash.Query
test "bulk destroys can run with nothing in the table" do
Api.bulk_destroy!(Post, :update, %{title: "new_title"})
end
test "bulk destroys destroy everything pertaining to the query" do
Api.bulk_create!([%{title: "fred"}, %{title: "george"}], Post, :create)
Api.bulk_destroy!(Post, :update, %{})
assert Api.read!(Post) == []
end
test "bulk destroys only apply to things that the query produces" do
Api.bulk_create!([%{title: "fred"}, %{title: "george"}], Post, :create)
Post
|> Ash.Query.filter(title == "fred")
|> Api.bulk_destroy!(:update, %{})
# 😢 sad
assert [%{title: "george"}] = Api.read!(Post)
end
test "bulk destroys can be done even on stream inputs" do
Api.bulk_create!([%{title: "fred"}, %{title: "george"}], Post, :create)
Post
|> Api.read!()
|> Api.bulk_destroy!(:destroy, %{})
assert [] = Api.read!(Post)
end
end