Personal Telegram developer console for GitHub

test: define deep file browser and numeric repo callback behavior

davoodmehraban89 committed Oct 2, 2026 at 23:01 UTC f5a1a75180344b306c000b3db580cd55c06abc67
1 file changed +65 -8
test/navigation.test.js
+65 -8
@@ -32,6 +32,9 @@ function installApiMock() {
32 const telegramCalls = [];
33 const githubCalls = [];
34 const originalFetch = globalThis.fetch;
35 + const folderSha = 'a'.repeat(40);
36 + const fileSha = 'b'.repeat(40);
37 + const nestedFileSha = 'c'.repeat(40);
38
39 globalThis.fetch = async (url, options = {}) => {
40 const value = String(url);
@@ -48,6 +51,7 @@ function installApiMock() {
51
52 if (value.startsWith('https://api.github.com/user/repos?')) {
53 return json([{
54 + id: 1001,
55 name: 'demo',
56 full_name: 'davoodmehraban89/demo',
57 private: true,
@@ -58,8 +62,9 @@ function installApiMock() {
62 }]);
63 }
64
61 - if (value === 'https://api.github.com/repos/davoodmehraban89/demo') {
65 + if (value === 'https://api.github.com/repositories/1001' || value === 'https://api.github.com/repos/davoodmehraban89/demo') {
66 return json({
67 + id: 1001,
68 name: 'demo',
69 full_name: 'davoodmehraban89/demo',
70 private: true,
@@ -72,11 +77,25 @@ function installApiMock() {
77
78 if (value === 'https://api.github.com/repos/davoodmehraban89/demo/contents') {
79 return json([
75 - { name: 'src', path: 'src', type: 'dir', size: 0, sha: 'a'.repeat(40) },
76 - { name: 'README.md', path: 'README.md', type: 'file', size: 100, sha: 'b'.repeat(40) }
80 + { name: 'src', path: 'src', type: 'dir', size: 0, sha: folderSha },
81 + { name: 'README.md', path: 'README.md', type: 'file', size: 100, sha: fileSha }
82 ]);
83 }
84
85 + if (value === `https://api.github.com/repos/davoodmehraban89/demo/git/trees/${folderSha}`) {
86 + return json({ tree: [
87 + { path: 'index.js', type: 'blob', size: 42, sha: nestedFileSha }
88 + ] });
89 + }
90 +
91 + if (value === `https://api.github.com/repos/davoodmehraban89/demo/git/blobs/${nestedFileSha}`) {
92 + return json({
93 + encoding: 'base64',
94 + size: 21,
95 + content: btoa('console.log("hello")\n')
96 + });
97 + }
98 +
99 if (value === 'https://api.github.com/repos/davoodmehraban89/demo/commits?per_page=5') {
100 return json([{
101 sha: '1234567890abcdef',
@@ -118,6 +137,8 @@ function installApiMock() {
137 return {
138 telegramCalls,
139 githubCalls,
140 + folderSha,
141 + nestedFileSha,
142 restore() {
143 globalThis.fetch = originalFetch;
144 }
@@ -147,7 +168,7 @@ test('single-message navigation edits the same Telegram message across menu laye
168 callback_query: { id: 'repos', from: { id: 123 }, data: 'menu:repos', message: menuMessage }
169 });
170 await sendUpdate({
150 - callback_query: { id: 'repo', from: { id: 123 }, data: 'repo:demo', message: menuMessage }
171 + callback_query: { id: 'repo', from: { id: 123 }, data: 'repo:1001', message: menuMessage }
172 });
173 await sendUpdate({
174 callback_query: { id: 'back', from: { id: 123 }, data: 'menu:repos', message: menuMessage }
@@ -174,7 +195,7 @@ test('repository activity views use live GitHub responses and edit in place', as
195 const mock = installApiMock();
196 try {
197 const menuMessage = { message_id: 701, chat: { id: 123 } };
177 - for (const data of ['files:demo', 'commits:demo', 'pr:demo', 'status:demo']) {
198 + for (const data of ['files:1001', 'commits:1001', 'pr:1001', 'status:1001']) {
199 await sendUpdate({
200 callback_query: { id: data, from: { id: 123 }, data, message: menuMessage }
201 });
@@ -187,13 +208,12 @@ test('repository activity views use live GitHub responses and edit in place', as
208 assert.match(edits[2].body.text, /#7/);
209 assert.match(edits[2].body.text, /Improve bot UI/);
210 assert.match(edits[3].body.text, /CI/);
190 - assert.ok(mock.githubCalls.some(url => url.startsWith('https://api.github.com/user/repos?')) === false);
211 } finally {
212 mock.restore();
213 }
214 });
215
196 -test('/repos uses authenticated repository discovery and renders the API result', async () => {
216 +test('/repos uses numeric repository ids in callbacks', async () => {
217 const mock = installApiMock();
218 try {
219 await sendUpdate({
@@ -204,9 +224,46 @@ test('/repos uses authenticated repository discovery and renders the API result'
224 assert.ok(sent);
225 const buttons = sent.body.reply_markup.inline_keyboard.flat();
226 assert.ok(buttons.some(button => button.text.includes('demo')));
207 - assert.ok(buttons.some(button => button.callback_data === 'repo:demo'));
227 + assert.ok(buttons.some(button => button.callback_data === 'repo:1001'));
228 assert.ok(mock.githubCalls.some(url => url.startsWith('https://api.github.com/user/repos?')));
229 } finally {
230 mock.restore();
231 }
232 });
233 +
234 +test('deep file browser opens directory and file previews in the same Telegram message', async () => {
235 + const mock = installApiMock();
236 + try {
237 + const menuMessage = { message_id: 702, chat: { id: 123 } };
238 +
239 + await sendUpdate({
240 + callback_query: { id: 'root', from: { id: 123 }, data: 'files:1001', message: menuMessage }
241 + });
242 +
243 + let edits = mock.telegramCalls.filter(call => call.method === 'editMessageText');
244 + const rootButtons = edits.at(-1).body.reply_markup.inline_keyboard.flat();
245 + assert.ok(rootButtons.some(button => button.callback_data === `tree:1001:${mock.folderSha}`));
246 +
247 + await sendUpdate({
248 + callback_query: { id: 'tree', from: { id: 123 }, data: `tree:1001:${mock.folderSha}`, message: menuMessage }
249 + });
250 +
251 + edits = mock.telegramCalls.filter(call => call.method === 'editMessageText');
252 + const treeView = edits.at(-1);
253 + assert.match(treeView.body.text, /index\.js/);
254 + const treeButtons = treeView.body.reply_markup.inline_keyboard.flat();
255 + assert.ok(treeButtons.some(button => button.callback_data === `blob:1001:${mock.nestedFileSha}`));
256 +
257 + await sendUpdate({
258 + callback_query: { id: 'blob', from: { id: 123 }, data: `blob:1001:${mock.nestedFileSha}`, message: menuMessage }
259 + });
260 +
261 + edits = mock.telegramCalls.filter(call => call.method === 'editMessageText');
262 + const blobView = edits.at(-1);
263 + assert.match(blobView.body.text, /console\.log/);
264 + assert.equal(blobView.body.message_id, 702);
265 + assert.ok(mock.telegramCalls.filter(call => call.method === 'sendMessage').length === 0);
266 + } finally {
267 + mock.restore();
268 + }
269 +});