Skip to content

Commit d2a45d0

Browse files
committed
more
1 parent 752d72c commit d2a45d0

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* @vitest-environment node
3+
*/
4+
import { workspaceFiles } from '@sim/db/schema'
5+
import { dbChainMockFns, queueTableRows, resetDbChainMock } from '@sim/testing'
6+
import { beforeEach, describe, expect, it, vi } from 'vitest'
7+
import { insertFileMetadata } from '@/lib/uploads/server/metadata'
8+
9+
describe('insertFileMetadata content versions', () => {
10+
beforeEach(() => {
11+
vi.clearAllMocks()
12+
resetDbChainMock()
13+
})
14+
15+
it('advances the content version when a replacement upload restores a deleted row', async () => {
16+
const deleted = {
17+
id: 'file-1',
18+
key: 'workspace/workspace-1/file.txt',
19+
deletedAt: new Date('2026-08-03T00:00:00.000Z'),
20+
contentUpdatedAt: new Date('2026-08-03T00:00:00.000Z'),
21+
}
22+
const restored = {
23+
...deleted,
24+
deletedAt: null,
25+
contentUpdatedAt: new Date('2026-08-04T00:00:00.000Z'),
26+
}
27+
queueTableRows(workspaceFiles, [deleted])
28+
dbChainMockFns.returning.mockResolvedValueOnce([restored])
29+
30+
await expect(
31+
insertFileMetadata({
32+
key: deleted.key,
33+
userId: 'user-1',
34+
workspaceId: 'workspace-1',
35+
context: 'workspace',
36+
originalName: 'file.txt',
37+
contentType: 'text/plain',
38+
size: 12,
39+
})
40+
).resolves.toEqual(restored)
41+
42+
expect(dbChainMockFns.set).toHaveBeenCalledWith(
43+
expect.objectContaining({ contentUpdatedAt: expect.anything() })
44+
)
45+
})
46+
})

0 commit comments

Comments
 (0)