Without explicit scope, set default scope only with default handler#79
Without explicit scope, set default scope only with default handler#79
default scope only with default handler#79Conversation
Change handler check to _hasHandler property
|
I would like to test what happens when someone tries to register a command without any handlers... Just because I don't remember exactly what it could compromise, but this little change makes a lot of sense tbh. something which test the following: commands
.command('broadcast', 'Send broadcast to all users')
await commands.setCommands(bot) |
|
@carafelix is that test cases correct ? commands
.command('...', '...') // Command without default handler and explicit scope
void {
scope: { type: 'default' },
commands: [{ command: '...', description: '...' }],
}commands
.command('...', '...', () => {}) // Command with default handler
void {
scope: { type: 'default' },
commands: [{ command: '...', description: '...' }],
}commands
.command('...', '...') // Command without default handler
.addToScope({ type: 'chat', chat_id: 0 }) // but with explicit scope
void {
scope: { type: 'chat', chat_id: 0 },
commands: [{ command: '...', description: '...' }],
}commands
.command('...', '...', () => {}) // Command with default handler
.addToScope({ type: 'chat', chat_id: 0 }) // and explicit scope
void {
scope: { type: 'default' },
commands: [{ command: '...', description: '...' }],
}
void {
scope: { type: 'chat', chat_id: 0 },
commands: [{ command: '...', description: '...' }],
}
|
default scope only for handlersdefault scope only with default handler
|
@PonomareVlad yup! That looks like the should-be-intended functionality :P Please add those test cases and fix the unrelated test cases that got affected by this and I'll merge. TO-DO reminder for myself: Refactor test cases which are too-heavily coupled with the inners output. Just check for the properties needed |
|
If we assume that the user of this plugin uses it to set explicit scopes, then previous
@carafelix so, in this case do we should to perform reset of commands
.command('...', '...') // Command without default handler
.addToScope({ type: 'chat', chat_id: 0 }) // but with explicit scope
void {
scope: { type: 'default' },
commands: [],
}
void {
scope: { type: 'chat', chat_id: 0 },
commands: [{ command: '...', description: '...' }],
} |
If, and only if, all the above test passes. As a backwards fix, I think it would be ideal. I think would benefit people who use to declare a default scoped command in any manner and later on decided to remove it from the default scope and only scope it. Iirc, if you have any other command in the default scope this would get reset anyways but for groups with only 1 command, it would not. Thanks for thinking about that too |
…avior Co-authored-by: PonomareVlad <2877584+PonomareVlad@users.noreply.github.com>
|
@carafelix I saw some test cases for commands/test/command-group.test.ts Line 211 in 6653e2a commands/test/command-group.test.ts Line 302 in 6653e2a commands/test/command-group.test.ts Line 328 in 6653e2a |
Removed unused command tests and added new tests for command scope behavior.
|
@carafelix also, can you check current changes in PR before I will go next (is this proper test cases, placement and format) ? |
It's okay. Chat id is a required property in every update manage by the plugin. We pass it in the testing simply as a mock. |
carafelix
left a comment
There was a problem hiding this comment.
Nice :3
The tests you added are all good ^-^ gj
This pull request refines command scope assignment logic in the
CommandGroupandCommandclasses and significantly expands the test suite to verify correct behavior for commands with and without handlers, as well as various scope configurations. The changes ensure that commands are properly assigned to default and explicit scopes based on their handler presence and scope declarations.Command scope assignment improvements
CommandGroupto automatically add commands with no explicit scopes to the default scope, ensuring all commands are properly scoped even if not explicitly assigned.Commandto use an internal_hasHandlerflag to determine if a handler exists before adding the command to the default scope, improving reliability of handler detection.Test suite enhancements
command-group.test.tsto cover new scope assignment behaviors, including cases for commands with/without handlers and with/without explicit scopes.