Personal Telegram developer console for GitHub
test: require github routes to use plugin router
davoodmehraban89 committed
Oct 3, 2026 at 01:35 UTC
f1ee926320dc918d0d0c8b21d60710077a9d119b
1 file changed
+72
test/bot.test.js
+72
@@ -65,6 +65,40 @@ describe('Nexa Dev Bot - Webhook Dispatcher & In-Place Editing', () => {
65
assert.ok(sentMessages[0].replyMarkup.inline_keyboard);
66
});
67
68
+ it('/repos is dispatched through the plugin router', async () => {
69
+ const sentMessages = [];
70
+ const bot = makeBot();
71
+ const routedView = {
72
+ text: 'routed repositories',
73
+ reply_markup: { inline_keyboard: [] }
74
+ };
75
+ let dispatchCount = 0;
76
+
77
+ bot.menu.getReposListView = async () => {
78
+ throw new Error('direct repository path must not be used');
79
+ };
80
+ bot.router.dispatchCommand = async (command, context) => {
81
+ dispatchCount += 1;
82
+ assert.equal(command, '/repos');
83
+ assert.equal(context.isOwner, true);
84
+ return routedView;
85
+ };
86
+ bot.telegram.sendMessage = async (chatId, text, replyMarkup) => {
87
+ sentMessages.push({ chatId, text, replyMarkup });
88
+ return { ok: true };
89
+ };
90
+
91
+ const res = await bot.handleUpdate({
92
+ message: { message_id: 101, chat: { id: 123456 }, text: '/repos' }
93
+ });
94
+
95
+ assert.equal(res.ok, true);
96
+ assert.equal(res.command, 'repos');
97
+ assert.equal(dispatchCount, 1);
98
+ assert.equal(sentMessages.length, 1);
99
+ assert.equal(sentMessages[0].text, 'routed repositories');
100
+ });
101
+
102
it('callback answers Telegram and edits the existing message in place', async () => {
103
const answeredCallbacks = [];
104
const editedMessages = [];
@@ -101,6 +135,44 @@ describe('Nexa Dev Bot - Webhook Dispatcher & In-Place Editing', () => {
135
assert.match(editedMessages[0].text, /فهرست مخزنها/);
136
});
137
138
+ it('github callbacks are dispatched through the plugin router before editing', async () => {
139
+ const bot = makeBot();
140
+ const edits = [];
141
+ let dispatchCount = 0;
142
+
143
+ bot.telegram.answerCallbackQuery = async () => ({ ok: true });
144
+ bot.menu.renderByCallback = async () => {
145
+ throw new Error('direct github callback path must not be used');
146
+ };
147
+ bot.router.dispatchCallback = async (data, context) => {
148
+ dispatchCount += 1;
149
+ assert.equal(data, 'repo:Factor-easy');
150
+ assert.equal(context.isOwner, true);
151
+ return {
152
+ text: 'routed project',
153
+ reply_markup: { inline_keyboard: [] }
154
+ };
155
+ };
156
+ bot.telegram.editMessageText = async (chatId, messageId, text, replyMarkup) => {
157
+ edits.push({ chatId, messageId, text, replyMarkup });
158
+ return { ok: true };
159
+ };
160
+
161
+ const res = await bot.handleUpdate({
162
+ callback_query: {
163
+ id: 'cb_route',
164
+ data: 'repo:Factor-easy',
165
+ message: { message_id: 501, chat: { id: 123456 } }
166
+ }
167
+ });
168
+
169
+ assert.equal(res.ok, true);
170
+ assert.equal(res.edited, true);
171
+ assert.equal(dispatchCount, 1);
172
+ assert.equal(edits.length, 1);
173
+ assert.equal(edits[0].text, 'routed project');
174
+ });
175
+
176
it('callback navigation still edits when answerCallbackQuery fails', async () => {
177
const editedMessages = [];
178
const bot = makeBot();