1- import { afterAll , describe , expect , test , vi } from 'vitest'
1+ import { afterAll , afterEach , describe , expect , test , vi } from 'vitest'
22import { readFile } from 'node:fs/promises'
33
44import { File , Folder , davRemoteURL , davGetFavoritesReport , davRootPath , getFavoriteNodes , davResultToNode } from '../../lib'
55import { FileStat } from 'webdav'
6+ import * as auth from '@nextcloud/auth'
7+
68// required as default URL will be the DOM URL class which will use the window.location
79import { URL as FileURL } from 'node:url'
810
@@ -24,6 +26,10 @@ describe('DAV functions', () => {
2426} )
2527
2628describe ( 'davResultToNode' , ( ) => {
29+ afterEach ( ( ) => {
30+ vi . resetAllMocks ( )
31+ } )
32+
2733 /* Result of:
2834 davGetClient().getDirectoryContents(`${davRootPath}${path}`, { details: true })
2935 */
@@ -78,6 +84,18 @@ describe('davResultToNode', () => {
7884 expect ( node . path ) . toBe ( '/New folder/Neue Textdatei.md' )
7985 expect ( node . dirname ) . toBe ( '/New folder' )
8086 } )
87+
88+ // If owner-id is set, it will be used as owner
89+ test ( 'has correct owner set' , ( ) => {
90+ vi . spyOn ( auth , 'getCurrentUser' ) . mockReturnValue ( { uid : 'user1' , displayName : 'User 1' , isAdmin : false } )
91+
92+ result . props = { ...result . props , ...{ 'owner-id' : 'user1' } } as FileStat [ 'props' ]
93+ const remoteResult = { ...result , filename : '/root/New folder/Neue Textdatei.md' }
94+ const node = davResultToNode ( remoteResult , '/root' , 'http://example.com/remote.php/dav' )
95+
96+ expect ( node . isDavRessource ) . toBe ( true )
97+ expect ( node . owner ) . toBe ( 'user1' )
98+ } )
8199} )
82100
83101describe ( 'DAV requests' , ( ) => {
0 commit comments