How to compare a seed and loaded resource?

I thought strip_metadata() would make the comparable
user = Ash.Seed.seed!(%User{...})
loaded_user = User.get_by_id!(user.id) |> Ash.Test.strip_metadata()
assert loaded_user == user

Assertion with == failed
code: assert loaded_user == user
left: #Iterup.Accounts.User<account: #Ash.NotLoaded<:relationship>, __meta__: #Ecto.Schema.Metadata<>, id: "d4a9ed2e-cfae-4b18-b2a2-d07a0d426854", email: #Ash.CiString<"[email protected]">, name: "Mohammad Abshire", avatar_path: nil, confirmed_at: nil, inserted_at: ~U[2023-04-21 15:49:04.534852Z], updated_at: ~U[2023-04-21 15:49:04.534852Z], account_id: "eeb36be1-a423-4569-81ac-c1256de4fda3", aggregates: %{}, calculations: %{}, __order__: nil, ...>
right: #Iterup.Accounts.User<account: #Iterup.Accounts.Account<users: #Ash.NotLoaded<:relationship>, invites: #Ash.NotLoaded<:relationship>, __meta__: #Ecto.Schema.Metadata<:loaded, "accounts">, id: "eeb36be1-a423-4569-81ac-c1256de4fda3", name: "Leffler-Connelly", slug: "leffler-connelly", inserted_at: ~U[2023-04-21 15:49:04.375199Z], updated_at: ~U[2023-04-21 15:49:04.375199Z], aggregates: %{}, calculations: %{}, __order__: nil, ...>, __meta__: #Ecto.Schema.Metadata<:loaded, "users">, id: "d4a9ed2e-cfae-4b18-b2a2-d07a0d426854", email: "[email protected]", name: "Mohammad Abshire", avatar_path: nil, confirmed_at: nil, inserted_at: ~U[2023-04-21 15:49:04.534852Z], updated_at: ~U[2023-04-21 15:49:04.534852Z], account_id: "eeb36be1-a423-4569-81ac-c1256de4fda3", aggregates: %{}, calculations: %{}, __order__: nil, ...>
user = Ash.Seed.seed!(%User{...})
loaded_user = User.get_by_id!(user.id) |> Ash.Test.strip_metadata()
assert loaded_user == user

Assertion with == failed
code: assert loaded_user == user
left: #Iterup.Accounts.User<account: #Ash.NotLoaded<:relationship>, __meta__: #Ecto.Schema.Metadata<>, id: "d4a9ed2e-cfae-4b18-b2a2-d07a0d426854", email: #Ash.CiString<"[email protected]">, name: "Mohammad Abshire", avatar_path: nil, confirmed_at: nil, inserted_at: ~U[2023-04-21 15:49:04.534852Z], updated_at: ~U[2023-04-21 15:49:04.534852Z], account_id: "eeb36be1-a423-4569-81ac-c1256de4fda3", aggregates: %{}, calculations: %{}, __order__: nil, ...>
right: #Iterup.Accounts.User<account: #Iterup.Accounts.Account<users: #Ash.NotLoaded<:relationship>, invites: #Ash.NotLoaded<:relationship>, __meta__: #Ecto.Schema.Metadata<:loaded, "accounts">, id: "eeb36be1-a423-4569-81ac-c1256de4fda3", name: "Leffler-Connelly", slug: "leffler-connelly", inserted_at: ~U[2023-04-21 15:49:04.375199Z], updated_at: ~U[2023-04-21 15:49:04.375199Z], aggregates: %{}, calculations: %{}, __order__: nil, ...>, __meta__: #Ecto.Schema.Metadata<:loaded, "users">, id: "d4a9ed2e-cfae-4b18-b2a2-d07a0d426854", email: "[email protected]", name: "Mohammad Abshire", avatar_path: nil, confirmed_at: nil, inserted_at: ~U[2023-04-21 15:49:04.534852Z], updated_at: ~U[2023-04-21 15:49:04.534852Z], account_id: "eeb36be1-a423-4569-81ac-c1256de4fda3", aggregates: %{}, calculations: %{}, __order__: nil, ...>
Are there any showcase apps that have some good example test suites?
3 Replies
ZachDaniel
ZachDaniel3y ago
It looks like the one on the right has some data loaded i.e invites Generally speaking, it is probably better to pick specific things you want to assert equality on like assert Map.take(record1, [:foo, bar]) == Map.take(record2, [:foo, :bar])
Robert Graff
Robert GraffOP3y ago
Thanks @Zach Daniel testing tag might be useful
ZachDaniel
ZachDaniel3y ago
Added

Did you find this page helpful?