Skip to content

Sync-in · Sovereign platform for file storage, sharing, synchronization, and collaboration.

test(backend:comments): assert file lookup payloads

johaven3be3602997c2
diff --git a/backend/src/applications/comments/services/comments-manager.service.spec.ts b/backend/src/applications/comments/services/comments-manager.service.spec.ts
index 91be7e1a..8d4fa8c6 100644
--- a/backend/src/applications/comments/services/comments-manager.service.spec.ts
+++ b/backend/src/applications/comments/services/comments-manager.service.spec.ts
@@ -160,21 +160,26 @@ describe(CommentsManager.name, () => {
})
it('uses getOrCreate when fileId > 0 but file is not yet indexed', async () => {
+ const space = makeSpace()
+ const fileProps = { name: 'file.txt', path: 'folder', id: undefined }
filesQueries.getSpaceFileId.mockResolvedValue(undefined)
filesQueries.getOrCreateSpaceFile.mockResolvedValue(77)
commentQueries.createComment.mockResolvedValue(1)
commentQueries.getComments.mockResolvedValue([{ id: 1, fileId: 77, content: 'hi' }])
commentQueries.membersToNotify.mockResolvedValue([])
- const res = await commentsManager.createComment(user, makeSpace(), { fileId: 42, content: 'hi' } as any)
+ const res = await commentsManager.createComment(user, space, { fileId: 42, content: 'hi' } as any)
expect(filesQueries.getSpaceFileId).toHaveBeenCalledTimes(1)
- expect(filesQueries.getOrCreateSpaceFile).toHaveBeenCalledWith(42, expect.anything(), expect.anything())
+ expect(filesQueries.getSpaceFileId).toHaveBeenCalledWith(fileProps, space.dbFile)
+ expect(filesQueries.getOrCreateSpaceFile).toHaveBeenCalledWith(42, fileProps, space.dbFile)
expect(commentQueries.createComment).toHaveBeenCalledWith(42, 77, 'hi')
expect(res).toMatchObject({ id: 1, fileId: 77, content: 'hi' })
})
it('uses getOrCreate when fileId < 0', async () => {
+ const space = makeSpace()
+ const fileProps = { name: 'file.txt', path: 'folder', id: undefined }
filesQueries.getOrCreateSpaceFile.mockResolvedValue(555)
commentQueries.createComment.mockResolvedValue(777)
commentQueries.getComments.mockResolvedValue([{ id: 777, fileId: 555, content: 'hello' }])
@@ -182,11 +187,11 @@ describe(CommentsManager.name, () => {
commentQueries.membersToNotify.mockRejectedValueOnce(new Error('members failed'))
const loggerSpy = jest.spyOn(commentsManager['logger'], 'error').mockImplementation(() => undefined as any)
- const res = await commentsManager.createComment(user, makeSpace(), { fileId: -1, content: 'hello' } as any)
+ const res = await commentsManager.createComment(user, space, { fileId: -1, content: 'hello' } as any)
// Let the microtask run the catch of createComment
await new Promise((r) => setImmediate(r))
- expect(filesQueries.getOrCreateSpaceFile).toHaveBeenCalled()
+ expect(filesQueries.getOrCreateSpaceFile).toHaveBeenCalledWith(-1, fileProps, space.dbFile)
expect(filesQueries.getSpaceFileId).not.toHaveBeenCalled()
expect(commentQueries.createComment).toHaveBeenCalledWith(42, 555, 'hello')
expect(notificationsManager.create).not.toHaveBeenCalled()