scinote-web/spec/controllers/api/api_controller_spec.rb

46 lines
1.3 KiB
Ruby
Raw Normal View History

2017-08-30 00:49:07 +08:00
require 'rails_helper'
describe Api::ApiController, type: :controller do
describe 'GET #status' do
before do
get :status
end
it 'Returns HTTP success' do
expect(response).to have_http_status(200)
end
it 'Response with correct JSON status structure' do
hash_body = nil
expect { hash_body = json }.not_to raise_exception
2018-11-13 00:51:23 +08:00
expect(hash_body).to include(message: I18n.t('api.core.status_ok'))
expect(hash_body).to include('versions')
2018-11-13 00:51:23 +08:00
Extends::API_VERSIONS.each do |ver|
expect(hash_body['versions']).to include(
2018-11-13 00:51:23 +08:00
'version' => ver,
'baseUrl' => "/api/#{ver}/"
)
end
end
end
describe 'GET #health' do
before do
stub_request(:get, Rails.application.secrets.system_notifications_uri + '/api/system_notifications')
.with(query: hash_including('channels_slug': Rails.application.secrets.system_notifications_channel),
headers: { 'Accept': 'application/vnd.system-notifications.1+json' })
.to_return(status: 200, body: '', headers: {})
get :health
end
it 'Returns HTTP success' do
expect(response).to have_http_status(200)
end
it 'Response with the correct plain text' do
expect(response.body).to match('RUNNING')
2017-08-30 00:49:07 +08:00
end
end
end