generated from cds-snc/project-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
40 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
from unittest.mock import MagicMock | ||
|
||
from integrations.slack import users | ||
from slack_sdk import WebClient | ||
|
||
|
||
def test_get_user_id_from_request_with_user_id(): | ||
|
@@ -127,3 +128,25 @@ def users_profile_get(user): | |
message = "Hello, <@U1234> and <@U5678>! Welcome to the team. Also welcome <@U9101> and <@U1121>." | ||
expected_message = "Hello, @john_doe and @jane_smith! Welcome to the team. Also welcome @joe_smith and @jenn_smith." | ||
assert users.replace_user_id_with_handle(client, message) == expected_message | ||
|
||
|
||
def test_get_user_email(): | ||
# Mock the WebClient | ||
client = MagicMock(spec=WebClient) | ||
|
||
# Test when the user ID is found in the request body and the users_info call is successful | ||
client.users_info.return_value = { | ||
"ok": True, | ||
"user": {"profile": {"email": "[email protected]"}}, | ||
} | ||
body = {"user_id": "U1234"} | ||
assert users.get_user_email(client, body) == "[email protected]" | ||
|
||
# Test when the user ID is not found in the request body | ||
body = {} | ||
assert users.get_user_email(client, body) is None | ||
|
||
# Test when the users_info call is not successful | ||
client.users_info.return_value = {"ok": False} | ||
body = {"user_id": "U1234"} | ||
assert users.get_user_email(client, body) is None |