ash_postgres/test/type_test.exs

39 lines
1,012 B
Elixir
Raw Normal View History

defmodule AshPostgres.Test.TypeTest do
use AshPostgres.RepoCase, async: false
alias AshPostgres.Test.Post
require Ash.Query
test "complex custom types can be used" do
post =
Post
|> Ash.Changeset.for_create(:create, %{title: "title", point: {1.0, 2.0, 3.0}})
|> Ash.create!()
assert post.point == {1.0, 2.0, 3.0}
end
test "complex custom types can be accessed with fragments" do
Post
|> Ash.Changeset.for_create(:create, %{title: "title", point: {1.0, 2.0, 3.0}})
|> Ash.create!()
Post
|> Ash.Changeset.for_create(:create, %{title: "title", point: {2.0, 1.0, 3.0}})
|> Ash.create!()
assert [%{point: {2.0, 1.0, 3.0}}] =
Post
|> Ash.Query.filter(fragment("(?)[1] > (?)[2]", point, point))
|> Ash.read!()
end
2022-10-18 02:40:32 +13:00
test "uuids can be used as strings in fragments" do
uuid = Ash.UUID.generate()
Post
|> Ash.Query.filter(fragment("? = ?", id, type(^uuid, :uuid)))
|> Ash.read!()
2022-10-18 02:40:32 +13:00
end
end