Skip to content

Commit

Permalink
Send message to user if the close incident command is not ran from an…
Browse files Browse the repository at this point in the history
… incident channel (#370)

* Adding message if you are not in an incident channel

* Adding logic that if the close incident command is not in an incident channel, a private message to the user is posted indicating that it should be ran from an incident channel

* Removing print statements
  • Loading branch information
sylviamclaughlin authored Jan 18, 2024
1 parent 4ac2b57 commit aeb2031
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
9 changes: 9 additions & 0 deletions app/commands/helpers/incident_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,15 @@ def close_incident(client, body, ack):
channel_id = body["channel_id"]
channel_name = body["channel_name"]

if not channel_name.startswith("incident-"):
user_id = body["user_id"]
client.chat_postEphemeral(
text=f"Channel {channel_name} is not an incident channel. Please use this command in an incident channel.",
channel=channel_id,
user=user_id,
)
return

# get and update the incident document
document_id = ""
response = client.bookmarks_list(channel_id=channel_id)
Expand Down
29 changes: 29 additions & 0 deletions app/tests/commands/helpers/test_incident_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,35 @@ def test_close_incident_no_bookmarks(
mock_update_spreadsheet.assert_called_once_with("#2024-01-12-test")


# Test that the channel that the command is ran in, is not an incident channel.
def test_close_incident_not_incident_channel():
mock_client = MagicMock()
mock_ack = MagicMock()

# Mock the response of the private message to have been posted as expected
mock_client.chat_postEphemeral.return_value = {"ok": True}

# Call close_incident
incident_helper.close_incident(
mock_client,
{
"channel_id": "C12345",
"user_id": "12345",
"channel_name": "some-other-channel",
},
mock_ack,
)

# Assert that ack was called
mock_ack.assert_called_once()

# Assert that the private message was posted as expected with the expected text
expected_text = "Channel some-other-channel is not an incident channel. Please use this command in an incident channel."
mock_client.chat_postEphemeral.assert_called_once_with(
channel="C12345", user="12345", text=expected_text
)


@patch("commands.helpers.incident_helper.google_drive.close_incident_document")
@patch(
"commands.helpers.incident_helper.google_drive.update_spreadsheet_close_incident"
Expand Down

0 comments on commit aeb2031

Please sign in to comment.