-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create rswag spec for reservations controller requests
- Loading branch information
1 parent
3afe9d3
commit 9b7c1f7
Showing
1 changed file
with
177 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
require 'swagger_helper' | ||
|
||
RSpec.describe 'api/reservations', type: :request do | ||
path '/api/v1/reservations' do | ||
|
||
get 'Retrieves reservations belonging to a user' do | ||
tags 'Get' | ||
produces 'application/json' | ||
|
||
response '200', 'reservation found' do | ||
let(:id) { create(:reservation).id } | ||
|
||
schema type: :object, | ||
properties: { | ||
status: { | ||
type: :object, | ||
properties: { | ||
code: { type: :integer }, | ||
message: { type: :string } | ||
} | ||
}, | ||
data: { | ||
type: :array, | ||
properties: [{ | ||
id: { type: :integer }, | ||
date: { type: :string }, | ||
}] | ||
} | ||
} | ||
|
||
run_test! | ||
end | ||
|
||
response '404', 'reservation not found' do | ||
let(:id) { 'invalid' } | ||
run_test! | ||
end | ||
end | ||
|
||
post 'Creates a reservation' do | ||
tags 'create' | ||
consumes 'application/json' | ||
produces 'application/json' | ||
parameter name: :reservation, in: :body, schema: { | ||
type: :object, | ||
properties: { | ||
date: { type: :string }, | ||
city_id: { type: :integer }, | ||
car_id: { type: :integer }, | ||
user_id: { type: :integer }, | ||
required: [ 'date', 'city_id', 'user_id', 'car_id' ] | ||
} | ||
} | ||
|
||
response '201', 'reservation created' do | ||
schema type: :object, | ||
properties: { | ||
status: { | ||
type: :object, | ||
properties: { | ||
code: { type: :integer }, | ||
message: { type: :string } | ||
} | ||
}, | ||
data: { | ||
type: :object, | ||
properties: { | ||
id: { type: :integer }, | ||
date: { type: :string }, | ||
} | ||
} | ||
} | ||
run_test! | ||
end | ||
|
||
end | ||
end | ||
|
||
path '/api/v1/reservations/{id}' do | ||
|
||
get 'Retrieves a reservation' do | ||
tags 'Get' | ||
produces 'application/json' | ||
parameter name: :id, in: :path, type: :string | ||
|
||
response '200', 'reservation found' do | ||
let(:id) { create(:reservation).id } | ||
|
||
schema type: :object, | ||
properties: { | ||
status: { | ||
type: :object, | ||
properties: { | ||
code: { type: :integer }, | ||
message: { type: :string } | ||
} | ||
}, | ||
data: { | ||
type: :object, | ||
properties: { | ||
id: { type: :integer }, | ||
date: { type: :string }, | ||
} | ||
} | ||
} | ||
|
||
run_test! | ||
end | ||
|
||
response '404', 'reservation not found' do | ||
let(:id) { 'invalid' } | ||
run_test! | ||
end | ||
end | ||
|
||
put 'Updates a reservation' do | ||
tags 'update' | ||
consumes 'application/json' | ||
produces 'application/json' | ||
parameter name: :city, in: :body, schema: { | ||
type: :object, | ||
properties: { | ||
date: { type: :string } | ||
} | ||
} | ||
parameter name: :id, in: :path, type: :string | ||
|
||
let(:id) { create(:reservation).id } | ||
|
||
response '200', 'reservation updated' do | ||
schema type: :object, | ||
properties: { | ||
status: { | ||
type: :object, | ||
properties: { | ||
code: { type: :integer }, | ||
message: { type: :string } | ||
} | ||
}, | ||
data: { | ||
type: :object, | ||
properties: { | ||
id: { type: :integer }, | ||
date: { type: :string }, | ||
} | ||
} | ||
} | ||
|
||
run_test! | ||
end | ||
end | ||
|
||
delete 'Deletes a reservation' do | ||
tags 'delete' | ||
produces 'application/json' | ||
parameter name: :id, in: :path, type: :string | ||
|
||
let(:id) { create(:reservation).id } | ||
|
||
response '200', 'reservation deleted' do | ||
schema type: :object, | ||
properties: { | ||
status: { | ||
type: :object, | ||
properties: { | ||
code: { type: :integer }, | ||
message: { type: :string } | ||
} | ||
}, | ||
} | ||
|
||
run_test! | ||
end | ||
end | ||
|
||
end | ||
end |