Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Problem with test that passes #12

Open
wolfiton opened this issue Feb 5, 2020 · 3 comments
Open

Problem with test that passes #12

wolfiton opened this issue Feb 5, 2020 · 3 comments

Comments

@wolfiton
Copy link

wolfiton commented Feb 5, 2020

I was trying to rewrite this test in Wormwood:

@query """
  {
    menuItems(matching: 123) {
      name
    }
  }
  """
  test "menuItems field returns errors when using a bad value" do
    response = get(build_conn(), "/api", query: @query)
    assert %{"errors" => [
      %{"message" => message}
    ]} = json_response(response, 400)
    assert message == "Argument \"matching\" has invalid value 123."
  end

And i don’t see any possibilities at the moment to do so.

My final version is this

describe "GetMenuItems.gql == error" do
    test "Should return error Menu items (error)" do
      term = 123
      result = query_gql(variables: %{"matching" => term})
      IO.inspect(result)

      assert {:ok, %{errors: [%{message: message}]}} = result

      assert message == "Argument \"matching\" has invalid value $matching."
    end
  end

The main problem is that I am expecting my value instead of $matching in this case 123 like in the exunit test
The problem is discussed here https://elixirforum.com/t/test-error-case-in-wormwood/28876/18

@QuinnWilton
Copy link
Contributor

Hi @wolfiton :)

What does the query look like that you're loading into Wormwood?

@wolfiton
Copy link
Author

wolfiton commented Feb 5, 2020

Hi @QuinnWilton

Here are my gql files

GetMenuItems.gql file content


#import "./MenuItemFields.frag.gql"

query($matching: String) {
  MenuItems(matching: $matching) {
    ...MenuItemFields
  }
}

MenuItemFields.frag.gql file content

fragment MenuItemFields on MenuItem {
  id
  name
}

Here is my schema.ex

defmodule PlateSlateWeb.Schema do
  use Absinthe.Schema

  alias PlateSlateWeb.Resolvers

  @desc "Queryable fields for Menu Item"
  query do
    field :menu_items, list_of(:menu_item) do
      arg(:matching, :string)
      arg(:order, type: :sort_order, default_value: :asc)
      resolve(&Resolvers.Menu.menu_items/3)
    end
  end

  @desc "define fileds that can be accessed for Menu Items"
  object :menu_item do
    field :id, :id
    field :name, :string
  end

  @desc "order menu items"
  enum :sort_order do
    value(:asc)
    value(:desc)
  end
end

I really appreciate any insights into this.
If anything else is needed let me know.
Thanks

@BlueHotDog
Copy link

Hey, also looking into this. can't pass an enum value using this lib to an argument for a mutation.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants