benswift
Ash.Generator property testing for invalid inputs
The new how to guide on testing resources has some helpful ideas on how to test that actions handle valid inputs.
What’s the recommended way to test that invalid inputs don’t slip through? There’s no Ash.Generator.invalid_action_input/3.
I could just gen all my own invalid inputs (using the “wrong” generator for each attribute) but I wondered if there was a better way?
Most Liked
zachdaniel
I think the best approach here would be to modify the existing generators with invalid attribute generators. For example:
property "doesn't accept maps as input to text" do
user = Domain.create_user!()
check all(input <- Ash.Generator.action_input(Tweet, :create, %{text: StreamData.fixed_map(%{a: 1})})) do
{text, other_inputs} = Map.pop!(input, :text)
Domain.create_tweet!(text, other_inputs, authorize?: false, actor: user)
end
end
This particular one is a bit of a silly example, but the point was to illustrate that individual generators can be overridden with generators that produce whatever you like to test specific conditions.
Does that seem like it fits the bill of what you’re looking for?
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #javascript
- #code-sync
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









