|
| 1 | +import unittest |
| 2 | +from unittest.mock import MagicMock |
| 3 | + |
| 4 | +from handler.otp.arp_response import ArpOtpResponse |
| 5 | +from test.handler.bigchat.sample_data import create_sample_app_mention_event |
| 6 | + |
| 7 | + |
| 8 | +class TestArpOtpResponse(unittest.TestCase): |
| 9 | + def test_run(self): |
| 10 | + event = create_sample_app_mention_event("<@U01BN035Y6L> otp") |
| 11 | + mock_slack_client = MagicMock() |
| 12 | + mock_otp = MagicMock() |
| 13 | + mock_otp.issue_login_url.return_value = "https://arp.ausg.me/auth/otp?code=test" |
| 14 | + sut = ArpOtpResponse(event, mock_slack_client, mock_otp) |
| 15 | + |
| 16 | + result = sut.handle_mention() |
| 17 | + |
| 18 | + mock_otp.issue_login_url.assert_called_once_with("UQJ8HQJG5") |
| 19 | + mock_slack_client.send_message_only_visible_to_user.assert_called_once() |
| 20 | + kwargs = mock_slack_client.send_message_only_visible_to_user.call_args.kwargs |
| 21 | + assert kwargs["user_id"] == "UQJ8HQJG5" |
| 22 | + assert kwargs["channel"] == "C03SZTDEDK3" |
| 23 | + assert kwargs["ts"] == "1689403771.805849" |
| 24 | + assert "10분" in kwargs["msg"] |
| 25 | + assert result is True |
| 26 | + |
| 27 | + def test_not_run_by_command_notfound(self): |
| 28 | + event = create_sample_app_mention_event("<@U01BN035Y6L> help") |
| 29 | + mock_slack_client = MagicMock() |
| 30 | + mock_otp = MagicMock() |
| 31 | + sut = ArpOtpResponse(event, mock_slack_client, mock_otp) |
| 32 | + |
| 33 | + result = sut.handle_mention() |
| 34 | + |
| 35 | + mock_otp.assert_not_called() |
| 36 | + mock_slack_client.assert_not_called() |
| 37 | + assert result is False |
| 38 | + |
| 39 | + def test_not_run_when_otp_is_not_exact_command(self): |
| 40 | + event = create_sample_app_mention_event("<@U01BN035Y6L> help otp") |
| 41 | + mock_slack_client = MagicMock() |
| 42 | + mock_otp = MagicMock() |
| 43 | + sut = ArpOtpResponse(event, mock_slack_client, mock_otp) |
| 44 | + |
| 45 | + result = sut.handle_mention() |
| 46 | + |
| 47 | + mock_otp.assert_not_called() |
| 48 | + mock_slack_client.assert_not_called() |
| 49 | + assert result is False |
| 50 | + |
| 51 | + def test_run_by_config_error(self): |
| 52 | + event = create_sample_app_mention_event("<@U01BN035Y6L> otp") |
| 53 | + mock_slack_client = MagicMock() |
| 54 | + mock_otp = MagicMock() |
| 55 | + mock_otp.issue_login_url.side_effect = ValueError() |
| 56 | + sut = ArpOtpResponse(event, mock_slack_client, mock_otp) |
| 57 | + |
| 58 | + result = sut.handle_mention() |
| 59 | + |
| 60 | + mock_slack_client.send_message.assert_called_once() |
| 61 | + assert result is False |
0 commit comments