Skip to content

Commit

Permalink
Fix #468 Replying with 0 results for a multi-select external option d…
Browse files Browse the repository at this point in the history
…isplay previous successful results (#580)
  • Loading branch information
seratch authored Jan 28, 2022
1 parent 8c0532d commit dc48378
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 2 deletions.
4 changes: 2 additions & 2 deletions slack_bolt/context/ack/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ def _set_response(
elif blocks and len(blocks) > 0:
body.update({"text": text, "blocks": convert_to_dict_list(blocks)})
self.response = BoltResponse(status=200, body=body)
elif options and len(options) > 0:
elif options is not None:
body = {"options": convert_to_dict_list(options)}
self.response = BoltResponse(status=200, body=body)
elif option_groups and len(option_groups) > 0:
elif option_groups is not None:
body = {"option_groups": convert_to_dict_list(option_groups)}
self.response = BoltResponse(status=200, body=body)
elif response_action:
Expand Down
40 changes: 40 additions & 0 deletions tests/scenario_tests/test_block_suggestion.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,34 @@ def test_failure_multi(self):
assert response.status == 404
assert_auth_test_count(self, 1)

def test_empty_options(self):
app = App(
client=self.web_client,
signing_secret=self.signing_secret,
)
app.options("mes_a")(show_empty_options)

request = self.build_valid_multi_request()
response = app.dispatch(request)
assert response.status == 200
assert response.body == """{"options": []}"""
assert response.headers["content-type"][0] == "application/json;charset=utf-8"
assert_auth_test_count(self, 1)

def test_empty_option_groups(self):
app = App(
client=self.web_client,
signing_secret=self.signing_secret,
)
app.options("mes_a")(show_empty_option_groups)

request = self.build_valid_multi_request()
response = app.dispatch(request)
assert response.status == 200
assert response.body == """{"option_groups": []}"""
assert response.headers["content-type"][0] == "application/json;charset=utf-8"
assert_auth_test_count(self, 1)


body = {
"type": "block_suggestion",
Expand Down Expand Up @@ -296,3 +324,15 @@ def show_multi_options(ack, body, payload, options):
assert body == options
assert payload == options
ack(multi_response)


def show_empty_options(ack, body, payload, options):
assert body == options
assert payload == options
ack(options=[])


def show_empty_option_groups(ack, body, payload, options):
assert body == options
assert payload == options
ack(option_groups=[])
42 changes: 42 additions & 0 deletions tests/scenario_tests_async/test_block_suggestion.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,36 @@ async def test_failure_multi(self):
assert response.status == 404
await assert_auth_test_count_async(self, 1)

@pytest.mark.asyncio
async def test_empty_options(self):
app = AsyncApp(
client=self.web_client,
signing_secret=self.signing_secret,
)
app.options("mes_a")(show_empty_options)

request = self.build_valid_multi_request()
response = await app.async_dispatch(request)
assert response.status == 200
assert response.body == """{"options": []}"""
assert response.headers["content-type"][0] == "application/json;charset=utf-8"
await assert_auth_test_count_async(self, 1)

@pytest.mark.asyncio
async def test_empty_option_groups(self):
app = AsyncApp(
client=self.web_client,
signing_secret=self.signing_secret,
)
app.options("mes_a")(show_empty_option_groups)

request = self.build_valid_multi_request()
response = await app.async_dispatch(request)
assert response.status == 200
assert response.body == """{"option_groups": []}"""
assert response.headers["content-type"][0] == "application/json;charset=utf-8"
await assert_auth_test_count_async(self, 1)


body = {
"type": "block_suggestion",
Expand Down Expand Up @@ -311,3 +341,15 @@ async def show_multi_options(ack, body, payload, options):
assert body == options
assert payload == options
await ack(multi_response)


async def show_empty_options(ack, body, payload, options):
assert body == options
assert payload == options
await ack(options=[])


async def show_empty_option_groups(ack, body, payload, options):
assert body == options
assert payload == options
await ack(option_groups=[])

0 comments on commit dc48378

Please sign in to comment.