From 9796d428466f21adcfa42e04f04cbfe2d15aff3c Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Sat, 20 Jul 2024 02:55:55 +0800 Subject: [PATCH] refactor: improve logger and test case --- src/server/app.ts | 3 ++- src/server/model/feed/event.ts | 9 +++++++-- src/server/router/__test__/telemetry.test.ts | 4 ++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/server/app.ts b/src/server/app.ts index 2a89761..5352eb0 100644 --- a/src/server/app.ts +++ b/src/server/app.ts @@ -81,9 +81,10 @@ app.use('/*', (req, res, next) => { app.use(express.static('public')); // fallback +const webEntry = path.join(process.cwd(), 'public', 'index.html'); app.use('/*', (req, res) => { if (req.method === 'GET' && req.accepts('html')) { - res.sendFile(path.join(process.cwd(), 'public', 'index.html')); + res.sendFile(webEntry); } }); diff --git a/src/server/model/feed/event.ts b/src/server/model/feed/event.ts index abf7ce0..8d001b9 100644 --- a/src/server/model/feed/event.ts +++ b/src/server/model/feed/event.ts @@ -59,7 +59,7 @@ export async function createFeedEvent( export async function sendFeedEventsNotify( channel: Pick< z.infer, - 'name' | 'notifyFrequency' + 'id' | 'name' | 'notifyFrequency' > & { notifications: z.infer[]; }, @@ -95,7 +95,12 @@ export async function sendFeedEventsNotify( await Promise.all( channel.notifications.map((notification) => sendNotification(notification, 'Feed Report', eventTokens).catch((err) => - logger.error('[Notification] sendFeedEventsNotify', err) + logger.error( + '[Notification] sendFeedEventsNotify', + channel.id, + notification.id, + err + ) ) ) ); diff --git a/src/server/router/__test__/telemetry.test.ts b/src/server/router/__test__/telemetry.test.ts index aa9b801..3b82753 100644 --- a/src/server/router/__test__/telemetry.test.ts +++ b/src/server/router/__test__/telemetry.test.ts @@ -11,7 +11,7 @@ describe('telemetry router', () => { const telemetry = await createTestTelemetry(workspace.id); const { status } = await app.get( - `/telemetry/${workspace.id}/${telemetry.id}.svg` + `/telemetry/${workspace.id}/${telemetry.id}.gif` ); expect(status).toBe(200); @@ -22,7 +22,7 @@ describe('telemetry router', () => { const telemetry = await createTestTelemetry(workspace.id); const { status } = await app.get( - `/telemetry/${workspace.id}/${telemetry.id}.svg?name=tianji-oss&url=http://localhost:10000&v=1.8.2` + `/telemetry/${workspace.id}/${telemetry.id}.gif?name=tianji-oss&url=https://google.com&v=1.8.2` ); expect(status).toBe(200);