ash_postgres/test/side_load_test.exs
Zach Daniel 7f8aa98f24 improvement: better errors for multitenant unique constraints
fix: un-break the `in` filter type casting code

test: add tests for untested features
2021-01-26 15:07:26 -05:00

46 lines
1.2 KiB
Elixir

defmodule AshPostgres.Test.SideLoadTest do
use AshPostgres.RepoCase, async: false
alias AshPostgres.Test.{Api, Comment, Post}
require Ash.Query
test "has_many relationships can be loaded" do
assert %Post{comments: %Ash.NotLoaded{type: :relationship}} =
post =
Post
|> Ash.Changeset.new(%{title: "title"})
|> Api.create!()
Comment
|> Ash.Changeset.new(%{title: "match"})
|> Ash.Changeset.replace_relationship(:post, post)
|> Api.create!()
results =
Post
|> Ash.Query.load(:comments)
|> Api.read!()
assert [%Post{comments: [%{title: "match"}]}] = results
end
test "belongs_to relationships can be loaded" do
assert %Comment{post: %Ash.NotLoaded{type: :relationship}} =
comment =
Comment
|> Ash.Changeset.new(%{})
|> Api.create!()
Post
|> Ash.Changeset.new(%{title: "match"})
|> Ash.Changeset.replace_relationship(:comments, [comment])
|> Api.create!()
results =
Comment
|> Ash.Query.load(:post)
|> Api.read!()
assert [%Comment{post: %{title: "match"}}] = results
end
end