Skip to content

gen1321/anise

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Anise

Anise is a set of helpers/assertions for Absinthe

Installation

def deps do
  [
    {:anise, "~> 0.1.1"}
  ]
end

Usage

Without subscriptions

Add use Anise on top of your tests.

Than you can do that.

graphql(conn, "/api", @mutation, %{email: "[email protected]", name: "Boris"})

same for queries.

With subscriptions

Create subscription_case.ex in test/support.

defmodule MyAppWeb.SubscriptionCase do
  use ExUnit.CaseTemplate

  using do
    quote do
      @endpoint MyAppWeb.Endpoint
      use Anise

      use Anise.SubscriptionCase,
        schema: MyAppWeb.Schema,
        socket: MyAppWeb.UserSocket
      end
  end

  setup do
    :ok
  end
end

Then in your subscription tests add use MyAppWeb.Subscription

Now you can test your subscriptions.

  describe "User add" do
    test "valid data", %{socket: socket, conn: conn} do
      assert %{
               payload: %{subscriptionId: sub_id},
               status: :ok
             } = subscribe(socket, @subscription)

      graphql(conn, "/api", @mutation, %{email: "[email protected]", name: "Boris"})

      expected = %{result: %{data: %{"userAdded" => %{"name" => "Boris"}}}}
      assert_subscription_fulfilment fufilment
      assert fufilment = expected
    end
  end

Releases

No releases published

Packages

No packages published

Languages