Haytni.Params (Haytni v0.7.0) View Source
Convenient functions to build the params Map (parameters for the HTTP request) in tests
Link to this section Summary
Functions
Adds the confirmation keys to the map params by copying the values of the given keys under the same suffixed by "_confirmation".
Creates parameters (a map of string as keys and values) by merging attrs into defaults.
Wraps params in an other Map with the stringified key as key
Link to this section Functions
Specs
confirm(params :: Haytni.params(), keys :: [atom() | String.t()]) :: Haytni.params()
Adds the confirmation keys to the map params by copying the values of the given keys under the same suffixed by "_confirmation".
Example:
iex> Elixir.Haytni.Params.confirm(%{"email" => "foo@bar.com", "password" => "azerty", ~W[password]a}
%{"email" => "foo@bar.com", "password" => "azerty", "password_confirmation" => "azerty"}
Specs
create( defaults :: Enumerable.t() | struct(), attrs :: Enumerable.t() | struct() ) :: Haytni.params() | no_return()
Creates parameters (a map of string as keys and values) by merging attrs into defaults.
NOTES:
- defaults has to contain all the necessary keys because, in order to accept struct as attrs the extra keys of attrs are dropped
- all keys are stringified for convenience/reduce boilerplate
- if a value in attrs is a function (of 1-arity), it will be called with the corresponding value of defaults to set the final value
nil
values from a struct are "safely" ignored
Specs
wrap(params :: Haytni.params(), key :: atom() | String.t()) :: Haytni.params()
Wraps params in an other Map with the stringified key as key
Example:
iex> Elixir.Haytni.Params.wrap(%{"email" => %{"email" => "foo@bar.com", "password" => "azerty"}}, :session)
%{"session" => %{"email" => "foo@bar.com", "password" => "azerty"}}