@@ -9,6 +9,7 @@ defmodule GraphQLWSClient.IteratorTest do
9
9
alias GraphQLWSClient.Iterator
10
10
alias GraphQLWSClient.Iterator.Opts
11
11
alias GraphQLWSClient.Message
12
+ alias GraphQLWSClient.SocketError
12
13
13
14
setup :set_mox_from_context
14
15
setup :verify_on_exit!
@@ -21,19 +22,18 @@ defmodule GraphQLWSClient.IteratorTest do
21
22
@ payload_2 % { "baz" => 23 }
22
23
23
24
setup do
24
- test_pid = self ( )
25
-
26
- expect ( MockDriver , :connect , fn @ conn ->
27
- send ( test_pid , :connected )
28
- { :ok , @ conn }
29
- end )
30
-
31
- client = start_supervised! ( { GraphQLWSClient , @ config } , id: :test_client )
32
- { :ok , client: client , test_pid: test_pid }
25
+ { :ok , test_pid: self ( ) }
33
26
end
34
27
35
28
describe "open!/4" do
36
- test "success" , % { client: client , test_pid: test_pid } do
29
+ test "success" , % { test_pid: test_pid } do
30
+ expect ( MockDriver , :connect , fn @ conn ->
31
+ send ( test_pid , :connected )
32
+ { :ok , @ conn }
33
+ end )
34
+
35
+ client = start_supervised! ( { GraphQLWSClient , @ config } , id: :test_client )
36
+
37
37
expect ( MockDriver , :push_message , fn @ conn ,
38
38
% Message {
39
39
type: :subscribe ,
@@ -51,15 +51,29 @@ defmodule GraphQLWSClient.IteratorTest do
51
51
assert_receive :subscribed
52
52
end
53
53
54
- test "non-numeric buffer size" , % { client: client } do
54
+ test "non-numeric buffer size" , % { test_pid: test_pid } do
55
+ expect ( MockDriver , :connect , fn @ conn ->
56
+ send ( test_pid , :connected )
57
+ { :ok , @ conn }
58
+ end )
59
+
60
+ client = start_supervised! ( { GraphQLWSClient , @ config } , id: :test_client )
61
+
55
62
assert_receive :connected
56
63
57
64
assert_raise ArgumentError , "invalid buffer size" , fn ->
58
65
Iterator . open! ( client , @ query , @ variables , buffer_size: "__invalid__" )
59
66
end
60
67
end
61
68
62
- test "negative buffer size" , % { client: client } do
69
+ test "negative buffer size" , % { test_pid: test_pid } do
70
+ expect ( MockDriver , :connect , fn @ conn ->
71
+ send ( test_pid , :connected )
72
+ { :ok , @ conn }
73
+ end )
74
+
75
+ client = start_supervised! ( { GraphQLWSClient , @ config } , id: :test_client )
76
+
63
77
assert_receive :connected
64
78
65
79
assert_raise ArgumentError , "invalid buffer size" , fn ->
@@ -69,8 +83,16 @@ defmodule GraphQLWSClient.IteratorTest do
69
83
end
70
84
71
85
describe "next/1" do
72
- setup % { client: client } do
86
+ setup % { test_pid: test_pid } do
87
+ expect ( MockDriver , :connect , fn @ conn ->
88
+ send ( test_pid , :connected )
89
+ { :ok , @ conn }
90
+ end )
91
+
92
+ client = start_supervised! ( { GraphQLWSClient , @ config } , id: :test_client )
93
+
73
94
{ :ok ,
95
+ client: client ,
74
96
opts: Opts . new ( client: client , query: @ query , variables: @ variables ) }
75
97
end
76
98
0 commit comments