|
5 | 5 | from slack_sdk import WebClient |
6 | 6 | from slack_sdk.signature import SignatureVerifier |
7 | 7 |
|
8 | | -from slack_bolt import BoltRequest |
| 8 | +from slack_bolt import BoltRequest, BoltContext |
9 | 9 | from slack_bolt.app import App |
10 | 10 | from tests.mock_web_api_server import ( |
11 | 11 | setup_mock_web_api_server, |
@@ -140,6 +140,58 @@ def simple_listener(ack, body, payload, view): |
140 | 140 | raw_response_url_body = f"payload={quote(json.dumps(response_url_payload_body))}" |
141 | 141 |
|
142 | 142 |
|
| 143 | +connect_channel_payload = { |
| 144 | + "type": "view_submission", |
| 145 | + "team": { |
| 146 | + "id": "T-other-side", |
| 147 | + "domain": "other-side", |
| 148 | + "enterprise_id": "E-other-side", |
| 149 | + "enterprise_name": "Kaz Sandbox Org", |
| 150 | + }, |
| 151 | + "user": {"id": "W111", "username": "kaz", "name": "kaz", "team_id": "T-other-side"}, |
| 152 | + "api_app_id": "A1111", |
| 153 | + "token": "legacy-fixed-token", |
| 154 | + "trigger_id": "111.222.xxx", |
| 155 | + "view": { |
| 156 | + "id": "V11111", |
| 157 | + "team_id": "T-other-side", |
| 158 | + "type": "modal", |
| 159 | + "blocks": [ |
| 160 | + { |
| 161 | + "type": "input", |
| 162 | + "block_id": "zniAM", |
| 163 | + "label": {"type": "plain_text", "text": "Label"}, |
| 164 | + "element": { |
| 165 | + "type": "plain_text_input", |
| 166 | + "dispatch_action_config": {"trigger_actions_on": ["on_enter_pressed"]}, |
| 167 | + "action_id": "qEJr", |
| 168 | + }, |
| 169 | + } |
| 170 | + ], |
| 171 | + "private_metadata": "", |
| 172 | + "callback_id": "view-id", |
| 173 | + "state": {"values": {"zniAM": {"qEJr": {"type": "plain_text_input", "value": "Hi there!"}}}}, |
| 174 | + "hash": "1664950703.CmTS8F7U", |
| 175 | + "title": {"type": "plain_text", "text": "My App"}, |
| 176 | + "close": {"type": "plain_text", "text": "Cancel"}, |
| 177 | + "submit": {"type": "plain_text", "text": "Submit"}, |
| 178 | + "root_view_id": "V00000", |
| 179 | + "app_id": "A1111", |
| 180 | + "external_id": "", |
| 181 | + "app_installed_team_id": "T-installed-workspace", |
| 182 | + "bot_id": "B1111", |
| 183 | + }, |
| 184 | + "enterprise": {"id": "E-other-side", "name": "Kaz Sandbox Org"}, |
| 185 | +} |
| 186 | + |
| 187 | +connect_channel_body = f"payload={quote(json.dumps(connect_channel_payload))}" |
| 188 | + |
| 189 | + |
| 190 | +def verify_connected_channel(ack, context: BoltContext): |
| 191 | + assert context.team_id == "T-installed-workspace" |
| 192 | + ack() |
| 193 | + |
| 194 | + |
143 | 195 | class TestViewSubmission: |
144 | 196 | signing_secret = "secret" |
145 | 197 | valid_token = "xoxb-valid" |
@@ -261,3 +313,15 @@ def check(ack, respond): |
261 | 313 | response = app.dispatch(request) |
262 | 314 | assert response.status == 200 |
263 | 315 | assert_auth_test_count(self, 1) |
| 316 | + |
| 317 | + def test_connected_channels(self): |
| 318 | + app = App( |
| 319 | + client=self.web_client, |
| 320 | + signing_secret=self.signing_secret, |
| 321 | + ) |
| 322 | + app.view("view-id")(verify_connected_channel) |
| 323 | + |
| 324 | + request = self.build_valid_request(body=connect_channel_body) |
| 325 | + response = app.dispatch(request) |
| 326 | + assert response.status == 200 |
| 327 | + assert_auth_test_count(self, 1) |
0 commit comments