PhoenixAI.Test (PhoenixAI v0.1.0)

Copy Markdown View Source

ExUnit helper for testing with PhoenixAI's TestProvider.

Usage

defmodule MyTest do
  use ExUnit.Case, async: true
  use PhoenixAI.Test

  test "chat returns scripted response" do
    set_responses([{:ok, %Response{content: "Hello"}}])

    assert {:ok, %Response{content: "Hello"}} =
      AI.chat([%Message{role: :user, content: "Hi"}], provider: :test, api_key: "test")
  end

  test "verifies calls were made" do
    set_responses([{:ok, %Response{content: "Hi"}}])
    AI.chat([%{role: "user", content: "Hello"}], provider: :test, api_key: "test")

    assert_called({[%{role: "user", content: "Hello"}], _opts})
  end
end

Summary

Functions

Asserts that at least one call to the TestProvider matches the given pattern.

Functions

assert_called(pattern)

(macro)

Asserts that at least one call to the TestProvider matches the given pattern.

Uses pattern matching, so you can use _ and pinned variables.

Examples

assert_called({[%{role: "user", content: "Hello"}], _opts})
assert_called({_messages, opts} when opts[:model] == "gpt-4o")