Skip to content

Commit

Permalink
fix: throw Error that dynamic menus only can handle buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
EdJoPaTo committed Sep 21, 2018
1 parent 9cb222a commit 39b335b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions inline-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ class TelegrafInlineMenu {
if (this.commands.length > 0) {
throw new Error('commands can not point on dynamic submenus. Happened in menu ' + actionCode.get() + ' with the following commands: ' + this.commands.join(', '))
}
const handlerNotActions = this.handlers.filter(o => !o.action)
if (handlerNotActions.length > 0) {
throw new Error('a dynamic submenu can only contain buttons. A question for example does not work. Happened in menu ' + actionCode.get())
}
}

options.log('middleware triggered', actionCode.get(), options, this)
Expand Down
16 changes: 16 additions & 0 deletions test/select.submenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,19 @@ test('hide dynamic submenu does not work', t => {
})
}, /dynamic/)
})

test('something that is not an action in dynamic menu throws error', t => {
const menu = new TelegrafInlineMenu('foo')
const submenu = new TelegrafInlineMenu('bar')
.question('Question', 'q', {
questionText: '42',
setFunc: () => {}
})
menu.select('a', ['a', 'b'], {
submenu
})
const bot = new Telegraf()
t.throws(() => {
bot.use(menu.init())
}, /dynamic.+question.+menu.+a/)
})

0 comments on commit 39b335b

Please sign in to comment.