Skip to content

Commit

Permalink
Make app.shortcut compatible with Bolt for JS (slackapi#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
seratch authored Aug 25, 2020
1 parent ed26ea0 commit afae827
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 10 deletions.
17 changes: 13 additions & 4 deletions scripts/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@
script_dir=`dirname $0`
cd ${script_dir}/..

pip install -e ".[testing]" && \
black slack_bolt/ tests/ && \
pytest $1 && \
pytype slack_bolt/
test_target="$1"

if [[ $test_target != "" ]]
then
pip install -e ".[testing]" && \
black slack_bolt/ tests/ && \
pytest $1
else
pip install -e ".[testing]" && \
black slack_bolt/ tests/ && \
pytest && \
pytype slack_bolt/
fi
14 changes: 12 additions & 2 deletions slack_bolt/listener_matcher/builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,18 @@ def func(payload: dict) -> bool:
return (
payload
and "callback_id" in payload
and payload["type"] == "shortcut"
and _matches(callback_id, payload["callback_id"])
and (
(
# global shortcut
_is_expected_type(payload, "shortcut")
and _matches(callback_id, payload["callback_id"])
)
or (
# message shortcut
_is_expected_type(payload, "message_action")
and _matches(callback_id, payload["callback_id"])
)
)
)

return build_listener_matcher(func, asyncio)
Expand Down
15 changes: 13 additions & 2 deletions tests/async_scenario_tests/test_shortcut.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ async def test_mock_server_is_running(self):
resp = await self.web_client.api_test()
assert resp != None

# NOTE: This is a compatible behavior with Bolt for JS
@pytest.mark.asyncio
async def test_success_global(self):
async def test_success_both_global_and_message(self):
app = AsyncApp(client=self.web_client, signing_secret=self.signing_secret,)
app.shortcut("test-shortcut")(simple_listener)

Expand All @@ -68,9 +69,19 @@ async def test_success_global(self):

request = self.build_valid_request(message_shortcut_raw_body)
response = await app.async_dispatch(request)
assert response.status == 404
assert response.status == 200
assert self.mock_received_requests["/auth.test"] == 2

@pytest.mark.asyncio
async def test_success_global(self):
app = AsyncApp(client=self.web_client, signing_secret=self.signing_secret,)
app.shortcut("test-shortcut")(simple_listener)

request = self.build_valid_request(global_shortcut_raw_body)
response = await app.async_dispatch(request)
assert response.status == 200
assert self.mock_received_requests["/auth.test"] == 1

@pytest.mark.asyncio
async def test_success_global_2(self):
app = AsyncApp(client=self.web_client, signing_secret=self.signing_secret,)
Expand Down
14 changes: 12 additions & 2 deletions tests/scenario_tests/test_shortcut.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ def test_mock_server_is_running(self):
resp = self.web_client.api_test()
assert resp != None

def test_success_global(self):
# NOTE: This is a compatible behavior with Bolt for JS
def test_success_both_global_and_message(self):
app = App(client=self.web_client, signing_secret=self.signing_secret,)
app.shortcut("test-shortcut")(simple_listener)

Expand All @@ -60,9 +61,18 @@ def test_success_global(self):

request = self.build_valid_request(message_shortcut_raw_body)
response = app.dispatch(request)
assert response.status == 404
assert response.status == 200
assert self.mock_received_requests["/auth.test"] == 2

def test_success_global(self):
app = App(client=self.web_client, signing_secret=self.signing_secret,)
app.shortcut("test-shortcut")(simple_listener)

request = self.build_valid_request(global_shortcut_raw_body)
response = app.dispatch(request)
assert response.status == 200
assert self.mock_received_requests["/auth.test"] == 1

def test_success_global_2(self):
app = App(client=self.web_client, signing_secret=self.signing_secret,)
app.global_shortcut("test-shortcut")(simple_listener)
Expand Down

0 comments on commit afae827

Please sign in to comment.