Personal Telegram developer console for GitHub
test: reproduce private repo id navigation 404
davoodmehraban89 committed
Oct 4, 2026 at 06:30 UTC
745aa5b20f2dae80bedeec8bfef20231d65ae9f4
1 file changed
+70
test/github-repository-fallback.test.js
new
+70
@@ -0,0 +1,70 @@
1
+import test from 'node:test';
2
+import assert from 'node:assert/strict';
3
+import { GitHubService } from '../src/github.js';
4
+
5
+function json(data, status = 200) {
6
+ return new Response(JSON.stringify(data), {
7
+ status,
8
+ headers: { 'content-type': 'application/json' }
9
+ });
10
+}
11
+
12
+test('numeric private repository lookup falls back through accessible repositories when /repositories/:id returns 404', async () => {
13
+ const originalFetch = globalThis.fetch;
14
+ const calls = [];
15
+ const repoId = 1401612143;
16
+
17
+ globalThis.fetch = async url => {
18
+ const value = String(url);
19
+ calls.push(value);
20
+
21
+ if (value === `https://api.github.com/repositories/${repoId}`) {
22
+ return json({ message: 'Not Found' }, 404);
23
+ }
24
+
25
+ if (value.startsWith('https://api.github.com/user/repos?')) {
26
+ return json([{
27
+ id: repoId,
28
+ name: 'nexa-dev-bot',
29
+ full_name: 'davoodmehraban89/nexa-dev-bot',
30
+ private: true,
31
+ default_branch: 'main',
32
+ archived: false,
33
+ description: 'Personal Telegram developer console for GitHub',
34
+ html_url: 'https://github.com/davoodmehraban89/nexa-dev-bot',
35
+ stargazers_count: 0,
36
+ forks_count: 0
37
+ }]);
38
+ }
39
+
40
+ if (value === 'https://api.github.com/repos/davoodmehraban89/nexa-dev-bot') {
41
+ return json({
42
+ id: repoId,
43
+ name: 'nexa-dev-bot',
44
+ full_name: 'davoodmehraban89/nexa-dev-bot',
45
+ private: true,
46
+ default_branch: 'main',
47
+ archived: false,
48
+ description: 'Personal Telegram developer console for GitHub',
49
+ html_url: 'https://github.com/davoodmehraban89/nexa-dev-bot',
50
+ stargazers_count: 0,
51
+ forks_count: 0
52
+ });
53
+ }
54
+
55
+ throw new Error(`Unexpected URL: ${value}`);
56
+ };
57
+
58
+ try {
59
+ const github = new GitHubService('test-token', 'davoodmehraban89');
60
+ const repo = await github.getRepository(repoId);
61
+
62
+ assert.equal(repo.id, String(repoId));
63
+ assert.equal(repo.fullName, 'davoodmehraban89/nexa-dev-bot');
64
+ assert.ok(calls.includes(`https://api.github.com/repositories/${repoId}`));
65
+ assert.ok(calls.some(value => value.startsWith('https://api.github.com/user/repos?')));
66
+ assert.ok(calls.includes('https://api.github.com/repos/davoodmehraban89/nexa-dev-bot'));
67
+ } finally {
68
+ globalThis.fetch = originalFetch;
69
+ }
70
+});