Skip to content

Add test coverage for actor availability in preparations for generic actions#418

Merged
zachdaniel merged 1 commit intoash-project:mainfrom
joshampton:prepare-actor
Mar 15, 2026
Merged

Add test coverage for actor availability in preparations for generic actions#418
zachdaniel merged 1 commit intoash-project:mainfrom
joshampton:prepare-actor

Conversation

@joshampton
Copy link
Copy Markdown
Contributor

Problem

In version 1.8.5, prepare functions in generic actions do not have an actor even if one is set. The actor is available in the context via the run block:

defmodule Helpdesk.Ticket do
  use Ash.Resource,
    otp_app: :example,
    domain: Helpdesk,
    extensions: [AshGraphql.Resource]

  graphql do
    type :ticket

    mutations do
      action :custom, :custom
    end
  end

  actions do
    action :custom, :string do
      prepare fn input, %{actor: actor} ->
        actor |> dbg()

        Ash.ActionInput.set_context(input, %{prepare_actor: actor})
      end

      run fn _input, context ->
        %{actor: actor} = context
        %{source_context: %{prepare_actor: prepare_actor}} = context

        actor |> dbg()

        {:ok, inspect(prepare_actor)}
      end
    end
  end

  attributes do
    uuid_v7_primary_key :id
  end
end
[lib/helpdesk/ticket.ex:18: Helpdesk.Ticket.preparation_0_generated_B22ED5B3B578F28D2D69ABAB6B5758F5/2]
actor #=> nil

[lib/helpdesk/ticket.ex:27: Helpdesk.Ticket.run_0_generated_03A740289189638B3359E25173FF68B3/2]
actor #=> %Example.Actor{user: :anonymous}

[test/helpdesk/ticket_test.exs:16: Helpdesk.TicketTest."test graphql example"/1]
response #=> %{"data" => %{"custom" => "nil"}}

Fix

I believe this is already fixed in main but could use some coverage.

Test Plan

Added test "actor is set for preparations on Generic Actions" to test/plug_test.exs

Contributor checklist

Leave anything that you believe does not apply unchecked.

  • I accept the AI Policy, or AI was not used in the creation of this PR.
  • Bug fixes include regression tests
  • Chores
  • Documentation changes
  • Features include unit/acceptance tests
  • Refactoring
  • Update dependencies

@zachdaniel zachdaniel merged commit 5d78189 into ash-project:main Mar 15, 2026
22 of 23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants