Add actor parameter to all tests requiring authorization
All checks were successful
continuous-integration/drone/push Build is passing
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:
parent
4c846f8bba
commit
a6cdeaa18d
75 changed files with 4649 additions and 2865 deletions
|
|
@ -19,6 +19,8 @@ defmodule MvWeb.CustomFieldLive.DeletionTest do
|
|||
alias Mv.Membership.{CustomField, CustomFieldValue, Member}
|
||||
|
||||
setup do
|
||||
system_actor = Mv.Helpers.SystemActor.get_system_actor()
|
||||
|
||||
# Create admin user for testing
|
||||
{:ok, user} =
|
||||
Mv.Accounts.User
|
||||
|
|
@ -26,7 +28,7 @@ defmodule MvWeb.CustomFieldLive.DeletionTest do
|
|||
email: "admin#{System.unique_integer([:positive])}@mv.local",
|
||||
password: "testpassword123"
|
||||
})
|
||||
|> Ash.create()
|
||||
|> Ash.create(actor: system_actor)
|
||||
|
||||
conn = log_in_user(build_conn(), user)
|
||||
%{conn: conn, user: user}
|
||||
|
|
@ -156,14 +158,16 @@ defmodule MvWeb.CustomFieldLive.DeletionTest do
|
|||
# Should show success message
|
||||
assert render(view) =~ "Data field deleted successfully"
|
||||
|
||||
system_actor = Mv.Helpers.SystemActor.get_system_actor()
|
||||
|
||||
# Custom field should be gone from database
|
||||
assert {:error, _} = Ash.get(CustomField, custom_field.id)
|
||||
assert {:error, _} = Ash.get(CustomField, custom_field.id, actor: system_actor)
|
||||
|
||||
# Custom field value should also be gone (CASCADE)
|
||||
assert {:error, _} = Ash.get(CustomFieldValue, custom_field_value.id)
|
||||
assert {:error, _} = Ash.get(CustomFieldValue, custom_field_value.id, actor: system_actor)
|
||||
|
||||
# Member should still exist
|
||||
assert {:ok, _} = Ash.get(Member, member.id)
|
||||
assert {:ok, _} = Ash.get(Member, member.id, actor: system_actor)
|
||||
end
|
||||
|
||||
test "button remains disabled and custom field not deleted when slug doesn't match", %{
|
||||
|
|
@ -188,7 +192,8 @@ defmodule MvWeb.CustomFieldLive.DeletionTest do
|
|||
assert html =~ ~r/disabled(?:=""|(?!\w))/
|
||||
|
||||
# Custom field should still exist since deletion couldn't proceed
|
||||
assert {:ok, _} = Ash.get(CustomField, custom_field.id)
|
||||
system_actor = Mv.Helpers.SystemActor.get_system_actor()
|
||||
assert {:ok, _} = Ash.get(CustomField, custom_field.id, actor: system_actor)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -214,38 +219,45 @@ defmodule MvWeb.CustomFieldLive.DeletionTest do
|
|||
refute has_element?(view, "#delete-custom-field-modal")
|
||||
|
||||
# Custom field should still exist
|
||||
assert {:ok, _} = Ash.get(CustomField, custom_field.id)
|
||||
system_actor = Mv.Helpers.SystemActor.get_system_actor()
|
||||
assert {:ok, _} = Ash.get(CustomField, custom_field.id, actor: system_actor)
|
||||
end
|
||||
end
|
||||
|
||||
# Helper functions
|
||||
defp create_member do
|
||||
system_actor = Mv.Helpers.SystemActor.get_system_actor()
|
||||
|
||||
Member
|
||||
|> Ash.Changeset.for_create(:create_member, %{
|
||||
first_name: "Test",
|
||||
last_name: "User#{System.unique_integer([:positive])}",
|
||||
email: "test#{System.unique_integer([:positive])}@example.com"
|
||||
})
|
||||
|> Ash.create()
|
||||
|> Ash.create(actor: system_actor)
|
||||
end
|
||||
|
||||
defp create_custom_field(name, value_type) do
|
||||
system_actor = Mv.Helpers.SystemActor.get_system_actor()
|
||||
|
||||
CustomField
|
||||
|> Ash.Changeset.for_create(:create, %{
|
||||
name: "#{name}_#{System.unique_integer([:positive])}",
|
||||
value_type: value_type
|
||||
})
|
||||
|> Ash.create()
|
||||
|> Ash.create(actor: system_actor)
|
||||
end
|
||||
|
||||
defp create_custom_field_value(member, custom_field, value) do
|
||||
system_actor = Mv.Helpers.SystemActor.get_system_actor()
|
||||
|
||||
CustomFieldValue
|
||||
|> Ash.Changeset.for_create(:create, %{
|
||||
member_id: member.id,
|
||||
custom_field_id: custom_field.id,
|
||||
value: %{"_union_type" => "string", "_union_value" => value}
|
||||
})
|
||||
|> Ash.create()
|
||||
|> Ash.create(actor: system_actor)
|
||||
end
|
||||
|
||||
defp log_in_user(conn, user) do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue