Skip to content

Commit

Permalink
More logging to indicate if a bookmark does not exist in an incident …
Browse files Browse the repository at this point in the history
…channel (#376)

* Add logging to figure out which channel does not have the bookmark

* Added more logging to see if the channel bookmark does not exist
  • Loading branch information
sylviamclaughlin authored Jan 29, 2024
1 parent 3216631 commit bc59633
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app/commands/helpers/incident_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,12 +305,19 @@ def close_incident(client, body, ack):
for item in range(len(response["bookmarks"])):
if response["bookmarks"][item]["title"] == "Incident report":
document_id = extract_google_doc_id(response["bookmarks"][item]["link"])
else:
logging.warning(
"No bookmark link for the incident document found for channel %s",
channel_name,
)

# Update the document status to "Closed" if we can get the document
if document_id != "":
google_drive.close_incident_document(document_id)
else:
logging.warning("No incident document found for this channel.")
logging.warning(
"Could not close the incident document - the document was not found."
)

# Update the spreadsheet with the current incident with status = closed
google_drive.update_spreadsheet_close_incident(return_channel_name(channel_name))
Expand Down
27 changes: 27 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,33 @@ def test_close_incident_no_bookmarks(
mock_update_spreadsheet.assert_called_once_with("#2024-01-12-test")


@patch("commands.helpers.incident_helper.google_drive.close_incident_document")
@patch(
"commands.helpers.incident_helper.google_drive.update_spreadsheet_close_incident"
)
@patch("commands.helpers.incident_helper.extract_google_doc_id", return_value=None)
def test_close_incident_no_bookmarks_error(
mock_extract_id, mock_update_spreadsheet, mock_close_document
):
mock_client = MagicMock()
mock_ack = MagicMock()

# Mock client.bookmarks_list to return no bookmarks
mock_client.bookmarks_list.return_value = {"ok": False, "error": "not_in_channel"}

# Call close_incident
incident_helper.close_incident(
mock_client,
{"channel_id": "C12345", "channel_name": "incident-2024-01-12-test"},
mock_ack,
)

# Assertions to ensure that document update functions are not called as there are no bookmarks
mock_extract_id.assert_not_called()
mock_close_document.assert_not_called()
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()
Expand Down

0 comments on commit bc59633

Please sign in to comment.