Anu.TestAssertions (Anu v0.2.0)

Copy Markdown View Source

ExUnit assertion helpers for testing Anu message delivery.

Requires delivering through a client built with the test adapter (Anu.Adapters.Test).

Usage

defmodule MyApp.NotifierTest do
  use ExUnit.Case
  import Anu.TestAssertions

  setup do
    {:ok, client: Anu.Client.new(adapter: Anu.Adapters.Test, finch: MyApp.Finch)}
  end

  test "sends welcome message", %{client: client} do
    Anu.Message.new("+5511999999999")
    |> Anu.Message.text("Welcome!")
    |> Anu.deliver(client)

    assert_message_sent to: "+5511999999999", body: "Welcome!"
  end

  test "does not send if condition is false" do
    refute_message_sent()
  end
end

Summary

Functions

Asserts that a message was sent via the test adapter.

Refutes that any message was sent via the test adapter.

Functions

assert_message_sent(fields \\ [])

(macro)

Asserts that a message was sent via the test adapter.

Accepts an optional keyword list of fields to match against the %Anu.Message{} struct.

Examples

assert_message_sent()
assert_message_sent(to: "+5511999999999")
assert_message_sent(to: "+5511999999999", body: "hello")

refute_message_sent()

(macro)

Refutes that any message was sent via the test adapter.

Examples

refute_message_sent()