Skip to content

Commit 763382e

Browse files
committed
Added CI +updated Airport direct connection + updated test files format
1 parent 8db1a3b commit 763382e

File tree

5 files changed

+78
-38
lines changed

5 files changed

+78
-38
lines changed

.github/workflows/ci.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Continuous Integration
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
schedule:
9+
- cron: "50 9 * * *"
10+
11+
jobs:
12+
run_tests:
13+
name: Run Tests
14+
runs-on: ubuntu-latest
15+
env:
16+
DB_CONN_STR: ${{ vars.DB_CONN_STR }}
17+
DB_USERNAME: ${{ vars.DB_USERNAME }}
18+
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
19+
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v4
23+
- name: Set up Ruby
24+
uses: ruby/setup-ruby@v1
25+
with:
26+
ruby-version: 3.3.0
27+
- name: Install dependencies
28+
run: bundle install
29+
30+
- name: Run tests
31+
run: bundle exec rspec test/integration
32+
33+
- name: Report Status
34+
if: always()
35+
uses: ravsamhq/notify-slack-action@v1
36+
with:
37+
status: ${{ job.status }}
38+
notify_when: "failure,warnings"
39+
notification_title: "Repo: *{repo}*"
40+
message_format: "{emoji} *{status_message}* in <{repo_url}|{repo}@{branch}> on <{commit_url}|{commit_sha}>"
41+
footer: "<{run_url}|View Full Run on GitHub>"
42+
env:
43+
SLACK_WEBHOOK_URL: ${{ secrets.ACTION_MONITORING_SLACK }}

app/controllers/api/v1/airports_controller.rb

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,21 +110,19 @@ def index
110110

111111
# GET /api/v1/airports/direct-connections
112112
def direct_connections
113-
raise ArgumentError, 'Source airport is missing' unless params[:sourceAirportCode].present?
113+
raise ArgumentError, 'Destination airport is missing' unless params[:destinationAirportCode].present?
114114

115-
source_airport = params[:sourceAirportCode]
115+
destination_airport = params[:destinationAirportCode]
116116
limit = params[:limit] || 10
117117
offset = params[:offset] || 0
118118

119-
begin
120-
destination_airports = Route.direct_connections(key: [source_airport, limit, offset])
121-
.pluck(:destinationairport)
122-
render json: destination_airports, status: :ok
123-
rescue ArgumentError => e
124-
render json: { error: 'Invalid request', message: e.message }, status: :bad_request
125-
rescue StandardError => e
126-
render json: { error: 'Internal server error', message: e.message }, status: :internal_server_error
127-
end
119+
destination_airports = Route.direct_connections(key: [destination_airport, limit, offset])
120+
.pluck(:destinationairport)
121+
render json: destination_airports, status: :ok
122+
rescue ArgumentError => e
123+
render json: { error: 'Invalid request', message: e.message }, status: :bad_request
124+
rescue StandardError => e
125+
render json: { error: 'Internal server error', message: e.message }, status: :internal_server_error
128126
end
129127

130128
private

config/couchbase.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
common: &common
2+
bucket: travel-sample
3+
connection_string: <%= ENV['DB_CONN_STR'] %>
4+
username: <%= ENV['DB_USERNAME'] %>
5+
password: <%= ENV['DB_PASSWORD'] %>
6+
7+
development:
28
connection_string: couchbase://localhost
39
username: kaustav
410
password: password
511

6-
development:
7-
<<: *common
8-
bucket: travel-sample
9-
1012
test:
1113
<<: *common
12-
bucket: travel-sample
1314

1415
production:
15-
<<: *common
16-
bucket: travel-sample
16+
<<: *common

test/integration/airlines_spec.rb

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -155,27 +155,25 @@
155155
end
156156

