Skip to content

Commit 48932a5

Browse files
blakenumbata
authored andcommitted
Add test
1 parent f0f2816 commit 48932a5

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
describe 'additional parameter settings' do
6+
before :all do
7+
module TheApi
8+
class RequestParamFix < Grape::API
9+
resource :bookings do
10+
desc 'Update booking'
11+
params do
12+
optional :name, type: String
13+
end
14+
put ':id' do
15+
{ 'declared_params' => declared(params) }
16+
end
17+
18+
desc 'Get booking details'
19+
get ':id' do
20+
{ 'declared_params' => declared(params) }
21+
end
22+
23+
desc 'Get booking details by access_number'
24+
get '/conf/:access_number' do
25+
{ 'declared_params' => declared(params) }
26+
end
27+
28+
desc 'Remove booking'
29+
delete ':id' do
30+
{ 'declared_params' => declared(params) }
31+
end
32+
end
33+
34+
add_swagger_documentation openapi_version: '3.0'
35+
end
36+
end
37+
end
38+
39+
def app
40+
TheApi::RequestParamFix
41+
end
42+
43+
subject do
44+
get '/swagger_doc'
45+
JSON.parse(last_response.body)
46+
end
47+
48+
specify do
49+
expect(subject['paths']['/bookings/{id}']['put']['parameters']).to eql(
50+
[
51+
{ 'in' => 'path', 'name' => 'id', 'schema' => { 'format' => 'int32', 'type' => 'integer' }, 'required' => true },
52+
]
53+
)
54+
55+
expect(subject['paths']['/bookings/{id}']['put']['requestBody']).to eql('content' => {
56+
'application/x-www-form-urlencoded' => {
57+
'schema' => {
58+
'properties' => { 'name' => { 'type' => 'string' } },
59+
'type' => 'object'
60+
}
61+
}
62+
})
63+
end
64+
65+
specify do
66+
expect(subject['paths']['/bookings/{id}']['get']['parameters']).to eql(
67+
[
68+
{ 'in' => 'path', 'name' => 'id', 'schema' => { 'format' => 'int32', 'type' => 'integer' }, 'required' => true }
69+
]
70+
)
71+
end
72+
73+
specify do
74+
expect(subject['paths']['/bookings/{id}']['delete']['parameters']).to eql(
75+
[
76+
{ 'in' => 'path', 'name' => 'id', 'schema' => { 'format' => 'int32', 'type' => 'integer' }, 'required' => true }
77+
]
78+
)
79+
end
80+
end

0 commit comments

Comments
 (0)