Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #468 Replying with 0 results for a multi-select external option display previous successful results #580

Merged
merged 1 commit into from
Jan 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": []}"""
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to the bug, this response body used to be empty string "". That's why the select menu options are not updated in the reported scenario.

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=[])