oncall-engine/engine/apps/slack/tests/test_slash_command.py
Innokentii Konstantinov 94219c25bb
Introduce slash command matcher (#4717)
With the Unified Slack app we now have two ways of calling commands.
1. Legacy one when command invoked directly: /escalate
2. Unified one: /grafana escalate
On top of that we have different slach commands for each environment:
/escalate-local, /escalate-dev, etc. It was leading to a weird command
to escalate via Unified App in dev u need to type: /grafana-dev
escalate-develop.

To support both, I introduced a matcher function for SlashCommandRoutes.
It allows to simplify handling of such cases without complex workarounds
in an EventAPIEndpoint.


# What this PR does

## Which issue(s) this PR closes

Related to [issue link here]

<!--
*Note*: If you want the issue to be auto-closed once the PR is merged,
change "Related to" to "Closes" in the line above.
If you have more than one GitHub issue that this PR closes, be sure to
preface
each issue link with a [closing
keyword](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/using-keywords-in-issues-and-pull-requests#linking-a-pull-request-to-an-issue).
This ensures that the issue(s) are auto-closed once the PR has been
merged.
-->

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [ ] Documentation added (or `pr:no public docs` PR label added if not
required)
- [ ] Added the relevant release notes label (see labels prefixed w/
`release:`). These labels dictate how your PR will
    show up in the autogenerated release notes.
2024-07-24 09:53:06 +00:00

32 lines
953 B
Python

from apps.slack.slash_command import SlashCommand
def test_parse():
payload = {
"command": "/grafana",
"text": "escalate",
"trigger_id": "trigger_id",
"user_id": "user_id",
"user_name": "user_name",
"api_app_id": "api_app_id",
}
slash_command = SlashCommand.parse(payload)
assert slash_command.command == "grafana"
assert slash_command.args == ["escalate"]
assert slash_command.subcommand == "escalate"
assert slash_command.is_grafana_command
def test_parse_command_without_subcommand():
payload = {
"command": "/escalate",
"text": "",
"trigger_id": "trigger_id",
"user_id": "user_id",
"user_name": "user_name",
"api_app_id": "api_app_id",
}
slash_command = SlashCommand.parse(payload)
assert slash_command.command == "escalate"
assert slash_command.args == []
assert slash_command.subcommand is None