ash_phoenix icon indicating copy to clipboard operation
ash_phoenix copied to clipboard

WIP tests for get_forms and has_form?

Open totaltrash opened this issue 3 years ago • 5 comments

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

totaltrash avatar May 22 '22 23:05 totaltrash

Looks perfect 🔥

zachdaniel avatar May 23 '22 06:05 zachdaniel

beat me to it 😸

kernel-io avatar May 23 '22 10:05 kernel-io

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)?

totaltrash avatar Jul 26 '22 06:07 totaltrash

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

zachdaniel avatar Jul 26 '22 07:07 zachdaniel

Cool, I'll have a go at fixing that first

totaltrash avatar Jul 26 '22 07:07 totaltrash

Going to close this since its been stale for a while.

zachdaniel avatar Dec 21 '22 03:12 zachdaniel

(7 months, to be exact 😆 )

zachdaniel avatar Dec 21 '22 03:12 zachdaniel