BigW Consortium Gitlab

admin_health_check_spec.rb 1.55 KB
Newer Older
1 2 3
require 'spec_helper'

feature "Admin Health Check", feature: true do
4
  include StubENV
5 6

  before do
7
    stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')
8 9 10 11 12 13 14 15
    login_as :admin
  end

  describe '#show' do
    before do
      visit admin_health_check_path
    end

16
    it 'has a health check access token' do
17 18 19
      page.has_text? 'Health Check'
      page.has_text? 'Health information can be retrieved'

20
      token = current_application_settings.health_check_access_token
21

22 23 24 25
      expect(page).to have_content("Access token is #{token}")
      expect(page).to have_selector('#health-check-token', text: token)
    end

26
    describe 'reload access token' do
27 28 29
      it 'changes the access token' do
        orig_token = current_application_settings.health_check_access_token
        click_button 'Reset health check access token'
30 31

        expect(page).to have_content('New health check access token has been generated!')
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
        expect(find('#health-check-token').text).not_to eq orig_token
      end
    end
  end

  context 'when services are up' do
    before do
      visit admin_health_check_path
    end

    it 'shows healthy status' do
      expect(page).to have_content('Current Status: Healthy')
    end
  end

  context 'when a service is down' do
    before do
      allow(HealthCheck::Utils).to receive(:process_checks).and_return('The server is on fire')
      visit admin_health_check_path
    end

    it 'shows unhealthy status' do
      expect(page).to have_content('Current Status: Unhealthy')
      expect(page).to have_content('The server is on fire')
    end
  end
end