Skip to content

Commit

Permalink
Add a test for parsing the view submission payload
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathansick committed Sep 25, 2024
1 parent b2cceae commit fce5420
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 6 deletions.
20 changes: 14 additions & 6 deletions server/tests/client/models/slack_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,34 @@

import pytest

from rubin.squarebot.models.slack import SlackBlockActionsPayload
from rubin.squarebot.models.slack import (
SlackBlockActionsPayload,
SlackViewSubmissionPayload,
)


@pytest.fixture
def samples_dir() -> Path:
"""Get the path to the samples directory for interactions."""
return (
Path(__file__).parent
/ "../../slack_messages/interactions/block_actions"
)
return Path(__file__).parent / "../../slack_messages/interactions"


def test_parse_block_actions_static_select(samples_dir: Path) -> None:
"""Test parsing a block action with a static select."""
data = SlackBlockActionsPayload.model_validate_json(
(samples_dir / "static_select.json").read_text()
(samples_dir / "block_actions/static_select.json").read_text()
)
assert data.type == "block_actions"
assert data.container.type == "message"
assert data.actions[0].type == "static_select"
assert data.actions[0].action_id == "templatebot_select_project_template"
assert data.actions[0].selected_option.value == "fastapi"
assert data.actions[0].selected_option.text.text == "FastAPI"


def test_parse_view_submission(samples_dir: Path) -> None:
"""Test parsing a view_submission."""
data = SlackViewSubmissionPayload.model_validate_json(
(samples_dir / "view_submission.json").read_text()
)
assert data.type == "view_submission"
121 changes: 121 additions & 0 deletions server/tests/slack_messages/interactions/view_submission.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
{
"type": "view_submission",
"team": {
"id": "ABCDEFG",
"domain": "lsstc"
},
"user": {
"id": "U2A73RVCL",
"username": "jonathansick",
"name": "jonathansick",
"team_id": "ABCDEFG"
},
"api_app_id": "APPID",
"trigger_id": "7771678089414.6444004512.0b2af9315b97b0e3babcc1f73cd23b15",
"view": {
"id": "V07NW911RBL",
"team_id": "ABCDEFG",
"type": "modal",
"blocks": [
{
"type": "section",
"block_id": "RRGN9",
"text": {
"type": "mrkdwn",
"text": "Let's create a FastAPI project.",
"verbatim": false
}
},
{
"type": "input",
"block_id": "license",
"label": {
"type": "plain_text",
"text": "License",
"emoji": true
},
"hint": {
"type": "plain_text",
"text": "MIT is preferred.",
"emoji": true
},
"optional": false,
"dispatch_action": false,
"element": {
"type": "static_select",
"action_id": "select_license",
"placeholder": {
"type": "plain_text",
"text": "Choose a license\u2026",
"emoji": true
},
"options": [
{
"text": {
"type": "plain_text",
"text": "MIT",
"emoji": true
},
"value": "mit"
},
{
"text": {
"type": "plain_text",
"text": "GPLv3",
"emoji": true
},
"value": "gplv3"
}
],
"focus_on_load": false
}
}
],
"private_metadata": "",
"callback_id": "",
"state": {
"values": {
"license": {
"select_license": {
"type": "static_select",
"selected_option": {
"text": {
"type": "plain_text",
"text": "MIT",
"emoji": true
},
"value": "mit"
}
}
}
}
},
"hash": "1727216577.fRLCN97Y",
"title": {
"type": "plain_text",
"text": "Set up your project",
"emoji": true
},
"clear_on_close": false,
"notify_on_close": false,
"close": {
"type": "plain_text",
"text": "Cancel",
"emoji": true
},
"submit": {
"type": "plain_text",
"text": "Create project",
"emoji": true
},
"previous_view_id": null,
"root_view_id": "V07NW911RBL",
"app_id": "APPID",
"external_id": "",
"app_installed_team_id": "ABCDEFG",
"bot_id": "BOTID"
},
"response_urls": [],
"is_enterprise_install": false,
"enterprise": null
}

0 comments on commit fce5420

Please sign in to comment.