diff --git a/apps/worker/src/queues/index.processor.test.ts b/apps/worker/src/queues/index.processor.test.ts index 267c2bb..139180a 100644 --- a/apps/worker/src/queues/index.processor.test.ts +++ b/apps/worker/src/queues/index.processor.test.ts @@ -56,4 +56,11 @@ describe('processIndexJob', () => { expect.objectContaining({ approvedAt: new Date('2026-01-01T00:00:00.000Z').getTime() }), ); }); + + it('throws for invalid approvedAt string', async () => { + const mockClient = {} as any; + await expect(processIndexJob(makeJob({ approvedAt: 'not-a-date' }), mockClient)).rejects.toThrow( + 'Invalid approvedAt timestamp: "not-a-date"', + ); + }); }); diff --git a/apps/worker/src/queues/index.processor.ts b/apps/worker/src/queues/index.processor.ts index 30f8168..e49d554 100644 --- a/apps/worker/src/queues/index.processor.ts +++ b/apps/worker/src/queues/index.processor.ts @@ -4,6 +4,10 @@ import { MeiliSearch, MeiliDocument, indexMessage } from '@tower/search'; import { parseRedisUrl } from './redis-connection'; export async function processIndexJob(job: IndexJobData, meiliClient: MeiliSearch): Promise { + const approvedAt = new Date(job.approvedAt).getTime(); + if (Number.isNaN(approvedAt)) { + throw new Error(`Invalid approvedAt timestamp: "${job.approvedAt}"`); + } const doc: MeiliDocument = { id: job.messageId, content: job.content, @@ -12,7 +16,7 @@ export async function processIndexJob(job: IndexJobData, meiliClient: MeiliSearc sourceGroupName: job.sourceGroupName, tags: job.tags, platform: job.platform, - approvedAt: new Date(job.approvedAt).getTime(), + approvedAt, }; await indexMessage(meiliClient, doc); }