towerops/test/support/fixtures/organizations_fixtures_test.exs
2026-06-15 11:15:46 -05:00

61 lines
1.8 KiB
Elixir

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)
assert %{role: :owner} = Towerops.Organizations.get_membership(organization.id, user.id)
end
end
end