test: fix test auth and improve reliability
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
- Add admin authentication to all tests - Fix 12 tests that were failing due to missing authentication - 3 tests still have business logic issues (will fix separately)
This commit is contained in:
parent
9a03485604
commit
adc6608e54
4 changed files with 370 additions and 213 deletions
96
test/support/fixtures.ex
Normal file
96
test/support/fixtures.ex
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
defmodule Mv.Fixtures do
|
||||
@moduledoc """
|
||||
Shared test fixtures for consistent test data creation.
|
||||
|
||||
This module provides factory functions for creating test data across
|
||||
different test suites, ensuring consistency and reducing duplication.
|
||||
"""
|
||||
|
||||
@doc """
|
||||
Creates a member with default or custom attributes.
|
||||
|
||||
## Parameters
|
||||
- `attrs` - Map or keyword list of attributes to override defaults
|
||||
|
||||
## Returns
|
||||
- Member struct
|
||||
|
||||
## Examples
|
||||
|
||||
iex> member_fixture()
|
||||
%Mv.Membership.Member{first_name: "Test", ...}
|
||||
|
||||
iex> member_fixture(%{first_name: "Alice", email: "alice@example.com"})
|
||||
%Mv.Membership.Member{first_name: "Alice", email: "alice@example.com"}
|
||||
|
||||
"""
|
||||
def member_fixture(attrs \\ %{}) do
|
||||
attrs
|
||||
|> Enum.into(%{
|
||||
first_name: "Test",
|
||||
last_name: "Member",
|
||||
email: "test#{System.unique_integer([:positive])}@example.com"
|
||||
})
|
||||
|> Mv.Membership.create_member()
|
||||
|> case do
|
||||
{:ok, member} -> member
|
||||
{:error, error} -> raise "Failed to create member: #{inspect(error)}"
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Creates a user with default or custom attributes.
|
||||
|
||||
## Parameters
|
||||
- `attrs` - Map or keyword list of attributes to override defaults
|
||||
|
||||
## Returns
|
||||
- User struct
|
||||
|
||||
## Examples
|
||||
|
||||
iex> user_fixture()
|
||||
%Mv.Accounts.User{email: "user123@example.com"}
|
||||
|
||||
iex> user_fixture(%{email: "custom@example.com"})
|
||||
%Mv.Accounts.User{email: "custom@example.com"}
|
||||
|
||||
"""
|
||||
def user_fixture(attrs \\ %{}) do
|
||||
attrs
|
||||
|> Enum.into(%{
|
||||
email: "user#{System.unique_integer([:positive])}@example.com"
|
||||
})
|
||||
|> Mv.Accounts.create_user()
|
||||
|> case do
|
||||
{:ok, user} -> user
|
||||
{:error, error} -> raise "Failed to create user: #{inspect(error)}"
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Creates a user linked to a member.
|
||||
|
||||
## Parameters
|
||||
- `user_attrs` - Map or keyword list of user attributes
|
||||
- `member_attrs` - Map or keyword list of member attributes
|
||||
|
||||
## Returns
|
||||
- Tuple of {user, member}
|
||||
|
||||
## Examples
|
||||
|
||||
iex> {user, member} = linked_user_member_fixture()
|
||||
iex> user.member_id == member.id
|
||||
true
|
||||
|
||||
"""
|
||||
def linked_user_member_fixture(user_attrs \\ %{}, member_attrs \\ %{}) do
|
||||
member = member_fixture(member_attrs)
|
||||
|
||||
user_attrs = Map.put(user_attrs, :member, %{id: member.id})
|
||||
user = user_fixture(user_attrs)
|
||||
|
||||
{user, member}
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue