mirror of
https://github.com/ash-project/ash_postgres.git
synced 2024-09-20 05:23:18 +12:00
e8643d4aa0
chore: update tests not to use deprecated helper
62 lines
1.9 KiB
Elixir
62 lines
1.9 KiB
Elixir
defmodule AshPostgres.SchemaTest do
|
|
@moduledoc false
|
|
use AshPostgres.RepoCase, async: false
|
|
alias AshPostgres.Test.{Api, Author, Profile}
|
|
|
|
require Ash.Query
|
|
|
|
setup do
|
|
[author: Api.create!(Ash.Changeset.for_create(Author, :create, %{}))]
|
|
end
|
|
|
|
test "data can be created", %{author: author} do
|
|
assert %{description: "foo"} =
|
|
Profile
|
|
|> Ash.Changeset.for_create(:create, %{description: "foo"})
|
|
|> Ash.Changeset.manage_relationship(:author, author, type: :append_and_remove)
|
|
|> Api.create!()
|
|
end
|
|
|
|
test "data can be read", %{author: author} do
|
|
Profile
|
|
|> Ash.Changeset.for_create(:create, %{description: "foo"})
|
|
|> Ash.Changeset.manage_relationship(:author, author, type: :append_and_remove)
|
|
|> Api.create!()
|
|
|
|
assert [%{description: "foo"}] = Profile |> Api.read!()
|
|
end
|
|
|
|
test "they can be filtered across", %{author: author} do
|
|
profile =
|
|
Profile
|
|
|> Ash.Changeset.for_create(:create, %{description: "foo"})
|
|
|> Ash.Changeset.manage_relationship(:author, author, type: :append_and_remove)
|
|
|> Api.create!()
|
|
|
|
Api.create!(Ash.Changeset.for_create(Author, :create, %{}))
|
|
|
|
assert [_] =
|
|
Author
|
|
|> Ash.Query.filter(profile.id == ^profile.id)
|
|
|> Api.read!()
|
|
|
|
assert [_] =
|
|
Profile
|
|
|> Ash.Query.filter(author.id == ^author.id)
|
|
|> Api.read!()
|
|
end
|
|
|
|
test "aggregates work across schemas", %{author: author} do
|
|
Profile
|
|
|> Ash.Changeset.for_create(:create, %{description: "foo"})
|
|
|> Ash.Changeset.manage_relationship(:author, author, type: :append_and_remove)
|
|
|> Api.create!()
|
|
|
|
assert [%{profile_description: "foo"}] =
|
|
Author
|
|
|> Ash.Query.filter(profile_description == "foo")
|
|
|> Api.read!()
|
|
|
|
assert %{profile_description: "foo"} = Api.load!(author, :profile_description)
|
|
end
|
|
end
|