I have written the following test.
test "list_users/1 returns all users in a tenant", %{tenant: tenant} do
user = insert(:user, tenant: tenant)
user_2 = insert(:user, tenant: tenant)
assert Accounts.list_users(tenant) == [user_2, user]
end
I'm testing if i get all the users back within a tenant, to do that, i need to assign my factories the tenant, that i want to test against. The problem is that, when i assign the user the tenant, the association is now loaded. The returned users, does not, hence the test fails with the following diff..
tenant: #Ecto.Association.NotLoaded<association :tenant is not loaded>
vs
tenant: %MyApp.Accounts.Tenant{__meta__: #Ecto.Schema.Metadata<:loaded, "tenants">, domain: "pharma-13", id: 484, inserted_at: ~N[2017-06-14 15:10:42.125243], logo: "some_logo_path.png", name: "Pharma", updated_at: ~N[2017-06-14 15:10:42.125250]
Should i somehow unload the associations? I certainly don't want add preload to my function, just in order to pass the test.
map
both sides of assertion to obtainID
s, and I'm comparing those – Lindeberg