Skip to content

Commit 50e99d3

Browse files
committed
Fix #111 by correcting the logic to check event type
1 parent 6a8d38d commit 50e99d3

File tree

4 files changed

+47
-2
lines changed

4 files changed

+47
-2
lines changed

slack_bolt/util/payload_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def is_event(body: Dict[str, Any]) -> bool:
3232
def is_workflow_step_execute(body: Dict[str, Any]) -> bool:
3333
return (
3434
is_event(body)
35-
and body["event"]["type"] == "workflow_step_edit"
35+
and body["event"]["type"] == "workflow_step_execute"
3636
and "workflow_step" in body["event"]
3737
)
3838

tests/scenario_tests/test_workflow_steps.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
import time as time_module
23
from time import time
34
from urllib.parse import quote
45

@@ -85,6 +86,8 @@ def test_execute(self):
8586
response = self.app.dispatch(request)
8687
assert response.status == 200
8788
assert self.mock_received_requests["/auth.test"] == 1
89+
time_module.sleep(0.5)
90+
assert self.mock_received_requests["/workflows.stepCompleted"] == 1
8891

8992
self.app = App(client=self.web_client, signing_secret=self.signing_secret)
9093
self.app.step(

tests/scenario_tests_async/test_workflow_steps.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ async def test_execute(self):
105105
response = await self.app.async_dispatch(request)
106106
assert response.status == 200
107107
assert self.mock_received_requests["/auth.test"] == 1
108+
await asyncio.sleep(0.5)
109+
assert self.mock_received_requests["/workflows.stepCompleted"] == 1
108110

109111
self.app = AsyncApp(client=self.web_client, signing_secret=self.signing_secret)
110112
self.app.step(

tests/slack_bolt/listener_matcher/test_builtins.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
from urllib.parse import quote
44

55
from slack_bolt import BoltRequest, BoltResponse
6-
from slack_bolt.listener_matcher.builtins import block_action, action
6+
from slack_bolt.listener_matcher.builtins import (
7+
block_action,
8+
action,
9+
workflow_step_execute,
10+
)
711

812

913
class TestBuiltins:
@@ -95,3 +99,39 @@ def test_block_action(self):
9599
)
96100
is False
97101
)
102+
103+
def test_workflow_step_execute(self):
104+
payload = {
105+
"team_id": "T111",
106+
"enterprise_id": "E111",
107+
"api_app_id": "A111",
108+
"event": {
109+
"type": "workflow_step_execute",
110+
"callback_id": "copy_review",
111+
"workflow_step": {
112+
"workflow_step_execute_id": "zzz-execution",
113+
"workflow_id": "12345",
114+
"workflow_instance_id": "11111",
115+
"step_id": "111-222-333-444-555",
116+
"inputs": {"taskName": {"value": "a"}},
117+
"outputs": [
118+
{"name": "taskName", "type": "text", "label": "Task Name"}
119+
],
120+
},
121+
"event_ts": "1601541373.225894",
122+
},
123+
"type": "event_callback",
124+
"event_id": "Ev111",
125+
"event_time": 1601541373,
126+
}
127+
128+
request = BoltRequest(body=f"payload={quote(json.dumps(payload))}")
129+
130+
m = workflow_step_execute("copy_review")
131+
assert m.matches(request, None) == True
132+
133+
m = workflow_step_execute("copy_review_2")
134+
assert m.matches(request, None) == False
135+
136+
m = workflow_step_execute(re.compile("copy_.+"))
137+
assert m.matches(request, None) == True

0 commit comments

Comments
 (0)