ash_sqlite/test/embeddable_resource_test.exs

35 lines
838 B
Elixir
Raw Permalink Normal View History

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