MishkaCmsCore.Test.Admin (Mishka CMS Core v0.0.3)

Copy Markdown View Source

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.

Summary

Functions

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

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

Clears both flashes of view, and answers view.

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

A registered master user holding no permission.

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

Signs user in on conn, in master mode.

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

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

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.

Functions

build_conn_for_host(host \\ "localhost")

@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(site)

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

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

clear_flashes(view)

@spec clear_flashes(struct()) :: struct()

Clears both flashes of view, and answers view.

create_admin(email, site_id \\ nil, permissions \\ ["*"])

@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(email)

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

A registered master user holding no permission.

flashes(view)

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

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

log_in(conn, user)

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

Signs user in on conn, in master mode.

narrow_conn(site, permissions)

@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!(name)

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

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

serve_localhost!(context)

@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.