ash_phoenix
ash_phoenix copied to clipboard
WIP tests for get_forms and has_form?
Tests for proposed api for get_forms/2, and extending has_form?/2 to work on a list of forms. see #42
get_forms/2 to find single or list of forms, but always returns a list.
Let me know how this looks and I'll have a go at the implementation.
Contributor checklist
- [ ] Bug fixes include regression tests
- [X] Features include unit/acceptance tests
Looks perfect 🔥
beat me to it 😸
Having a look at this now, I've started writing some tests for get_form just to get my head around the current implementation (and there aren't any tests currently), and found an inconsistency.
form =
Post
|> Form.for_create(:create,
api: Api,
forms: [
comments: [
type: :list,
resource: Comment,
create_action: :create
]
]
)
# All good
assert Form.get_form(form, [:comments]) == nil
assert Form.get_form(form, "form[comments]") == nil
# Inconsistent
assert Form.get_form(form, [:comments, 0]) == nil
assert Form.get_form(form, "form[comments][0]") == nil # <-- raises Invalid Path: form[comments][0]
Is that intended (the query path version raise and the list version not)?
That sounds problematic and undesired. It would be interesting to see if we can't find out why it fails to parse that path though....nevermind. Its because it is using parse_path! which expects to find a form at that path. We need a different utility that returns nil (or something) when it encounters an index that doesn't exist, so that we can return nil from get_form/2
Cool, I'll have a go at fixing that first
Going to close this since its been stale for a while.
(7 months, to be exact 😆 )