# `Letterbox.Test`
[🔗](https://github.com/hattoriai/letterbox/blob/v0.1.0-rc.0/lib/letterbox/test.ex#L1)

An app's tests of its mailboxes and routes.

    import Letterbox.Test

    test "photographs sent to a site are in its library", %{site: site} do
      inbound =
        deliver(
          from: "ana@example.com",
          to: "site+#{site.inbound_token}@in.example.com",
          subject: "From the beach",
          attachments: [%{name: "praia.jpg", content_type: "image/jpeg", data: File.read!("test/fixtures/praia.jpg")}]
        )

      assert inbound.status == "delivered"
      assert [%{name: "praia.jpg"}] = Media.list(site)
    end

`deliver/2` goes the whole way, as a webhook's message would: kept (in
the app's store, `Storehouse.Memory` in tests), a row in the app's
database (Ecto's sandbox), and given to its mailbox in the test's own
process, at once. `message/2` makes a `Letterbox.Message` only, to call a
mailbox's `process/1` with it; `mailbox_for/2` says which mailbox takes
one.

# `deliver`

```elixir
@spec deliver(keyword() | binary(), keyword()) :: Letterbox.Inbound.t()
```

An email made from `fields` (`Letterbox.Email.build/1`, or a raw email),
received and given to its mailbox at once. Gives its row, with the
status its mailbox left.

Options: `:recipients` (the envelope's; by default the email's `To`,
`Cc` and `Delivered-To`), `:ingress` (`"test"`), `:external_id`.

# `mailbox_for`

```elixir
@spec mailbox_for(keyword() | binary(), keyword()) :: {:ok, module()} | :none
```

The mailbox the app's routes give a message made from `fields`: `{:ok,
mailbox}`, or `:none`.

# `message`

```elixir
@spec message(keyword() | binary(), keyword()) :: Letterbox.Message.t()
```

The `Letterbox.Message` a mailbox would get for an email made from
`fields` (or a raw email). Options: `:recipients`, and `:recipient`, the
address its route matched (`message.recipient`; by default the first
recipient).

---

*Consult [api-reference.md](api-reference.md) for complete listing*
