Skip to content

Commit dc48378

Browse files
authored
Fix #468 Replying with 0 results for a multi-select external option display previous successful results (#580)
1 parent 8c0532d commit dc48378

File tree

3 files changed

+84
-2
lines changed

3 files changed

+84
-2
lines changed

slack_bolt/context/ack/internals.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ def _set_response(
4242
elif blocks and len(blocks) > 0:
4343
body.update({"text": text, "blocks": convert_to_dict_list(blocks)})
4444
self.response = BoltResponse(status=200, body=body)
45-
elif options and len(options) > 0:
45+
elif options is not None:
4646
body = {"options": convert_to_dict_list(options)}
4747
self.response = BoltResponse(status=200, body=body)
48-
elif option_groups and len(option_groups) > 0:
48+
elif option_groups is not None:
4949
body = {"option_groups": convert_to_dict_list(option_groups)}
5050
self.response = BoltResponse(status=200, body=body)
5151
elif response_action:

tests/scenario_tests/test_block_suggestion.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,34 @@ def test_failure_multi(self):
180180
assert response.status == 404
181181
assert_auth_test_count(self, 1)
182182

183+
def test_empty_options(self):
184+
app = App(
185+
client=self.web_client,
186+
signing_secret=self.signing_secret,
187+
)
188+
app.options("mes_a")(show_empty_options)
189+
190+
request = self.build_valid_multi_request()
191+
response = app.dispatch(request)
192+
assert response.status == 200
193+
assert response.body == """{"options": []}"""
194+
assert response.headers["content-type"][0] == "application/json;charset=utf-8"
195+
assert_auth_test_count(self, 1)
196+
197+
def test_empty_option_groups(self):
198+
app = App(
199+
client=self.web_client,
200+
signing_secret=self.signing_secret,
201+
)
202+
app.options("mes_a")(show_empty_option_groups)
203+
204+
request = self.build_valid_multi_request()
205+
response = app.dispatch(request)
206+
assert response.status == 200
207+
assert response.body == """{"option_groups": []}"""
208+
assert response.headers["content-type"][0] == "application/json;charset=utf-8"
209+
assert_auth_test_count(self, 1)
210+
183211

184212
body = {
185213
"type": "block_suggestion",
@@ -296,3 +324,15 @@ def show_multi_options(ack, body, payload, options):
296324
assert body == options
297325
assert payload == options
298326
ack(multi_response)
327+
328+
329+
def show_empty_options(ack, body, payload, options):
330+
assert body == options
331+
assert payload == options
332+
ack(options=[])
333+
334+
335+
def show_empty_option_groups(ack, body, payload, options):
336+
assert body == options
337+
assert payload == options
338+
ack(option_groups=[])

tests/scenario_tests_async/test_block_suggestion.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,36 @@ async def test_failure_multi(self):
195195
assert response.status == 404
196196
await assert_auth_test_count_async(self, 1)
197197

198+
@pytest.mark.asyncio
199+
async def test_empty_options(self):
200+
app = AsyncApp(
201+
client=self.web_client,
202+
signing_secret=self.signing_secret,
203+
)
204+
app.options("mes_a")(show_empty_options)
205+
206+
request = self.build_valid_multi_request()
207+
response = await app.async_dispatch(request)
208+
assert response.status == 200
209+
assert response.body == """{"options": []}"""
210+
assert response.headers["content-type"][0] == "application/json;charset=utf-8"
211+
await assert_auth_test_count_async(self, 1)
212+
213+
@pytest.mark.asyncio
214+
async def test_empty_option_groups(self):
215+
app = AsyncApp(
216+
client=self.web_client,
217+
signing_secret=self.signing_secret,
218+
)
219+
app.options("mes_a")(show_empty_option_groups)
220+
221+
request = self.build_valid_multi_request()
222+
response = await app.async_dispatch(request)
223+
assert response.status == 200
224+
assert response.body == """{"option_groups": []}"""
225+
assert response.headers["content-type"][0] == "application/json;charset=utf-8"
226+
await assert_auth_test_count_async(self, 1)
227+
198228

199229
body = {
200230
"type": "block_suggestion",
@@ -311,3 +341,15 @@ async def show_multi_options(ack, body, payload, options):
311341
assert body == options
312342
assert payload == options
313343
await ack(multi_response)
344+
345+
346+
async def show_empty_options(ack, body, payload, options):
347+
assert body == options
348+
assert payload == options
349+
await ack(options=[])
350+
351+
352+
async def show_empty_option_groups(ack, body, payload, options):
353+
assert body == options
354+
assert payload == options
355+
await ack(option_groups=[])

0 commit comments

Comments
 (0)