|
13 | 13 | expect(status.teams_count).to eq 0 |
14 | 14 | end |
15 | 15 |
|
| 16 | + it 'selects an active installation even when inactive records surround it' do |
| 17 | + Fabricate(:team, active: false) |
| 18 | + active = Fabricate(:team, active: true) |
| 19 | + Fabricate(:team, active: false) |
| 20 | + allow_any_instance_of(Team).to receive(:ping!) do |record| |
| 21 | + expect(record.id).to eq active.id |
| 22 | + { ok: 1 } |
| 23 | + end |
| 24 | + expect(client.status.ping['ok']).to eq 1 |
| 25 | + end |
| 26 | + |
16 | 27 | context 'with a team' do |
17 | | - let!(:team) { Fabricate(:team, active: false) } |
| 28 | + let!(:team) { Fabricate(:team, active: true) } |
18 | 29 | it 'returns a status with ping' do |
19 | 30 | status = client.status |
20 | 31 | expect(status.teams_count).to eq 1 |
21 | 32 | ping = status.ping |
22 | 33 | expect(ping['ok']).to eq 1 |
23 | 34 | end |
| 35 | + |
| 36 | + %w[account_inactive invalid_auth].each do |error| |
| 37 | + context "when Slack returns #{error}" do |
| 38 | + before do |
| 39 | + allow_any_instance_of(Team).to receive(:ping!).and_raise(Slack::Web::Api::Errors::SlackError, error) |
| 40 | + end |
| 41 | + |
| 42 | + it 'deactivates the installation and returns an explicit failed ping' do |
| 43 | + expect(SlackRubyBotServer::Service.instance).to receive(:deactivate!).with(instance_of(Team)).and_call_original |
| 44 | + get '/api/status' |
| 45 | + status = JSON.parse(last_response.body) |
| 46 | + expect(last_response.status).to eq 200 |
| 47 | + expect(status['ping']).to eq('ok' => false, 'error' => error) |
| 48 | + expect(status['active_teams_count']).to eq 0 |
| 49 | + expect(team.reload.active?).to be false |
| 50 | + end |
| 51 | + end |
| 52 | + end |
| 53 | + |
| 54 | + it 'does not hide unrelated Slack failures or deactivate the installation' do |
| 55 | + allow_any_instance_of(Team).to receive(:ping!).and_raise(Slack::Web::Api::Errors::SlackError, 'ratelimited') |
| 56 | + get '/api/status' |
| 57 | + expect(last_response.status).to eq 400 |
| 58 | + expect(JSON.parse(last_response.body)['message']).to eq 'ratelimited' |
| 59 | + expect(team.reload.active?).to be true |
| 60 | + end |
| 61 | + end |
| 62 | + |
| 63 | + context 'with only inactive teams' do |
| 64 | + before { Fabricate(:team, active: false) } |
| 65 | + |
| 66 | + it 'does not ping revoked credentials' do |
| 67 | + expect_any_instance_of(Team).not_to receive(:ping!) |
| 68 | + get '/api/status' |
| 69 | + status = JSON.parse(last_response.body) |
| 70 | + expect(last_response.status).to eq 200 |
| 71 | + expect(status['ping']).to be_nil |
| 72 | + expect(status['teams_count']).to eq 1 |
| 73 | + expect(status['active_teams_count']).to eq 0 |
| 74 | + end |
24 | 75 | end |
25 | 76 | end |
26 | 77 | end |
0 commit comments