prop/vendor/oban_pro/usage-rules/testing.md
Graham McIntire e99bf06eb4
deps: re-vendor oban_pro 1.7.0 (revert hex-repo dep)
Previous commit (3c988a5f) switched oban_pro to the licensed hex
repo at deploy time. Reverting that — keep all three Pro packages
vendored so prod image builds don't depend on oban.pro reachability
or auth on every CI run.

oban_pro 1.7.0 dropped into vendor/oban_pro via
`mix hex.package fetch oban_pro 1.7.0 --repo=oban --unpack`. mix.exs
goes back to `path: "vendor/oban_pro"` (matching oban_met / oban_web,
which were already vendored — and stay vendored since the licensed
repo only has older versions of those: 0.1.11 / 2.10.6 vs the
1.1.0 / 2.12.1 we vendor).

Schema migration from 3c988a5f stays — 1.7.0 tables/indexes are
already applied. No code changes.
2026-04-30 09:29:55 -05:00

48 lines
1.2 KiB
Markdown

# Testing
Use `Oban.Pro.Testing` — a drop-in replacement for `Oban.Testing` with Pro helpers.
## Configuration
```elixir
# config/test.exs
config :my_app, Oban, testing: :manual
```
## Helpers
**Unit testing** — execute jobs without the database:
- `perform_job/3` — execute a single job
- `perform_callback/4` — execute batch callbacks
- `perform_chunk/3` — execute chunk workers
**Integration testing** — insert and execute jobs:
- `drain_jobs/1` — execute jobs across queues
- `run_workflow/2` — insert and execute a workflow
- `run_batch/2` — insert and execute a batch
- `run_chunk/2` — insert and execute chunked jobs
**Always use `drain_jobs/1` instead of `Oban.drain_queue/2`:**
- Drains all queues with `queue: :all`
- Handles workflows, batches, and chains correctly
- Supports recursive draining
- Returns completion counts
```elixir
defmodule MyApp.WorkerTest do
use MyApp.DataCase, async: false
use Oban.Pro.Testing, repo: MyApp.Repo
test "processes job" do
assert :ok == perform_job(SomeWorker, %{user_id: 123})
end
test "drains enqueued jobs" do
MyApp.enqueue_work()
assert %{completed: 3} = drain_jobs(queue: :all)
end
end
```