Alternera.Resource.Test.Contract (alternera_resource_sdk v0.9.0)

Copy Markdown View Source

The contract test kit for a resource package, run with no proxy around.

defmodule Finance.ContractTest do
  use Alternera.Resource.Test.Contract

  resource_package_contract Finance.Resources,
    samples: %{Finance.Currency => %{code: "SEK"}}
end

For each resource of the domain it generates tests that:

  • check every rule of Alternera.Resource.Verifiers on the compiled resource;
  • (once per package) refuse a migration that drops functions, as the down ash.codegen writes for the extensions migration does: on the proxy's database Ash's functions are the proxy's too;
  • find a migration that creates its table and its versions table in the package's schema with an index on tenant_id, and a snapshot of each under the snapshots directory;
  • create, read, update and destroy a record in two stand-in tenants and find each tenant's record only in that tenant;
  • find a version row for each write, carrying the actor's id;
  • with cache on, tell the host of each committed write; without it, tell it nothing;
  • refuse writes to an actor without tenant_admin, and reads when the host is not licensed (a destroy still works then);
  • refuse, as an error on the reference's field, a create or an update whose belongs_to names a record of another tenant.

It also checks the package's page of the user guide, when the domain has one (docs:): its front matter has title, section: Resource packages, order, summary and verified, and no licensed.

Options: :samples (see Alternera.Resource.Test.Samples), :priv (the directory holding migrations, default "priv/resource_repo") and :snapshots (default "priv/resource_snapshots"). The test database comes from Alternera.Resource.Test.start_database!/2 in test_helper.exs.

Summary

Functions

Generates the contract tests for every resource of domain.

Functions

resource_package_contract(domain, opts \\ [])

(macro)

Generates the contract tests for every resource of domain.