Skip to content

Commit

Permalink
Create rswag spec for reservations controller requests
Browse files Browse the repository at this point in the history
  • Loading branch information
simplegoose committed Feb 20, 2024
1 parent 3afe9d3 commit 9b7c1f7
Showing 1 changed file with 177 additions and 0 deletions.
177 changes: 177 additions & 0 deletions spec/requests/api/reservations_spec.rb
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

0 comments on commit 9b7c1f7

Please sign in to comment.