Skip to content

Commit

Permalink
Adding files so that the person archiving the channel is displayed in…
Browse files Browse the repository at this point in the history
… the archived channel.
  • Loading branch information
sylviamclaughlin authored Mar 26, 2024
1 parent 8e9bec0 commit c621ec1
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 6 deletions.
8 changes: 7 additions & 1 deletion app/modules/incident/incident_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,9 @@ def close_incident(client, body, ack):
# get the current chanel id and name
channel_id = body["channel_id"]
channel_name = body["channel_name"]
user_id = body["user_id"]

if not channel_name.startswith("incident-"):
user_id = body["user_id"]
try:
response = client.chat_postEphemeral(
text=f"Channel {channel_name} is not an incident channel. Please use this command in an incident channel.",
Expand Down Expand Up @@ -352,6 +352,12 @@ def close_incident(client, body, ack):
logging.error(
"Could not archive the channel %s - %s", channel_name, response["error"]
)
else:
# post a message that the channel has been archived by the user
client.chat_postMessage(
channel=channel_id,
text=f"<@{user_id}> has archived this channel 👋",
)


def stale_incidents(client, body, ack):
Expand Down
76 changes: 71 additions & 5 deletions app/tests/modules/incident/test_incident_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,11 @@ def test_close_incident(mock_extract_id, mock_update_spreadsheet, mock_close_doc
# Call close_incident
incident_helper.close_incident(
mock_client,
{"channel_id": "C12345", "channel_name": "incident-2024-01-12-test"},
{
"channel_id": "C12345",
"channel_name": "incident-2024-01-12-test",
"user_id": "U12345",
},
mock_ack,
)

Expand Down Expand Up @@ -479,7 +483,11 @@ def test_close_incident_no_bookmarks(
# Call close_incident
incident_helper.close_incident(
mock_client,
{"channel_id": "C12345", "channel_name": "incident-2024-01-12-test"},
{
"channel_id": "C12345",
"channel_name": "incident-2024-01-12-test",
"user_id": "U12345",
},
mock_ack,
)

Expand Down Expand Up @@ -508,7 +516,11 @@ def test_close_incident_no_bookmarks_error(
# Call close_incident
incident_helper.close_incident(
mock_client,
{"channel_id": "C12345", "channel_name": "incident-2024-01-12-test"},
{
"channel_id": "C12345",
"channel_name": "incident-2024-01-12-test",
"user_id": "U12345",
},
mock_ack,
)

Expand Down Expand Up @@ -622,7 +634,11 @@ def test_conversations_archive_fail(
# Call close_incident
incident_helper.close_incident(
mock_client,
{"channel_id": "C12345", "channel_name": "incident-2024-01-12-test"},
{
"channel_id": "C12345",
"channel_name": "incident-2024-01-12-test",
"user_id": "U12345",
},
mock_ack,
)

Expand Down Expand Up @@ -669,7 +685,11 @@ def test_conversations_archive_fail_error_message(
# Call close_incident
incident_helper.close_incident(
mock_client,
{"channel_id": "C12345", "channel_name": "incident-2024-01-12-test"},
{
"channel_id": "C12345",
"channel_name": "incident-2024-01-12-test",
"user_id": "U12345",
},
mock_ack,
)

Expand All @@ -687,6 +707,52 @@ def test_conversations_archive_fail_error_message(
)


@patch("modules.incident.incident_helper.google_drive.close_incident_document")
@patch(
"modules.incident.incident_helper.google_drive.update_spreadsheet_close_incident"
)
@patch(
"integrations.google_workspace.google_docs.extract_google_doc_id",
return_value="dummy_document_id",
)
def test_conversations_archive_succeeds_post_message_who_archived(
mock_extract_id, mock_update_spreadsheet, mock_close_document, caplog
):
mock_client = MagicMock()
mock_ack = MagicMock()
body = {
"channel_id": "channel_id",
"channel_name": "incident-channel_name",
"user_id": "user_id",
}
incident_helper.close_incident(mock_client, body, mock_ack)

# Mock the response of client.bookmarks_list with a valid bookmark
mock_client.bookmarks_list.return_value = {
"ok": True,
"bookmarks": [
{
"title": "Incident report",
"link": "https://docs.google.com/document/d/dummy_document_id/edit",
}
],
}

# Mock the response of client.conversations_archive to indicate success
mock_client.conversations_archive.return_value = {
"ok": True,
}

# assert that the channel was archived
mock_client.conversations_archive.assert_called_once_with(channel="channel_id")

# assert message was posted to archived channel.
mock_client.chat_postMessage.assert_any_call(
text="<@user_id> has archived this channel 👋",
channel="channel_id",
)


def test_return_channel_name_with_prefix():
# Test the function with a string that includes the prefix.
assert incident_helper.return_channel_name("incident-abc123") == "#abc123"
Expand Down

0 comments on commit c621ec1

Please sign in to comment.