Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F112725
param_test.exs
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
param_test.exs
View Options
defmodule
ParamTest
do
use
ExUnit.Case
describe
"Param"
do
test
"Valid Param"
do
conn
=
:get
|>
Plug.Test
.
conn
(
"/api/users?validParam=true"
)
|>
OpenApiSpexTest.Router
.
call
([])
assert
conn
.
status
==
200
end
test
"Invalid value"
do
conn
=
:get
|>
Plug.Test
.
conn
(
"/api/users?validParam=123"
)
|>
OpenApiSpexTest.Router
.
call
([])
assert
conn
.
status
==
422
end
test
"Invalid Param"
do
conn
=
:get
|>
Plug.Test
.
conn
(
"/api/users?validParam=123&inValidParam=123&inValid2=hi"
)
|>
OpenApiSpexTest.Router
.
call
([])
assert
conn
.
status
==
422
assert
conn
.
resp_body
==
"Undefined query parameter: \"inValid2\""
end
test
"with requestBody"
do
body
=
Poison
.
encode!
(%{
phone_number
:
"123-456-789"
,
postal_address
:
"123 Lane St"
})
conn
=
:post
|>
Plug.Test
.
conn
(
"/api/users/123/contact_info"
,
body
)
|>
Plug.Conn
.
put_req_header
(
"content-type"
,
"application/json"
)
|>
OpenApiSpexTest.Router
.
call
([])
assert
conn
.
status
==
200
end
end
describe
"Param with custom error handling"
do
test
"Valid Param"
do
conn
=
:get
|>
Plug.Test
.
conn
(
"/api/custom_error_users?validParam=true"
)
|>
OpenApiSpexTest.Router
.
call
([])
assert
conn
.
status
==
200
end
test
"Invalid value"
do
conn
=
:get
|>
Plug.Test
.
conn
(
"/api/custom_error_users?validParam=123"
)
|>
OpenApiSpexTest.Router
.
call
([])
assert
conn
.
status
==
400
end
test
"Invalid Param"
do
conn
=
:get
|>
Plug.Test
.
conn
(
"/api/custom_error_users?validParam=123&inValidParam=123&inValid2=hi"
)
|>
OpenApiSpexTest.Router
.
call
([])
assert
conn
.
status
==
400
assert
conn
.
resp_body
==
"Undefined query parameter: \"inValid2\""
end
end
end
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 23, 10:46 PM (21 h, 44 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
39178
Default Alt Text
param_test.exs (1 KB)
Attached To
Mode
R22 open_api_spex
Attached
Detach File
Event Timeline
Log In to Comment