|
| 1 | +require 'swagger_helper' |
| 2 | + |
| 3 | +describe 'Airlines API', type: :request do |
| 4 | + path '/api/v1/airlines/{id}' do |
| 5 | + get 'Retrieves an airline by ID' do |
| 6 | + tags 'Airlines' |
| 7 | + produces 'application/json' |
| 8 | + parameter name: :id, in: :path, type: :string, description: 'ID of the airline' |
| 9 | + |
| 10 | + response '200', 'airline found' do |
| 11 | + schema type: :object, |
| 12 | + properties: { |
| 13 | + name: { type: :string }, |
| 14 | + iata: { type: :string }, |
| 15 | + icao: { type: :string }, |
| 16 | + callsign: { type: :string }, |
| 17 | + country: { type: :string } |
| 18 | + }, |
| 19 | + required: %w[name iata icao callsign country] |
| 20 | + |
| 21 | + let(:id) { 'airline_10' } |
| 22 | + run_test! |
| 23 | + end |
| 24 | + |
| 25 | + response '404', 'airline not found' do |
| 26 | + let(:id) { 'invalid_id' } |
| 27 | + run_test! |
| 28 | + end |
| 29 | + end |
| 30 | + |
| 31 | + post 'Creates an airline' do |
| 32 | + tags 'Airlines' |
| 33 | + consumes 'application/json' |
| 34 | + parameter name: :id, in: :path, type: :string, description: 'ID of the airline' |
| 35 | + parameter name: :airline, in: :body, schema: { |
| 36 | + type: :object, |
| 37 | + properties: { |
| 38 | + name: { type: :string }, |
| 39 | + iata: { type: :string }, |
| 40 | + icao: { type: :string }, |
| 41 | + callsign: { type: :string }, |
| 42 | + country: { type: :string } |
| 43 | + }, |
| 44 | + required: %w[name iata icao callsign country] |
| 45 | + } |
| 46 | + |
| 47 | + response '201', 'airline created' do |
| 48 | + let(:airline) { { name: 'Foo Airlines', iata: 'FA', icao: 'FOO', callsign: 'FOO', country: 'US' } } |
| 49 | + run_test! |
| 50 | + end |
| 51 | + |
| 52 | + response '400', 'bad request' do |
| 53 | + let(:airline) { { name: 'Foo Airlines', iata: 'FA', icao: 'FOO', callsign: 'FOO' } } |
| 54 | + run_test! |
| 55 | + end |
| 56 | + |
| 57 | + response '409', 'airline already exists' do |
| 58 | + let(:airline) { { name: 'Foo Airlines', iata: 'FA', icao: 'FOO', callsign: 'FOO', country: 'US' } } |
| 59 | + run_test! |
| 60 | + end |
| 61 | + end |
| 62 | + |
| 63 | + put 'Updates an airline' do |
| 64 | + tags 'Airlines' |
| 65 | + consumes 'application/json' |
| 66 | + parameter name: :id, in: :path, type: :string, description: 'ID of the airline' |
| 67 | + parameter name: :airline, in: :body, schema: { |
| 68 | + type: :object, |
| 69 | + properties: { |
| 70 | + name: { type: :string }, |
| 71 | + iata: { type: :string }, |
| 72 | + icao: { type: :string }, |
| 73 | + callsign: { type: :string }, |
| 74 | + country: { type: :string } |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | + response '200', 'airline updated' do |
| 79 | + let(:id) { 'airline_10' } |
| 80 | + let(:airline) { { name: 'Updated Airline' } } |
| 81 | + run_test! |
| 82 | + end |
| 83 | + |
| 84 | + response '400', 'bad request' do |
| 85 | + let(:id) { 'airline_10' } |
| 86 | + let(:airline) { { name: '' } } |
| 87 | + run_test! |
| 88 | + end |
| 89 | + end |
| 90 | + |
| 91 | + delete 'Deletes an airline' do |
| 92 | + tags 'Airlines' |
| 93 | + parameter name: :id, in: :path, type: :string, description: 'ID of the airline' |
| 94 | + |
| 95 | + response '204', 'airline deleted' do |
| 96 | + let(:id) { 'airline_10' } |
| 97 | + run_test! |
| 98 | + end |
| 99 | + |
| 100 | + response '404', 'airline not found' do |
| 101 | + let(:id) { 'invalid_id' } |
| 102 | + run_test! |
| 103 | + end |
| 104 | + end |
| 105 | + end |
| 106 | + |
| 107 | + path '/api/v1/airlines/list' do |
| 108 | + get 'Retrieves all airlines by country' do |
| 109 | + tags 'Airlines' |
| 110 | + produces 'application/json' |
| 111 | + parameter name: :country, in: :query, type: :string, description: 'Country of the airline' |
| 112 | + parameter name: :limit, in: :query, type: :integer, description: 'Maximum number of results to return' |
| 113 | + parameter name: :offset, in: :query, type: :integer, description: 'Number of results to skip for pagination' |
| 114 | + |
| 115 | + response '200', 'airlines found' do |
| 116 | + schema type: :array, |
| 117 | + items: { |
| 118 | + type: :object, |
| 119 | + properties: { |
| 120 | + name: { type: :string }, |
| 121 | + iata: { type: :string }, |
| 122 | + icao: { type: :string }, |
| 123 | + callsign: { type: :string }, |
| 124 | + country: { type: :string } |
| 125 | + }, |
| 126 | + required: %w[name iata icao callsign country] |
| 127 | + } |
| 128 | + |
| 129 | + let(:country) { 'United States' } |
| 130 | + let(:limit) { 10 } |
| 131 | + let(:offset) { 0 } |
| 132 | + run_test! |
| 133 | + end |
| 134 | + end |
| 135 | + end |
| 136 | + |
| 137 | + path '/api/v1/airlines/to-airport' do |
| 138 | + get 'Retrieves airlines flying to a destination airport' do |
| 139 | + tags 'Airlines' |
| 140 | + produces 'application/json' |
| 141 | + parameter name: :destinationAirportCode, in: :query, type: :string, |
| 142 | + description: 'The ICAO or IATA code of the destination airport' |
| 143 | + parameter name: :limit, in: :query, type: :integer, description: 'Maximum number of results to return' |
| 144 | + parameter name: :offset, in: :query, type: :integer, description: 'Number of results to skip for pagination' |
| 145 | + |
| 146 | + response '200', 'airlines found' do |
| 147 | + schema type: :array, |
| 148 | + items: { |
| 149 | + type: :object, |
| 150 | + properties: { |
| 151 | + name: { type: :string }, |
| 152 | + iata: { type: :string }, |
| 153 | + icao: { type: :string }, |
| 154 | + callsign: { type: :string }, |
| 155 | + country: { type: :string } |
| 156 | + }, |
| 157 | + required: %w[name iata icao callsign country] |
| 158 | + } |
| 159 | + |
| 160 | + let(:destinationAirportCode) { 'LAX' } |
| 161 | + let(:limit) { 10 } |
| 162 | + let(:offset) { 0 } |
| 163 | + run_test! |
| 164 | + end |
| 165 | + |
| 166 | + response '400', 'bad request' do |
| 167 | + let(:destinationAirportCode) { '' } |
| 168 | + run_test! |
| 169 | + end |
| 170 | + end |
| 171 | + end |
| 172 | +end |
0 commit comments