Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🐛 fix: update generationBatch tests to match filesToDelete refactor

YuTengjing8f2e72d1b85c
diff --git a/packages/database/src/models/__tests__/generationBatch.test.ts b/packages/database/src/models/__tests__/generationBatch.test.ts
index b80b4295777..17f6d53506b 100644
--- a/packages/database/src/models/__tests__/generationBatch.test.ts
+++ b/packages/database/src/models/__tests__/generationBatch.test.ts
@@ -474,7 +474,7 @@ describe('GenerationBatchModel', () => {
...testBatch,
userId,
});
- expect(result!.thumbnailUrls).toEqual(['thumbnail-url.jpg']);
+ expect(result!.filesToDelete).toEqual(['asset-url.jpg', 'thumbnail-url.jpg']);
// Verify batch was actually deleted from database
const deletedBatch = await serverDB.query.generationBatches.findFirst({
@@ -483,6 +483,40 @@ describe('GenerationBatchModel', () => {
expect(deletedBatch).toBeUndefined();
});
+ it('should delete a video generation batch and collect all asset URLs', async () => {
+ const [createdBatch] = await serverDB
+ .insert(generationBatches)
+ .values({ ...testBatch, userId })
+ .returning();
+
+ await serverDB.insert(generations).values({
+ ...testGeneration,
+ generationBatchId: createdBatch.id,
+ asset: {
+ coverUrl: 'cover.jpg',
+ duration: 5,
+ height: 720,
+ thumbnailUrl: 'thumbnail.jpg',
+ type: 'video',
+ url: 'video.mp4',
+ width: 1280,
+ },
+ });
+
+ const result = await generationBatchModel.delete(createdBatch.id);
+
+ expect(result).toBeDefined();
+ expect(result!.filesToDelete).toHaveLength(3);
+ expect(result!.filesToDelete).toContain('video.mp4');
+ expect(result!.filesToDelete).toContain('thumbnail.jpg');
+ expect(result!.filesToDelete).toContain('cover.jpg');
+
+ const deletedBatch = await serverDB.query.generationBatches.findFirst({
+ where: eq(generationBatches.id, createdBatch.id),
+ });
+ expect(deletedBatch).toBeUndefined();
+ });
+
it('should collect multiple thumbnail URLs from multiple generations', async () => {
const [createdBatch] = await serverDB
.insert(generationBatches)
@@ -520,9 +554,11 @@ describe('GenerationBatchModel', () => {
const result = await generationBatchModel.delete(createdBatch.id);
expect(result).toBeDefined();
- expect(result!.thumbnailUrls).toHaveLength(2);
- expect(result!.thumbnailUrls).toContain('thumbnail1.jpg');
- expect(result!.thumbnailUrls).toContain('thumbnail2.jpg');
+ expect(result!.filesToDelete).toHaveLength(4);
+ expect(result!.filesToDelete).toContain('asset1.jpg');
+ expect(result!.filesToDelete).toContain('thumbnail1.jpg');
+ expect(result!.filesToDelete).toContain('asset2.jpg');
+ expect(result!.filesToDelete).toContain('thumbnail2.jpg');
});
it('should return empty thumbnail URLs when no generations have thumbnails', async () => {
@@ -535,7 +571,7 @@ describe('GenerationBatchModel', () => {
expect(result).toBeDefined();
expect(result!.deletedBatch.id).toBe(createdBatch.id);
- expect(result!.thumbnailUrls).toEqual([]);
+ expect(result!.filesToDelete).toEqual([]);
});
it('should return undefined when trying to delete non-existent batch', async () => {
diff --git a/src/server/routers/lambda/__tests__/generationBatch.test.ts b/src/server/routers/lambda/__tests__/generationBatch.test.ts
index 17c0749c984..0c47129d327 100644
--- a/src/server/routers/lambda/__tests__/generationBatch.test.ts
+++ b/src/server/routers/lambda/__tests__/generationBatch.test.ts
@@ -74,7 +74,7 @@ describe('generationBatchRouter', () => {
const mockDelete = vi.fn().mockResolvedValue({
deletedBatch: mockDeletedBatch,
- thumbnailUrls: [], // 没有缩略图
+ filesToDelete: [], // 没有缩略图
});
const mockDeleteFiles = vi.fn();
@@ -121,7 +121,7 @@ describe('generationBatchRouter', () => {
const mockDelete = vi.fn().mockResolvedValue({
deletedBatch: mockDeletedBatch,
- thumbnailUrls: mockThumbnailUrls,
+ filesToDelete: mockThumbnailUrls,
});
const mockDeleteFiles = vi.fn().mockResolvedValue(true);
@@ -168,7 +168,7 @@ describe('generationBatchRouter', () => {
const mockDelete = vi.fn().mockResolvedValue({
deletedBatch: mockDeletedBatch,
- thumbnailUrls: mockThumbnailUrls,
+ filesToDelete: mockThumbnailUrls,
});
// Mock thumbnail deletion to fail
@@ -197,7 +197,7 @@ describe('generationBatchRouter', () => {
expect(mockDelete).toHaveBeenCalledWith(mockBatchId);
expect(mockDeleteFiles).toHaveBeenCalledWith(mockThumbnailUrls);
expect(consoleSpy).toHaveBeenCalledWith(
- 'Failed to delete thumbnail files from S3:',
+ 'Failed to delete files from S3:',
expect.any(Error),
);
@@ -254,7 +254,7 @@ describe('generationBatchRouter', () => {
const mockDelete = vi.fn().mockResolvedValue({
deletedBatch: mockDeletedBatch,
- thumbnailUrls: mockThumbnailUrls,
+ filesToDelete: mockThumbnailUrls,
});
const mockDeleteFiles = vi.fn().mockResolvedValue(true);
@@ -336,7 +336,7 @@ describe('generationBatchRouter', () => {
const mockDelete = vi.fn().mockResolvedValue({
deletedBatch: mockDeletedBatch,
- thumbnailUrls: mockThumbnailUrls,
+ filesToDelete: mockThumbnailUrls,
});
// Mock partial failure - some thumbnails could not be deleted
@@ -367,7 +367,7 @@ describe('generationBatchRouter', () => {
expect(mockDelete).toHaveBeenCalledWith(mockBatchId);
expect(mockDeleteFiles).toHaveBeenCalledWith(mockThumbnailUrls);
expect(consoleSpy).toHaveBeenCalledWith(
- 'Failed to delete thumbnail files from S3:',
+ 'Failed to delete files from S3:',
expect.any(Error),
);