So I’m trying to test my workers, and I have queues and plugins set to false in my config/test.exs file. It seems like the jobs are being completed before I can assert that they’re enqueued??
config :app, Oban, plugins: false, queues: false, testing: :inline
test "successfully enqueues jobs for valid youtube playlist subscriptions" do
subs = insert_list(2, :subscription)
assert :ok = perform_job(SubscriptionsWorker, %{})
Enum.each(subs, fn sub ->
assert_enqueued(
[worker: YouTubeAPIWorker, args: %{"playlist_id" => sub.external_id}],
100
)
end)
end
And in my SubscriptionsWorker here is the perform function:
def perform(_job) do
Subscriptions.list_subscriptions()
|> Enum.map(&subscription_to_job/1)
|> Enum.reject(&(&1 == :drop))
|> Oban.insert_all()
|> IO.inspect() # prints the jobs as already completed
:ok
end
But still I’m getting an error that that there are no matches:
# Expected a job matching:
%{
args: %{"playlist_id" => "subscription_-576460752303423484"},
worker: YouTubeAPIWorker
}