defmodule Towerops.OrganizationsFixtures do
  @moduledoc """
  This module defines test helpers for creating
  entities via the `Towerops.Organizations` context.
  """

  alias Towerops.Organizations

  def unique_organization_name, do: "Test Org #{System.unique_integer()}"

  def valid_organization_attributes(attrs \\ %{}) do
    Enum.into(attrs, %{
      name: unique_organization_name()
    })
  end

  def organization_fixture(user_id, attrs \\ %{}) do
    attrs = valid_organization_attributes(attrs)

    {:ok, organization} = Organizations.create_organization(attrs, user_id, bypass_limits: true)

    organization
  end

  def membership_fixture(organization_id, user_id, role) do
    {:ok, membership} =
      Organizations.create_membership(%{
        organization_id: organization_id,
        user_id: user_id,
        role: role
      })

    membership
  end
end
