diff --git a/__tests__/dav/dav.spec.ts b/__tests__/dav/dav.spec.ts index d7698750c..7af0f0e50 100644 --- a/__tests__/dav/dav.spec.ts +++ b/__tests__/dav/dav.spec.ts @@ -1,8 +1,10 @@ -import { afterAll, describe, expect, test, vi } from 'vitest' +import { afterAll, afterEach, describe, expect, test, vi } from 'vitest' import { readFile } from 'node:fs/promises' import { File, Folder, davRemoteURL, davGetFavoritesReport, davRootPath, getFavoriteNodes, davResultToNode } from '../../lib' import { FileStat } from 'webdav' +import * as auth from '@nextcloud/auth' + // required as default URL will be the DOM URL class which will use the window.location import { URL as FileURL } from 'node:url' @@ -24,6 +26,10 @@ describe('DAV functions', () => { }) describe('davResultToNode', () => { + afterEach(() => { + vi.resetAllMocks() + }) + /* Result of: davGetClient().getDirectoryContents(`${davRootPath}${path}`, { details: true }) */ @@ -78,6 +84,18 @@ describe('davResultToNode', () => { expect(node.path).toBe('/New folder/Neue Textdatei.md') expect(node.dirname).toBe('/New folder') }) + + // If owner-id is set, it will be used as owner + test('has correct owner set', () => { + vi.spyOn(auth, 'getCurrentUser').mockReturnValue({ uid: 'user1', displayName: 'User 1', isAdmin: false }) + + result.props = { ...result.props, ...{ 'owner-id': 'user1' } } as FileStat['props'] + const remoteResult = { ...result, filename: '/root/New folder/Neue Textdatei.md' } + const node = davResultToNode(remoteResult, '/root', 'http://example.com/remote.php/dav') + + expect(node.isDavRessource).toBe(true) + expect(node.owner).toBe('user1') + }) }) describe('DAV requests', () => { diff --git a/lib/dav/dav.ts b/lib/dav/dav.ts index 931da5f6b..2512f927d 100644 --- a/lib/dav/dav.ts +++ b/lib/dav/dav.ts @@ -143,7 +143,7 @@ export const getFavoriteNodes = async (davClient: WebDAVClient, path = '/', davR export const davResultToNode = function(node: FileStat, filesRoot = davRootPath, remoteURL = davRemoteURL): Node { const props = node.props as ResponseProps const permissions = davParsePermissions(props?.permissions) - const owner = getCurrentUser()?.uid as string + const owner = props?.['owner-id'] as string || getCurrentUser()?.uid as string const nodeData: NodeData = { id: (props?.fileid as number) || 0,