From 5f63dbcff7c6b14c58aaf86a0f448b0ae83bdcfe Mon Sep 17 00:00:00 2001 From: Tobias Casper Date: Wed, 27 Mar 2024 22:44:08 +0100 Subject: [PATCH] fix: GraphQLWSClient test --- test/graphql_ws_client_test.exs | 43 ++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/test/graphql_ws_client_test.exs b/test/graphql_ws_client_test.exs index 3dee2f9..e7e180c 100644 --- a/test/graphql_ws_client_test.exs +++ b/test/graphql_ws_client_test.exs @@ -47,7 +47,7 @@ defmodule GraphQLWSClientTest do {:ok, @conn} end) - assert {:ok, client} = start_supervised({GraphQLWSClient, @config}) + assert {:ok, client} = GraphQLWSClient.start_link(@config) # start_supervised({GraphQLWSClient, @config}) assert GraphQLWSClient.connected?(client) == true end @@ -56,7 +56,7 @@ defmodule GraphQLWSClientTest do {:ok, @conn} end) - assert {:ok, client} = start_supervised({GraphQLWSClient, @opts}) + assert {:ok, client} = GraphQLWSClient.start_link(@opts) assert GraphQLWSClient.connected?(client) == true end @@ -68,7 +68,7 @@ defmodule GraphQLWSClientTest do end) assert capture_log(fn -> - start_supervised!({GraphQLWSClient, @config}) + GraphQLWSClient.start_link(@config) # wait a little bit until connection fails Process.sleep(100) @@ -87,7 +87,7 @@ defmodule GraphQLWSClientTest do {:ok, conn} end) - client = start_supervised!({GraphQLWSClient, config}) + {:ok, client} = GraphQLWSClient.start_link(config) assert GraphQLWSClient.connected?(client) == false assert GraphQLWSClient.open(client) == :ok @@ -101,13 +101,13 @@ defmodule GraphQLWSClientTest do {:error, error} end) - client = start_supervised!({GraphQLWSClient, config}) + {:ok, client} = GraphQLWSClient.start_link(config) assert GraphQLWSClient.open(client) == {:error, error} end test "no-op when already connected", %{config: config, conn: conn} do - client = start_supervised!({GraphQLWSClient, config}) + {:ok, client} = GraphQLWSClient.start_link(config) expect(MockDriver, :connect, fn ^conn -> {:ok, conn} @@ -130,7 +130,7 @@ defmodule GraphQLWSClientTest do {:ok, conn} end) - client = start_supervised!({GraphQLWSClient, config}) + {:ok, client} = GraphQLWSClient.start_link(config) assert GraphQLWSClient.connected?(client) == false assert GraphQLWSClient.open!(client) == :ok @@ -144,7 +144,7 @@ defmodule GraphQLWSClientTest do {:error, error} end) - client = start_supervised!({GraphQLWSClient, config}) + {:ok, client} = GraphQLWSClient.start_link(config) assert_raise SocketError, Exception.message(error), fn -> GraphQLWSClient.open!(client) @@ -158,6 +158,7 @@ defmodule GraphQLWSClientTest do setup do config = %{@config | connect_on_start: false} conn = %{@conn | config: config, init_payload: @init_payload} + {:ok, config: config, conn: conn} end @@ -166,7 +167,7 @@ defmodule GraphQLWSClientTest do {:ok, conn} end) - client = start_supervised!({GraphQLWSClient, config}) + {:ok, client} = GraphQLWSClient.start_link(config) assert GraphQLWSClient.connected?(client) == false assert GraphQLWSClient.open_with(client, @init_payload) == :ok @@ -180,13 +181,13 @@ defmodule GraphQLWSClientTest do {:error, error} end) - client = start_supervised!({GraphQLWSClient, config}) + {:ok, client} = GraphQLWSClient.start_link(config) assert GraphQLWSClient.open_with(client, @init_payload) == {:error, error} end test "no-op when already connected", %{config: config, conn: conn} do - client = start_supervised!({GraphQLWSClient, config}) + {:ok, client} = GraphQLWSClient.start_link(config) expect(MockDriver, :connect, fn ^conn -> {:ok, conn} @@ -209,7 +210,7 @@ defmodule GraphQLWSClientTest do |> expect(:disconnect, fn ^conn -> :ok end) |> expect(:connect, fn ^reconnect_conn -> {:ok, reconnect_conn} end) - client = start_supervised!({GraphQLWSClient, config}) + {:ok, client} = GraphQLWSClient.start_link(config) assert GraphQLWSClient.open_with(client, @init_payload) == :ok assert GraphQLWSClient.close(client) == :ok @@ -234,7 +235,7 @@ defmodule GraphQLWSClientTest do {:ok, conn} end) - client = start_supervised!({GraphQLWSClient, config}) + {:ok, client} = GraphQLWSClient.start_link(config) assert GraphQLWSClient.open_with(client, @init_payload) == {:error, error} assert_receive :reconnected_msg @@ -259,7 +260,7 @@ defmodule GraphQLWSClientTest do {:ok, conn} end) - client = start_supervised!({GraphQLWSClient, config}) + {:ok, client} = GraphQLWSClient.start_link(config) assert GraphQLWSClient.open_with(client, @init_payload) == :ok assert_receive :reconnected_msg @@ -280,7 +281,7 @@ defmodule GraphQLWSClientTest do {:ok, conn} end) - client = start_supervised!({GraphQLWSClient, config}) + {:ok, client} = GraphQLWSClient.start_link(config) assert GraphQLWSClient.connected?(client) == false assert GraphQLWSClient.open_with!(client, @init_payload) == :ok @@ -294,7 +295,7 @@ defmodule GraphQLWSClientTest do {:error, error} end) - client = start_supervised!({GraphQLWSClient, config}) + {:ok, client} = GraphQLWSClient.start_link(config) assert_raise SocketError, Exception.message(error), fn -> GraphQLWSClient.open_with!(client, @init_payload) @@ -382,7 +383,7 @@ defmodule GraphQLWSClientTest do test "not connected" do config = %{@config | connect_on_start: false} - client = start_supervised!({GraphQLWSClient, config}) + {:ok, client} = GraphQLWSClient.start_link(config) assert GraphQLWSClient.query(client, @query, @variables) == {:error, %SocketError{cause: :closed}} @@ -404,7 +405,7 @@ defmodule GraphQLWSClientTest do :ok end) - client = start_supervised!({GraphQLWSClient, config}) + {:ok, client} = GraphQLWSClient.start_link(config) assert GraphQLWSClient.query(client, @query, @variables) == {:error, %SocketError{cause: :timeout}} @@ -587,7 +588,7 @@ defmodule GraphQLWSClientTest do test "not connected" do config = %{@config | connect_on_start: false} - client = start_supervised!({GraphQLWSClient, config}) + {:ok, client} = GraphQLWSClient.start_link(config) error = %SocketError{cause: :closed} assert_raise SocketError, Exception.message(error), fn -> @@ -925,7 +926,9 @@ defmodule GraphQLWSClientTest do end test "ignore message when not connected", %{client: client, conn: conn} do - stub(MockDriver, :disconnect, fn ^conn -> :ok end) + expect(MockDriver, :disconnect, fn ^conn -> + :ok + end) :ok = GraphQLWSClient.close(client) refute GraphQLWSClient.connected?(client)