@@ -6,9 +6,11 @@ defmodule ExVCR.Adapter.FinchTest do
6
6
7
7
setup_all do
8
8
HttpServer . start ( path: "/server" , port: @ port , response: "test_response" )
9
- on_exit fn ->
9
+
10
+ on_exit ( fn ->
10
11
HttpServer . stop ( @ port )
11
- end
12
+ end )
13
+
12
14
:ok
13
15
end
14
16
@@ -17,17 +19,20 @@ defmodule ExVCR.Adapter.FinchTest do
17
19
ExVCR.Actor.CurrentRecorder . default_state ( )
18
20
|> ExVCR.Actor.CurrentRecorder . set ( )
19
21
end
22
+
20
23
url = "http://localhost:#{ @ port } /server"
21
24
{ :ok , response } = Finch . build ( :get , url ) |> Finch . request ( ExVCRFinch )
22
25
assert response . status == 200
23
26
end
24
27
25
28
test "passthrough works after cassette has been used" do
26
29
url = "http://localhost:#{ @ port } /server"
30
+
27
31
use_cassette "finch_get_localhost" do
28
32
{ :ok , response } = Finch . build ( :get , url ) |> Finch . request ( ExVCRFinch )
29
33
assert response . status == 200
30
34
end
35
+
31
36
{ :ok , response } = Finch . build ( :get , url ) |> Finch . request ( ExVCRFinch )
32
37
assert response . status == 200
33
38
end
@@ -63,7 +68,11 @@ defmodule ExVCR.Adapter.FinchTest do
63
68
test "request with HTTPError" do
64
69
use_cassette "finch_httperror" , custom: true do
65
70
{ :error , response } = Finch . build ( :get , "http://example.com/" ) |> Finch . request ( ExVCRFinch )
66
- assert response == % Mint.HTTPError { module: Mint.HTTP2 , reason: :too_many_concurrent_requests }
71
+
72
+ assert response == % Mint.HTTPError {
73
+ module: Mint.HTTP2 ,
74
+ reason: :too_many_concurrent_requests
75
+ }
67
76
end
68
77
end
69
78
@@ -90,31 +99,84 @@ defmodule ExVCR.Adapter.FinchTest do
90
99
91
100
test "post method" do
92
101
use_cassette "finch_post" do
93
- assert_response Finch . build ( :post , "http://httpbin.org/post" , [ ] , "test" ) |> Finch . request ( ExVCRFinch )
102
+ assert_response (
103
+ Finch . build ( :post , "http://httpbin.org/post" , [ ] , "test" )
104
+ |> Finch . request ( ExVCRFinch )
105
+ )
106
+ end
107
+ end
108
+
109
+ @ tag :wip
110
+ test "post method with json body" do
111
+ use_cassette "finch_post_map" do
112
+ assert_response (
113
+ Finch . build (
114
+ :post ,
115
+ "http://httpbin.org/post" ,
116
+ [ ] ,
117
+ JSX . encode! ( % {
118
+ name: "John" ,
119
+ age: 30 ,
120
+ city: "New York" ,
121
+ country: "USA" ,
122
+ isMarried: true ,
123
+ hobbies: [ "reading" , "traveling" , "swimming" ] ,
124
+ address: % {
125
+ street: "123 Main St" ,
126
+ city: "Los Angeles" ,
127
+ state: "CA" ,
128
+ zip: "90001"
129
+ } ,
130
+ phoneNumbers: [
131
+ % {
132
+ type: "home" ,
133
+ number: "555-555-1234"
134
+ } ,
135
+ % {
136
+ type: "work" ,
137
+ number: "555-555-5678"
138
+ }
139
+ ] ,
140
+ favoriteColor: "blue"
141
+ } )
142
+ )
143
+ |> Finch . request ( ExVCRFinch )
144
+ )
94
145
end
95
146
end
96
147
97
148
test "put method" do
98
149
use_cassette "finch_put" do
99
- assert_response Finch . build ( :put , "http://httpbin.org/put" , [ ] , "test" ) |> Finch . request ( ExVCRFinch , receive_timeout: 10_000 )
150
+ assert_response (
151
+ Finch . build ( :put , "http://httpbin.org/put" , [ ] , "test" )
152
+ |> Finch . request ( ExVCRFinch , receive_timeout: 10_000 )
153
+ )
100
154
end
101
155
end
102
156
103
157
test "patch method" do
104
158
use_cassette "finch_patch" do
105
- assert_response Finch . build ( :patch , "http://httpbin.org/patch" , [ ] , "test" ) |> Finch . request ( ExVCRFinch )
159
+ assert_response (
160
+ Finch . build ( :patch , "http://httpbin.org/patch" , [ ] , "test" )
161
+ |> Finch . request ( ExVCRFinch )
162
+ )
106
163
end
107
164
end
108
165
109
166
test "delete method" do
110
167
use_cassette "finch_delete" do
111
- assert_response Finch . build ( :delete , "http://httpbin.org/delete" ) |> Finch . request ( ExVCRFinch , receive_timeout: 10_000 )
168
+ assert_response (
169
+ Finch . build ( :delete , "http://httpbin.org/delete" )
170
+ |> Finch . request ( ExVCRFinch , receive_timeout: 10_000 )
171
+ )
112
172
end
113
173
end
114
174
115
175
test "get fails with timeout" do
116
176
use_cassette "finch_get_timeout" do
117
- { :error , error } = Finch . build ( :get , "http://example.com" ) |> Finch . request ( ExVCRFinch , receive_timeout: 1 )
177
+ { :error , error } =
178
+ Finch . build ( :get , "http://example.com" ) |> Finch . request ( ExVCRFinch , receive_timeout: 1 )
179
+
118
180
assert error == % Mint.TransportError { reason: :timeout }
119
181
end
120
182
end
@@ -128,13 +190,15 @@ defmodule ExVCR.Adapter.FinchTest do
128
190
129
191
use_cassette "example_finch_different" do
130
192
assert_raise ExVCR.RequestNotMatchError , ~r/ different_from_original/ , fn ->
131
- { :ok , _response } = Finch . build ( :get , "http://example.com/different_from_original" ) |> Finch . request ( ExVCRFinch )
193
+ { :ok , _response } =
194
+ Finch . build ( :get , "http://example.com/different_from_original" )
195
+ |> Finch . request ( ExVCRFinch )
132
196
end
133
197
end
134
198
end
135
199
136
200
test "stub request works for Finch" do
137
- use_cassette :stub , [ url: "http://example.com/" , body: "Stub Response" , status_code: 200 ] do
201
+ use_cassette :stub , url: "http://example.com/" , body: "Stub Response" , status_code: 200 do
138
202
{ :ok , response } = Finch . build ( :get , "http://example.com" ) |> Finch . request ( ExVCRFinch )
139
203
assert response . body =~ ~r/ Stub Response/
140
204
assert Map . new ( response . headers ) [ "content-type" ] == "text/html"
0 commit comments