Skip to content

Commit afae827

Browse files
authored
Make app.shortcut compatible with Bolt for JS (slackapi#40)
1 parent ed26ea0 commit afae827

File tree

4 files changed

+50
-10
lines changed

4 files changed

+50
-10
lines changed

scripts/run_tests.sh

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,16 @@
66
script_dir=`dirname $0`
77
cd ${script_dir}/..
88

9-
pip install -e ".[testing]" && \
10-
black slack_bolt/ tests/ && \
11-
pytest $1 && \
12-
pytype slack_bolt/
9+
test_target="$1"
10+
11+
if [[ $test_target != "" ]]
12+
then
13+
pip install -e ".[testing]" && \
14+
black slack_bolt/ tests/ && \
15+
pytest $1
16+
else
17+
pip install -e ".[testing]" && \
18+
black slack_bolt/ tests/ && \
19+
pytest && \
20+
pytype slack_bolt/
21+
fi

slack_bolt/listener_matcher/builtins.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,18 @@ def func(payload: dict) -> bool:
127127
return (
128128
payload
129129
and "callback_id" in payload
130-
and payload["type"] == "shortcut"
131-
and _matches(callback_id, payload["callback_id"])
130+
and (
131+
(
132+
# global shortcut
133+
_is_expected_type(payload, "shortcut")
134+
and _matches(callback_id, payload["callback_id"])
135+
)
136+
or (
137+
# message shortcut
138+
_is_expected_type(payload, "message_action")
139+
and _matches(callback_id, payload["callback_id"])
140+
)
141+
)
132142
)
133143

134144
return build_listener_matcher(func, asyncio)

tests/async_scenario_tests/test_shortcut.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ async def test_mock_server_is_running(self):
5656
resp = await self.web_client.api_test()
5757
assert resp != None
5858

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

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

6970
request = self.build_valid_request(message_shortcut_raw_body)
7071
response = await app.async_dispatch(request)
71-
assert response.status == 404
72+
assert response.status == 200
7273
assert self.mock_received_requests["/auth.test"] == 2
7374

75+
@pytest.mark.asyncio
76+
async def test_success_global(self):
77+
app = AsyncApp(client=self.web_client, signing_secret=self.signing_secret,)
78+
app.shortcut("test-shortcut")(simple_listener)
79+
80+
request = self.build_valid_request(global_shortcut_raw_body)
81+
response = await app.async_dispatch(request)
82+
assert response.status == 200
83+
assert self.mock_received_requests["/auth.test"] == 1
84+
7485
@pytest.mark.asyncio
7586
async def test_success_global_2(self):
7687
app = AsyncApp(client=self.web_client, signing_secret=self.signing_secret,)

tests/scenario_tests/test_shortcut.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ def test_mock_server_is_running(self):
4949
resp = self.web_client.api_test()
5050
assert resp != None
5151

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

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

6162
request = self.build_valid_request(message_shortcut_raw_body)
6263
response = app.dispatch(request)
63-
assert response.status == 404
64+
assert response.status == 200
6465
assert self.mock_received_requests["/auth.test"] == 2
6566

67+
def test_success_global(self):
68+
app = App(client=self.web_client, signing_secret=self.signing_secret,)
69+
app.shortcut("test-shortcut")(simple_listener)
70+
71+
request = self.build_valid_request(global_shortcut_raw_body)
72+
response = app.dispatch(request)
73+
assert response.status == 200
74+
assert self.mock_received_requests["/auth.test"] == 1
75+
6676
def test_success_global_2(self):
6777
app = App(client=self.web_client, signing_secret=self.signing_secret,)
6878
app.global_shortcut("test-shortcut")(simple_listener)

0 commit comments

Comments
 (0)