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

Copy Markdown View Source

Builds a valid record of any resource, for the contract kit and for tests.

The input for the primary create action comes from the attributes' types and constraints: a string, a number inside its bounds, today's date, the first of a one_of and so on. A required belongs_to gets a record of its own, made first in the same tenant. A value the types cannot guess (a string with a match: pattern, a custom type) comes from samples, a map of resource module to the attributes that override the generated ones:

Samples.create!(Finance.Currency, tenant, actor, %{Finance.Currency => %{code: "SEK"}})

A sample may also be a function of no arguments that returns the map, called for each record: a resource with two required references to the same parent needs two parents, and a parent with a unique attribute then needs a new value each time.

Summary

Functions

Creates a record of resource in tenant as actor, with its required parents.

The create input for resource, without its required parents.

The create input for resource, after creating a record for each required belongs_to in tenant as actor.

The sample attributes for resource in samples: the map, or what its function returns.

Functions

create!(resource, tenant, actor, samples \\ %{}, depth \\ 0)

@spec create!(module(), String.t(), term(), map(), non_neg_integer()) ::
  Ash.Resource.record()

Creates a record of resource in tenant as actor, with its required parents.

input(resource, samples \\ %{})

@spec input(module(), map()) :: map()

The create input for resource, without its required parents.

input_with_parents!(resource, tenant, actor, samples \\ %{}, depth \\ 0)

@spec input_with_parents!(module(), String.t(), term(), map(), non_neg_integer()) ::
  map()

The create input for resource, after creating a record for each required belongs_to in tenant as actor.

sample(samples, resource)

@spec sample(map(), module()) :: map()

The sample attributes for resource in samples: the map, or what its function returns.