ash_oban icon indicating copy to clipboard operation
ash_oban copied to clipboard

Test helper functions like `assert_triggered`

Open sevenseacat opened this issue 1 year ago • 0 comments

When testing actions that can kick off background jobs, it would be nice to be able to have succinct and fine-grained assertions on exactly what jobs were fired.

Oban provides assert_enqueued, and that can be used eg.

# A job should be enqueued to make the meeting on Zoom
assert_enqueued(args: %{primary_key: %{id: appointment.id}}, queue: :zoom_api)

But nothing really more specific, given that worker modules are dynamically defined.

It would be great if assert_enqueued was wrapped in a way that if we had code like:

update :update do
  change AshOban.Changes.BuiltinChanges.run_oban_trigger(:create_zoom_meeting)
end

We could test it like:

{:ok, appointment} = Appointment.update(appointment, params)
assert_triggered(appointment, :create_zoom_meeting)

sevenseacat avatar Feb 21 '24 06:02 sevenseacat