From 1c08aa6a8b93354363584e3fada60f67c339e64a Mon Sep 17 00:00:00 2001 From: Jure Grabnar Date: Mon, 12 Nov 2018 17:17:22 +0100 Subject: [PATCH] Add unit tests for status/health API endpoints Closes [SCI-2746]. --- spec/controllers/api/api_controller_spec.rb | 31 +++++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/spec/controllers/api/api_controller_spec.rb b/spec/controllers/api/api_controller_spec.rb index 68a7ec432..1bf4d1f37 100644 --- a/spec/controllers/api/api_controller_spec.rb +++ b/spec/controllers/api/api_controller_spec.rb @@ -13,12 +13,31 @@ describe Api::ApiController, type: :controller do it 'Response with correct JSON status structure' do hash_body = nil - expect { hash_body = json }.not_to raise_exception - expect(hash_body).to match( - 'message' => I18n.t('api.core.status_ok'), - 'versions' => [{ 'version' => 'v1', - 'baseUrl' => '/api/v1/' }] - ) + expect{hash_body = json}.not_to raise_exception + expect(hash_body).to include(:message => I18n.t('api.core.status_ok')) + expect(hash_body).to include('versions') + + Extends::API_VERSIONS.each_with_index do |ver, index| + expect(hash_body['versions']).to include( + { 'version' => ver, + 'baseUrl' => "/api/#{ver}/" } + ) + end + end + end + + describe 'GET #health' do + before do + get :health + end + + it 'Returns HTTP success' do + expect(response).to be_success + expect(response).to have_http_status(200) + end + + it 'Response with the correct plain text' do + expect(response.body).to match('RUNNING') end end end