Implemented tests for critical security modules with significant coverage improvements: - ApiAuth plug: 0% → 100% (12 tests) - Permissions module: 0% → 85% (32 tests) - Devices API controller: 0% → 95% (22 tests) Enhanced test fixtures to support membership roles and device creation with proper organization scoping.
35 lines
878 B
Elixir
35 lines
878 B
Elixir
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
|