# `MishkaCmsCore.Test.Admin`
[🔗](https://github.com/mishka-group/mishka_cms_core/blob/v0.0.3/lib/mishka_cms_core/test/admin.ex#L5)

Admins, signed-in connections and the master `localhost` site, for a test that drives the admin
through its LiveViews — the core's or an extension's.

    setup :serve_localhost!

`serve_localhost!/1` caches a master `localhost` site, marks the CMS installed, saves one page on
the site and signs `boss@example.com` in as a `*` admin of it, then hands the test
`%{conn: conn, site: site, page: page}`. The rest build what a test needs beside that: an admin
with other permissions (`create_admin/3`, `narrow_conn/2`), a user with none, a connection on
another host, and the flashes a LiveView shows.

The site cache (`MishkaCmsCore.Runtime.States.SiteState`) and the installed mark are the node's,
not the test's sandbox, so a test using `serve_localhost!/1` is `async: false`.

# `build_conn_for_host`

```elixir
@spec build_conn_for_host(String.t()) :: Plug.Conn.t()
```

A fresh connection on a site's own address, `localhost` unless told — `serve_localhost!/1`'s is
already signed in.

# `cache_site`

```elixir
@spec cache_site(struct()) :: term()
```

Puts `site` in the site cache, as the runtime does when it loads it.

# `clear_flashes`

```elixir
@spec clear_flashes(struct()) :: struct()
```

Clears both flashes of `view`, and answers `view`.

# `create_admin`

```elixir
@spec create_admin(String.t(), String.t() | nil, [String.t()]) :: struct()
```

A user registered with a password, on `site_id` (`nil` for a master user), holding
`permissions` — every one by default.

# `create_user_without_permissions`

```elixir
@spec create_user_without_permissions(String.t()) :: struct()
```

A registered master user holding no permission.

# `flashes`

```elixir
@spec flashes(struct()) :: String.t()
```

The text of the info and error flashes `view` shows, tags removed.

# `log_in`

```elixir
@spec log_in(Plug.Conn.t(), struct()) :: Plug.Conn.t()
```

Signs `user` in on `conn`, in master mode.

# `narrow_conn`

```elixir
@spec narrow_conn(struct(), [String.t()]) :: Plug.Conn.t()
```

A connection on `localhost` signed in as a new admin of `site` holding only `permissions`.

# `permission!`

```elixir
@spec permission!(String.t()) :: struct()
```

The permission named `name`, created when it does not exist yet.

# `serve_localhost!`

```elixir
@spec serve_localhost!(map()) :: %{
  conn: Plug.Conn.t(),
  site: struct(),
  page: struct()
}
```

A setup callback: the master `localhost` site, created and cached, the CMS marked installed, one
page on the site drawing the context's `:template` (a hero section when it has none), and the
context's `conn` (a new one when it has none) on `localhost`, signed in as a `*` admin. Both
marks are cleared when the test exits.

---

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