Coffrify.Testing (Coffrify v0.9.0)

View Source

Test helpers for apps consuming the Coffrify Elixir SDK.

Summary

Functions

Sign a payload using the same scheme as Coffrify's server. Returns {body, headers_list} ready to plug into a Plug.Test.conn/3 call.

Convenience: assert that a self-signed payload verifies. Returns the decoded event on success, raises with the rejection reason otherwise.

Functions

sign_payload_test(secret, body, opts \\ [])

@spec sign_payload_test(String.t(), iodata(), keyword()) ::
  {binary(), [{String.t(), String.t()}]}

Sign a payload using the same scheme as Coffrify's server. Returns {body, headers_list} ready to plug into a Plug.Test.conn/3 call.

Options

  • :event_id — explicit webhook-id (default evt_<rand>)
  • :timestamp — explicit webhook-timestamp (default now)
  • :extra_headers — extra headers merged into the result

Example

{body, headers} =
  Coffrify.Testing.sign_payload_test("whsec_abc...",
    Jason.encode!(%{type: "ping"}))

conn =
  :post
  |> Plug.Test.conn("/webhook", body)
  |> Map.update!(:req_headers, &(&1 ++ headers))

verify_test_payload!(secret, body, opts \\ [])

@spec verify_test_payload!(String.t(), iodata(), keyword()) :: map()

Convenience: assert that a self-signed payload verifies. Returns the decoded event on success, raises with the rejection reason otherwise.