Skip to content

Commit

Permalink
Fix: avoid constantly pinging an inactive team for status.
Browse files Browse the repository at this point in the history
  • Loading branch information
dblock committed Jul 13, 2023
1 parent 3421681 commit 5165883
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion slack-gamebot/api/presenters/status_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def games
h[game.name][:matches_count] = game.matches.count
h[game.name][:seasons_count] = game.seasons.count
team = game.teams.active.asc(:_id).first
h[game.name][:ping] = team.ping! if team
h[game.name][:ping] = team.ping_if_active! if team
end
end

Expand Down
16 changes: 16 additions & 0 deletions spec/api/endpoints/status_endpoint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@
end
end

context 'with a team that has an inactive account' do
let!(:team) { Fabricate(:team, api: true, active: true) }
before do
expect_any_instance_of(Team).to receive(:ping!) { raise Slack::Web::Api::Errors::SlackError, 'account_inactive' }
end
it 'returns a status and deactivates team' do
status = client.status
expect(status.games_count).to eq 1
game = status.games[team.game.name]
expect(game['teams_count']).to eq 1
expect(game['active_teams_count']).to eq 1
expect(game['api_teams_count']).to eq 1
expect(team.reload.active).to be false
end
end

context 'with a team with api off' do
let!(:team) { Fabricate(:team, api: false) }
it 'returns total counts anyway' do
Expand Down

0 comments on commit 5165883

Please sign in to comment.