ash_postgres/test/embeddable_resource_test.exs
Zach Daniel 37cc01957d
improvement!: 3.0 (#227)
* WIP

* chore: fix mix.lock merge issues

* improvement: upgrade to 3.0

* chore: remove `repo.to_tenant`

* chore: continue removal of unnecessary helper

* chore: use `Ash.ToTenant`
2024-03-27 16:52:28 -04:00

34 lines
856 B
Elixir

defmodule AshPostgres.EmbeddableResourceTest do
@moduledoc false
use AshPostgres.RepoCase, async: false
alias AshPostgres.Test.{Author, Bio, Post}
require Ash.Query
setup do
post =
Post
|> Ash.Changeset.for_create(:create, %{title: "title"})
|> Ash.create!()
%{post: post}
end
test "calculations can load json", %{post: post} do
assert %{calc_returning_json: %AshPostgres.Test.Money{amount: 100, currency: :usd}} =
Ash.load!(post, :calc_returning_json)
end
test "embeds with list attributes set to nil are loaded as nil" do
author =
Author
|> Ash.Changeset.for_create(:create, %{bio: %Bio{list_of_strings: nil}})
|> Ash.create!()
assert is_nil(author.bio.list_of_strings)
author = Ash.reload!(author)
assert is_nil(author.bio.list_of_strings)
end
end