Browse Source

test(app): tighten completedAt assertion to a call-time boundary

Replace toBeInstanceOf(Date) with a before/after timestamp window so
the test detects sentinel values (e.g. new Date(0)) or stale dates,
not just "some Date got stored". This is what actually matters for
the bug being fixed: completedAt must fall within the live download
window so that the expiration query `{ completedAt: { $lt: threshold } }`
includes it.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
tomoyuki-t 2 weeks ago
parent
commit
0df84954dc

+ 8 - 2
apps/app/src/features/page-bulk-export/server/service/page-bulk-export-job-cron/notify-export-result-and-clean-up.integ.ts

@@ -61,15 +61,21 @@ describe('PageBulkExportJobCronService.notifyExportResultAndCleanUp', () => {
     expect(job.completedAt).toBeUndefined();
 
     // act
+    const before = Date.now();
     await pageBulkExportJobCronService?.notifyExportResultAndCleanUp(
       SupportedAction.ACTION_PAGE_BULK_EXPORT_COMPLETED,
       job,
     );
+    const after = Date.now();
 
-    // assert
+    // assert: completedAt is a Date stamped during this call (not a sentinel
+    // like new Date(0) or a stale value), so the download-expiration query
+    // `{ completedAt: { $lt: thresholdDate } }` will correctly include it.
     const updated = await PageBulkExportJob.findById(job._id);
     expect(updated?.status).toBe(PageBulkExportJobStatus.completed);
-    expect(updated?.completedAt).toBeInstanceOf(Date);
+    const completedAtMs = updated?.completedAt?.getTime();
+    expect(completedAtMs).toBeGreaterThanOrEqual(before);
+    expect(completedAtMs).toBeLessThanOrEqual(after);
   });
 
   test('should preserve an already-set completedAt (normal completion path)', async () => {