grammyjs / commands

Work-in-progress plugin for managing commands with grammY.
https://grammy.dev/plugins/commands
MIT License
13 stars 2 forks source link

fix: add delay registration to default scope handler #50

Closed roziscoding closed 2 weeks ago

roziscoding commented 2 weeks ago

Fixes #49

carafelix commented 2 weeks ago
        const defaultHandler = spy(() => {});
        const specificHandler = spy(() => {});

        const commandGroup = new CommandGroup();
        commandGroup.command("command", "_", defaultHandler, { prefix: "!" })
          .addToScope({ type: "all_group_chats" }, specificHandler);

        const bot = getBot();
        bot.use(commands());
        bot.use(commandGroup);

        await bot.handleUpdate(
          getDummyUpdate({
            chatType: "group",
            userInput: "!command",
          }),
        );
        assertSpyCalls(defaultHandler, 0); // called once
        assertSpyCalls(specificHandler, 1); // no call

Set up this little integration test and it's failing. Also tried in a real bot, and the default handler it's still taking prevalence.

Should I commit the test (+ the change to getDummyUpdate to allow changing the chat type) to the pr?

I'll take a look now on why is it not properly fixing the issue

KnorpelSenf commented 2 weeks ago

https://github.com/grammyjs/commands/pull/50#discussion_r1831294674 needs to be fixed before tests are useful