2024-11-01 15:49:59 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
|
|
RSpec.describe 'Api::V1::Countries::Borders', type: :request do
|
|
|
|
|
describe 'GET /index' do
|
2025-08-07 19:19:59 -04:00
|
|
|
context 'when user is not authenticated' do
|
|
|
|
|
it 'returns http unauthorized' do
|
|
|
|
|
get '/api/v1/countries/borders'
|
|
|
|
|
|
|
|
|
|
expect(response).to have_http_status(:unauthorized)
|
|
|
|
|
end
|
2025-08-10 18:21:58 -04:00
|
|
|
|
|
|
|
|
it 'returns X-Dawarich-Response header' do
|
|
|
|
|
get '/api/v1/countries/borders'
|
|
|
|
|
|
|
|
|
|
expect(response.headers['X-Dawarich-Response']).to eq('Hey, I\'m alive!')
|
|
|
|
|
expect(response.headers['X-Dawarich-Version']).to eq(APP_VERSION)
|
|
|
|
|
end
|
2025-08-07 19:19:59 -04:00
|
|
|
end
|
2025-08-10 06:05:34 -04:00
|
|
|
|
|
|
|
|
context 'when user is authenticated' do
|
2025-08-10 06:28:32 -04:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
2025-08-10 06:05:34 -04:00
|
|
|
it 'returns a list of countries with borders' do
|
|
|
|
|
get '/api/v1/countries/borders', headers: { 'Authorization' => "Bearer #{user.api_key}" }
|
|
|
|
|
|
|
|
|
|
expect(response).to have_http_status(:success)
|
|
|
|
|
expect(response.body).to include('AF')
|
|
|
|
|
expect(response.body).to include('ZW')
|
|
|
|
|
end
|
2025-08-10 18:21:58 -04:00
|
|
|
|
|
|
|
|
it 'returns X-Dawarich-Response header' do
|
|
|
|
|
get '/api/v1/countries/borders', headers: { 'Authorization' => "Bearer #{user.api_key}" }
|
|
|
|
|
|
|
|
|
|
expect(response.headers['X-Dawarich-Response']).to eq('Hey, I\'m alive and authenticated!')
|
|
|
|
|
expect(response.headers['X-Dawarich-Version']).to eq(APP_VERSION)
|
|
|
|
|
end
|
2024-11-01 15:49:59 -04:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|