157157
describe 'GET /api/v1/airlines/list' do
158-
let(:country) { 'United States' }
158+
let(:country) { 'France' }
159159
let(:limit) { '10' }
160160
let(:offset) { '0' }
161+
161162
let(:expected_airlines) do
162163
[
163-
{ 'name' => '40-Mile Air', 'iata' => 'Q5', 'icao' => 'MLA', 'callsign' => 'MILE-AIR',
164-
'country' => 'United States' },
165-
{ 'name' => 'Texas Wings', 'iata' => 'TQ', 'icao' => 'TXW', 'callsign' => 'TXW', 'country' => 'United States' },
166-
{ 'name' => 'Atifly', 'iata' => 'A1', 'icao' => 'A1F', 'callsign' => 'atifly', 'country' => 'United States' },
167-
{ 'name' => 'Locair', 'iata' => 'ZQ', 'icao' => 'LOC', 'callsign' => 'LOCAIR', 'country' => 'United States' },
168-
{ 'name' => 'SeaPort Airlines', 'iata' => 'K5', 'icao' => 'SQH', 'callsign' => 'SASQUATCH',
169-
'country' => 'United States' },
170-
{ 'name' => 'Alaska Central Express', 'iata' => 'KO', 'icao' => 'AER', 'callsign' => 'ACE AIR',
171-
'country' => 'United States' },
172-
{ 'name' => 'AirTran Airways', 'iata' => 'FL', 'icao' => 'TRS', 'callsign' => 'CITRUS',
173-
'country' => 'United States' },
174-
{ 'name' => 'U.S. Air', 'iata' => '-+', 'icao' => '--+', 'callsign' => nil, 'country' => 'United States' },
175-
{ 'name' => 'PanAm World Airways', 'iata' => 'WQ', 'icao' => 'PQW', 'callsign' => nil,
176-
'country' => 'United States' },
177-
{ 'name' => 'Bemidji Airlines', 'iata' => 'CH', 'icao' => 'BMJ', 'callsign' => 'BEMIDJI',
178-
'country' => 'United States' }
164+
{ 'callsign' => 'REUNION', 'country' => 'France', 'iata' => 'UU', 'icao' => 'REU', 'name' => 'Air Austral' },
165+
{ 'callsign' => 'AIRLINAIR', 'country' => 'France', 'iata' => 'A5', 'icao' => 'RLA', 'name' => 'Airlinair' },
166+
{ 'callsign' => 'AIRFRANS', 'country' => 'France', 'iata' => 'AF', 'icao' => 'AFR', 'name' => 'Air France' },
167+
{ 'callsign' => 'AIRCALIN', 'country' => 'France', 'iata' => 'SB', 'icao' => 'ACI',
168+
'name' => 'Air Caledonie International' },
169+
{ 'callsign' => 'T&', 'country' => 'France', 'iata' => '&T', 'icao' => 'T&O',
170+
'name' => "Tom's & co airliners" },
171+
{ 'callsign' => 'BRITAIR', 'country' => 'France', 'iata' => 'DB', 'icao' => 'BZH', 'name' => 'Brit Air' },
172+
{ 'callsign' => 'Vickjet', 'country' => 'France', 'iata' => 'KT', 'icao' => 'VKJ', 'name' => 'VickJet' },
173+
{ 'callsign' => 'CORSAIR', 'country' => 'France', 'iata' => 'SS', 'icao' => 'CRL', 'name' => 'Corsairfly' },
174+
{ 'callsign' => 'CORSICA', 'country' => 'France', 'iata' => 'XK', 'icao' => 'CCM',
175+
'name' => 'Corse-Mediterranee' },
176+
{ 'callsign' => 'AIGLE AZUR', 'country' => 'France', 'iata' => 'ZI', 'icao' => 'AAF', 'name' => 'Aigle Azur' }
179177
]
180178
end
181179

test/integration/airports_spec.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,10 @@
192192
end
193193

194194
describe 'GET /api/v1/airports/direct-connections' do
195-
let(:destination_airport_code) { 'JFK' }
195+
let(:destination_airport_code) { 'LAX' }
196196
let(:limit) { 10 }
197197
let(:offset) { 0 }
198-
let(:expected_connections) { %w[DEL LHR EZE ATL CUN MEX LAX SAN SEA SFO] }
198+
let(:expected_connections) { %w[NRT CUN GDL HMO MEX MZT PVR SJD ZIH ZLO] }
199199

200200
context 'when the destination airport code is provided' do
201201
it 'returns the direct connections' do
@@ -213,7 +213,8 @@
213213
get '/api/v1/airports/direct-connections'
214214

215215
expect(response).to have_http_status(:bad_request)
216-
expect(JSON.parse(response.body)).to eq({ 'message' => 'Destination airport code is required' })
216+
expect(JSON.parse(response.body)).to eq({ 'error' => 'Invalid request',
217+
'message' => 'Destination airport is missing' })
217218
end
218219
end
219220
end

0 commit comments

Comments
 (0)