summaryrefslogtreecommitdiff
path: root/spec/controllers/health_controller_spec.rb
blob: e7c19b47a6ac09f256e6f5e7611d63220e975f15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
require 'spec_helper'

describe HealthController do
  include StubENV

  let(:token) { current_application_settings.health_check_access_token }
  let(:json_response) { JSON.parse(response.body) }

  before do
    stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')
  end

  describe '#readiness' do
    context 'authorization token provided' do
      before do
        request.headers['TOKEN'] = token
      end

      it 'returns proper response' do
        get :readiness
        expect(json_response['db_check']['status']).to eq('ok')
        expect(json_response['redis_check']['status']).to eq('ok')
        expect(json_response['fs_shards_check']['status']).to eq('ok')
        expect(json_response['fs_shards_check']['labels']['shard']).to eq('default')
      end
    end

    context 'without authorization token' do
      it 'returns proper response' do
        get :readiness
        expect(response.status).to eq(404)
      end
    end
  end

  describe '#liveness' do
    context 'authorization token provided' do
      before do
        request.headers['TOKEN'] = token
      end

      it 'returns proper response' do
        get :liveness
        expect(json_response['db_check']['status']).to eq('ok')
        expect(json_response['redis_check']['status']).to eq('ok')
        expect(json_response['fs_shards_check']['status']).to eq('ok')
      end
    end

    context 'without authorization token' do
      it 'returns proper response' do
        get :liveness
        expect(response.status).to eq(404)
      end
    end
  end
end