Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion __tests__/dav/dav.spec.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -24,6 +26,10 @@ describe('DAV functions', () => {
})

describe('davResultToNode', () => {
afterEach(() => {
vi.resetAllMocks()
})

/* Result of:
davGetClient().getDirectoryContents(`${davRootPath}${path}`, { details: true })
*/
Expand Down Expand Up @@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion lib/dav/dav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add owner-id to ResponseProps as string | undefined? Then you do not need to cast later and it is more clear that it exists

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,
Expand Down