diff --git a/test/support/fixtures/organizations_fixtures_test.exs b/test/support/fixtures/organizations_fixtures_test.exs new file mode 100644 index 00000000..d7ce304f --- /dev/null +++ b/test/support/fixtures/organizations_fixtures_test.exs @@ -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