Add actor parameter to all tests requiring authorization
All checks were successful
continuous-integration/drone/push Build is passing

This commit adds actor: system_actor to all Ash operations in tests that
require authorization.
This commit is contained in:
Moritz 2026-01-23 20:00:24 +01:00
parent 4c846f8bba
commit a6cdeaa18d
Signed by: moritz
GPG key ID: 1020A035E5DD0824
75 changed files with 4649 additions and 2865 deletions

View file

@ -7,12 +7,17 @@ defmodule Mv.Authorization.ActorTest do
alias Mv.Accounts
alias Mv.Authorization.Actor
setup do
system_actor = Mv.Helpers.SystemActor.get_system_actor()
%{actor: system_actor}
end
describe "ensure_loaded/1" do
test "returns nil when actor is nil" do
assert Actor.ensure_loaded(nil) == nil
end
test "returns actor as-is when role is already loaded" do
test "returns actor as-is when role is already loaded", %{actor: actor} do
# Create user with role
{:ok, user} =
Accounts.User
@ -20,7 +25,7 @@ defmodule Mv.Authorization.ActorTest do
email: "test#{System.unique_integer([:positive])}@example.com",
password: "testpassword123"
})
|> Ash.create()
|> Ash.create(actor: actor)
# Load role
{:ok, user_with_role} = Ash.load(user, :role, domain: Mv.Accounts)
@ -31,7 +36,7 @@ defmodule Mv.Authorization.ActorTest do
assert result.role != %Ash.NotLoaded{}
end
test "loads role when it's NotLoaded" do
test "loads role when it's NotLoaded", %{actor: actor} do
# Create a role first
{:ok, role} =
Mv.Authorization.Role
@ -40,7 +45,7 @@ defmodule Mv.Authorization.ActorTest do
description: "Test role",
permission_set_name: "own_data"
})
|> Ash.create()
|> Ash.create(actor: actor)
# Create user with role
{:ok, user} =
@ -49,18 +54,18 @@ defmodule Mv.Authorization.ActorTest do
email: "test#{System.unique_integer([:positive])}@example.com",
password: "testpassword123"
})
|> Ash.create()
|> Ash.create(actor: actor)
# Assign role to user
{:ok, user_with_role} =
user
|> Ash.Changeset.for_update(:update, %{})
|> Ash.Changeset.manage_relationship(:role, role, type: :append_and_remove)
|> Ash.update()
|> Ash.update(actor: actor)
# Fetch user again WITHOUT loading role (simulates "role not preloaded" scenario)
{:ok, user_without_role_loaded} =
Ash.get(Accounts.User, user_with_role.id, domain: Mv.Accounts)
Ash.get(Accounts.User, user_with_role.id, domain: Mv.Accounts, actor: actor)
# User has role as NotLoaded (relationship not preloaded)
assert match?(%Ash.NotLoaded{}, user_without_role_loaded.role)