refactor: enhance file handling and metrics tracking; remove unused bot health tracker

This commit is contained in:
asepharyana
2026-07-06 01:25:18 +07:00
parent bbf420759b
commit 52bd704d21
17 changed files with 90 additions and 310 deletions
+3
View File
@@ -47,6 +47,9 @@ mock.module('../src/routes/health', () => ({
mock.module('../src/utils/rateLimit', () => ({
cleanupRateLimitCache: mock(),
withRateLimit: <T extends Request>(
handler: (req: T) => Promise<Response>,
): ((req: T) => Promise<Response>) => handler,
}));
describe('Bootstrap Server', () => {
+2 -2
View File
@@ -39,7 +39,7 @@ describe('Environment Variables Validation', () => {
expect(config.rateLimitWindowMs).toBe(60000);
});
it('rateLimitMaxRequests should default to 30 when not specified', () => {
expect(config.rateLimitMaxRequests).toBe(30);
it('rateLimitMaxRequests should default to 150 when not specified', () => {
expect(config.rateLimitMaxRequests).toBe(150);
});
});
+9 -21
View File
@@ -60,25 +60,16 @@ mock.module('../src/db/files', () => ({
}));
// Mock telegram utils
const mockGetFile = mock(() => Promise.resolve({ file_path: 'photos/file_0.jpg' }));
mock.module('../src/utils/telegram', () => ({
getBot: () => ({
telegram: {
getFile: mockGetFile,
},
}),
const mockGetFileInfo = mock(async (_telegramFileId: string) => ({
file_size: 98765,
mime_type: 'image/jpeg',
file_path: 'photos/file_0.jpg',
bot_token: '123456:ABC-DEF',
}));
// Mock global fetch for proxy path
const originalFetch = globalThis.fetch;
const mockGlobalFetch = mock(async (_url: string) =>
Promise.resolve(
new Response('fake-file-content', {
status: 200,
headers: { 'Content-Type': 'application/octet-stream' },
}),
),
);
mock.module('../src/utils/telegram', () => ({
getFileInfo: mockGetFileInfo,
}));
describe('File Route Handlers', () => {
let handleFileRedirect: typeof import('../src/routes/files').handleFileRedirect;
@@ -86,12 +77,10 @@ describe('File Route Handlers', () => {
beforeEach(async () => {
mockSelect.mockClear();
mockGetFile.mockClear();
mockGlobalFetch.mockClear();
mockGetFileInfo.mockClear();
// Set up mock token
process.env.BOT_TOKEN = '123456:ABC-DEF';
globalThis.fetch = mockGlobalFetch as any;
const filesRoute = await import('../src/routes/files');
handleFileRedirect = filesRoute.handleFileRedirect;
@@ -100,7 +89,6 @@ describe('File Route Handlers', () => {
afterAll(() => {
mock.restore();
globalThis.fetch = originalFetch;
});
describe('handleFileRedirect', () => {
+1
View File
@@ -28,6 +28,7 @@ mock.module('telegraf', () => {
constructor(token) {
this.token = token;
this.telegram = {
token: token,
sendPhoto: mock(() =>
Promise.resolve({
message_id: 12345,