forked from open-api-spex/open_api_spex
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoperation_test.exs
69 lines (60 loc) · 1.85 KB
/
operation_test.exs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
defmodule OpenApiSpex.OperationTest do
use ExUnit.Case
alias OpenApiSpexTest.Schemas
alias OpenApiSpex.Operation
alias OpenApiSpexTest.UserController
doctest Operation
describe "Operation" do
test "from_route %Phoenix.Router.Route{}" do
plug = UserController
plug_opts = :show
route =
Phoenix.Router.Route.build(
_line = nil,
_kind = :match,
_verb = :atom,
_path = nil,
_host = nil,
plug,
plug_opts,
_helper = nil,
_pipe_through = [],
_private = %{},
_assigns = %{},
_metadata = %{},
_trailing_slash? = false
)
assert Operation.from_route(route) ==
UserController.open_api_operation(:show)
end
test "from_route ~ phoenix v1.4.7+" do
route = %{plug: UserController, plug_opts: :show}
assert Operation.from_route(route) ==
UserController.open_api_operation(:show)
end
test "from_plug" do
assert Operation.from_plug(UserController, :show) ==
UserController.open_api_operation(:show)
end
test "response" do
assert %OpenApiSpex.Response{} =
Operation.response(
"A description for the response",
"application/json",
Schemas.User.schema().example
)
assert %OpenApiSpex.Response{} =
Operation.response(
"A description for the response",
"application/json",
Schemas.User.schema().example,
headers: %{
"content-length" => %OpenApiSpex.Header{
description: "The length of response",
example: "content-length: 42"
}
}
)
end
end
end