Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tenant <-> realm relationship #431

Open
szakhlypa opened this issue Jan 18, 2024 · 0 comments
Open

Tenant <-> realm relationship #431

szakhlypa opened this issue Jan 18, 2024 · 0 comments

Comments

@szakhlypa
Copy link
Contributor

The Tenant schema uses the has_one :realm, Realm relationship, but Edgehog allows to create a few realms associated with the same tenant.

test "create_realm/2 allows to create few realms in the same tenant", %{tenant: tenant, cluster: cluster} do
  realm1 = Edgehog.AstarteFixtures.realm_fixture(cluster, name: "realm1")

  valid_attrs = %{name: "realm2", private_key: @valid_private_key}
  assert {:ok, %Realm{} = realm2} = Edgehog.Astarte.create_realm(cluster, valid_attrs)

  tenant = Edgehog.Tenants.preload_astarte_resources_for_tenant(tenant)
  
  # 2 realms are associated with tenant
  assert [realm1, realm2] == Edgehog.Astarte.list_realms()
  # tenant returns only one realm
  assert tenant.realm == Edgehog.Repo.preload(realm1, [:cluster], skip_tenant_id: true) 
end

Also, if there are multiple realms associated with the same tenant, the reconciliation and cleanup after delete tasks will only use one realm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant