Add tests for OrganizationsFixtures

- Test unique organization name generation
- Test valid organization attributes
- Test organization creation with defaults and custom attributes
- Test membership creation for organization owner
This commit is contained in:
Graham McIntire 2026-01-13 08:59:40 -06:00
parent 2c35ad457c
commit 7a33fbff66
No known key found for this signature in database

View file

@ -0,0 +1,63 @@
defmodule Towerops.OrganizationsFixturesTest do
use Towerops.DataCase
import Towerops.AccountsFixtures
import Towerops.OrganizationsFixtures
describe "unique_organization_name/0" do
test "generates unique organization names" do
name1 = unique_organization_name()
name2 = unique_organization_name()
assert name1 != name2
assert name1 =~ "Test Org"
assert name2 =~ "Test Org"
end
end
describe "valid_organization_attributes/1" do
test "returns valid organization attributes with default name" do
attrs = valid_organization_attributes()
assert attrs.name =~ "Test Org"
end
test "merges provided attributes" do
attrs = valid_organization_attributes(%{custom_field: "value"})
assert attrs.name =~ "Test Org"
assert attrs.custom_field == "value"
end
test "overrides name if provided" do
custom_name = "My Custom Org"
attrs = valid_organization_attributes(%{name: custom_name})
assert attrs.name == custom_name
end
end
describe "organization_fixture/2" do
test "creates an organization with default attributes" do
user = user_fixture()
organization = organization_fixture(user.id)
assert organization.name =~ "Test Org"
assert organization.slug
end
test "creates an organization with custom attributes" do
user = user_fixture()
custom_name = "Custom Organization"
organization = organization_fixture(user.id, %{name: custom_name})
assert organization.name == custom_name
end
test "creates membership for user" do
user = user_fixture()
organization = organization_fixture(user.id)
membership = Towerops.Organizations.get_membership(organization.id, user.id)
assert membership
assert membership.role == :owner
end
end
end