Kiq v0.1.0 Kiq.Testing View Source

This module simplifies testing whether your application is enqueuing jobs as expected.

If your application has defined a top level Kiq module as MyApp.Kiq, then you would use the testing module inside your application’s case templates like so:

use Kiq.Testing, client: MyApp.Kiq.Client

That will define two helper functions, assert_enqueued/1 and refute_enqueued/1. The functions can then be used to make assertions on the jobs that have been stored while testing.

Given a simple module that enqueues a job:

defmodule MyApp.Business do
  alias MyApp.Kiq

  def work(args) do
    Kiq.enqueue(class: "SomeWorker", args: args)
  end
end

The behaviour can be exercised in your test code:

defmodule MyApp.BusinessTest do
  use ExUnit.Case, async: true
  use Kiq.Testing, client: MyApp.Kiq.Client

  alias MyApp.Business

  test "jobs are enqueued with provided arguments" do
    Business.work([1, 2])

    assert_enqueued(class: "SomeWorker", args: [1, 2])
  end
end

Link to this section Summary

Functions

Assert that a job with particular options has been enqueued

Refute that a job with particular options has been enqueued

Link to this section Functions

Link to this function assert_enqueued(client, args) View Source
assert_enqueued(client :: identifier(), args :: Enum.t()) :: any()

Assert that a job with particular options has been enqueued.

Only values for the provided arguments will be checked. For example, an assertion made on class: "MyWorker" will match any jobs for that class, regardless of the args.

If the queue isn’t specified it falls back to default. This can cause confusion when checking for jobs pushed into alternate queues.

Link to this function refute_enqueued(client, args) View Source
refute_enqueued(client :: identifier(), args :: Enum.t()) :: any()

Refute that a job with particular options has been enqueued.

See assert_enqueued/2 for additional details.