66from lunch_buddies .clients .slack import SlackClient
77from lunch_buddies .dao .polls import PollsDao
88from lunch_buddies .dao .teams import TeamsDao
9+ from lunch_buddies .dao .team_settings import TeamSettingsDao
910from lunch_buddies .dao .groups import GroupsDao
1011from lunch_buddies .models .teams import Team
1112import lunch_buddies .actions .notify_group as module
@@ -28,6 +29,13 @@ def test_notify_group(mocker):
2829 'created_at' : created_at .timestamp (),
2930 }]
3031 )
32+ team_settings_dao = TeamSettingsDao ()
33+ mocker .patch .object (
34+ team_settings_dao ,
35+ '_read_internal' ,
36+ auto_spec = True ,
37+ return_value = []
38+ )
3139 polls_dao = PollsDao ()
3240 mocker .patch .object (
3341 polls_dao ,
@@ -79,6 +87,7 @@ def test_notify_group(mocker):
7987 slack_client ,
8088 polls_dao ,
8189 teams_dao ,
90+ team_settings_dao ,
8291 groups_dao ,
8392 )
8493
@@ -104,5 +113,123 @@ def test_notify_group(mocker):
104113 ),
105114 channel = 'new_group_message_channel' ,
106115 as_user = True ,
107- text = 'Hello! This is your lunch group for today. You all should meet somewhere at `11:45`. I am selecting <@user_id_two> to be in charge of picking the location.' ,
116+ text = 'Hello! This is your group for today. You all should meet somewhere at `11:45`. I am selecting <@user_id_two> to be in charge of picking the location.' ,
117+ )
118+
119+
120+ def test_notify_group_feature_notify_in_channel (mocker ):
121+ slack_client = SlackClient ()
122+ teams_dao = TeamsDao ()
123+ created_at = datetime .now ()
124+ mocker .patch .object (
125+ teams_dao ,
126+ '_read_internal' ,
127+ auto_spec = True ,
128+ return_value = [{
129+ 'team_id' : '123' ,
130+ 'access_token' : 'fake-token' ,
131+ 'name' : 'fake-team-name' ,
132+ 'bot_access_token' : 'fake-bot-token' ,
133+ 'created_at' : created_at .timestamp (),
134+ }]
135+ )
136+ team_settings_dao = TeamSettingsDao ()
137+ mocker .patch .object (
138+ team_settings_dao ,
139+ '_read_internal' ,
140+ auto_spec = True ,
141+ return_value = [{
142+ 'team_id' : '123' ,
143+ 'feature_notify_in_channel' : 1 ,
144+ }]
108145 )
146+ polls_dao = PollsDao ()
147+ mocker .patch .object (
148+ polls_dao ,
149+ '_read_internal' ,
150+ auto_spec = True ,
151+ return_value = [
152+ {
153+ 'team_id' : '123' ,
154+ 'created_at' : datetime .now ().timestamp (),
155+ 'channel_id' : 'test_channel_id' ,
156+ 'created_by_user_id' : 'foo' ,
157+ 'callback_id' : 'f0d101f9-9aaa-4899-85c8-aa0a2dbb07cb' ,
158+ 'state' : polls_constants .CREATED ,
159+ 'choices' : '[{"key": "yes_1145", "is_yes": true, "time": "11:45", "display_text": "Yes (11:45)"}, {"key": "no", "is_yes": false, "time": "", "display_text": "No"}]' ,
160+ 'group_size' : polls_constants .DEFAULT_GROUP_SIZE ,
161+ },
162+ ]
163+ )
164+
165+ groups_dao = GroupsDao ()
166+ mocked_groups_dao_create_internal = mocker .patch .object (
167+ groups_dao ,
168+ '_create_internal' ,
169+ auto_spec = True ,
170+ return_value = True ,
171+ )
172+
173+ mocked_post_message = mocker .patch .object (
174+ slack_client ,
175+ 'post_message' ,
176+ auto_spec = True ,
177+ return_value = {
178+ 'ts' : 'fake_thread_ts' ,
179+ },
180+ )
181+ random .seed (0 )
182+
183+ module .notify_group (
184+ GroupsToNotifyMessage (
185+ team_id = '123' ,
186+ callback_id = UUID ('f0d101f9-9aaa-4899-85c8-aa0a2dbb07cb' ),
187+ response = 'yes_1145' ,
188+ user_ids = ['user_id_one' , 'user_id_two' ],
189+ ),
190+ slack_client ,
191+ polls_dao ,
192+ teams_dao ,
193+ team_settings_dao ,
194+ groups_dao ,
195+ )
196+
197+ expected_group = {
198+ 'callback_id' : 'f0d101f9-9aaa-4899-85c8-aa0a2dbb07cb' ,
199+ 'user_ids' : '["user_id_one", "user_id_two"]' ,
200+ 'response_key' : 'yes_1145' ,
201+ }
202+
203+ mocked_groups_dao_create_internal .assert_called_with (
204+ expected_group ,
205+ )
206+
207+ assert mocked_post_message .call_count == 2
208+
209+ mocked_post_message .assert_has_calls ([
210+ mocker .call (
211+ team = Team (
212+ team_id = '123' ,
213+ access_token = 'fake-token' ,
214+ name = 'fake-team-name' ,
215+ bot_access_token = 'fake-bot-token' ,
216+ created_at = created_at ,
217+ ),
218+ channel = 'test_channel_id' ,
219+ as_user = True ,
220+ text = 'Hey <@user_id_one>, <@user_id_two>! This is your group for today. You all should meet somewhere at `11:45`.' ,
221+ ),
222+ mocker .call (
223+ team = Team (
224+ team_id = '123' ,
225+ access_token = 'fake-token' ,
226+ name = 'fake-team-name' ,
227+ bot_access_token = 'fake-bot-token' ,
228+ created_at = created_at ,
229+ ),
230+ channel = 'test_channel_id' ,
231+ as_user = True ,
232+ thread_ts = 'fake_thread_ts' ,
233+ text = '<@user_id_two> should pick the location.' ,
234+ )
235+ ])
0 commit comments