# `Alternera.Resource.Test`
[🔗](https://github.com/10e-ab/alternera-sdk/blob/v0.9.0/alternera_resource_sdk/lib/alternera/resource/test.ex#L1)

The database side of a resource package's own tests, with no proxy around.

In `test/test_helper.exs`:

    Alternera.Resource.Test.start_database!(Finance.Resources)
    ExUnit.start()

`start_database!/2` creates the test database when it is missing, starts
`Alternera.Resource.Repo` on it, runs the package's migrations and
puts the repo's sandbox in manual mode. Configure
the repo in the package's `config/test.exs`:

    config :alternera_resource_sdk, Alternera.Resource.Repo,
      database: "finance_test",
      pool: Ecto.Adapters.SQL.Sandbox,
      priv: "priv/resource_repo"

The contract kit (`Alternera.Resource.Test.Contract`) and tests of
the package's own check out the sandbox with `checkout/1` and make tenant
ids with `create_tenant!/0`.

# `checkout`

```elixir
@spec checkout(map()) :: :ok
```

Checks out a sandbox connection for the test; shared unless the test is async.

# `create_tenant!`

```elixir
@spec create_tenant!() :: String.t()
```

A stand-in tenant id. Resource tables have no foreign key to a tenants
table, so a tenant is only an id here.

# `start_database!`

```elixir
@spec start_database!(module(), keyword()) :: :ok
```

Prepares the test database for the package of `domain`. `:priv` is the
directory that holds the package's `migrations` (default
`"priv/resource_repo"`, relative to the package project).

---

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