@@ -15,19 +15,14 @@ import { FormatUtils } from '../../../src/utils/format.utils';
1515import { WebDavRequestedResource } from '../../../src/types/webdav.types' ;
1616import { WebDavUtils } from '../../../src/utils/webdav.utils' ;
1717import mime from 'mime-types' ;
18- import crypto , { randomUUID } from 'node:crypto' ;
18+ import crypto from 'node:crypto' ;
1919import { UsageService } from '../../../src/services/usage.service' ;
2020import { XMLUtils } from '../../../src/utils/xml.utils' ;
21+ import { DriveFileItem , DriveFolderItem } from '../../../src/types/drive.types' ;
2122
22- vi . mock ( 'node:crypto' , async ( ) => {
23- const actual = await vi . importActual < typeof import ( 'node:crypto' ) > ( 'node:crypto' ) ;
24- return {
25- ...( actual as object ) ,
26- randomUUID : vi . fn ( ) . mockImplementation ( actual . randomUUID ) ,
27- } ;
28- } ) ;
29-
30- const randomUUIDStub = vi . mocked ( randomUUID ) ;
23+ const getExpectedETag = ( item : DriveFileItem | DriveFolderItem ) : string => {
24+ return WebDavUtils . getItemETag ( item ) . replaceAll ( '"' , '' ) ;
25+ } ;
3126
3227describe ( 'PROPFIND request handler' , ( ) => {
3328 let sut : PROPFINDRequestHandler ;
@@ -57,11 +52,8 @@ describe('PROPFIND request handler', () => {
5752 } ) ;
5853 const usageFixture = crypto . randomInt ( 2000000000 ) ;
5954 const spaceLimitFixture = crypto . randomInt ( 2000000000 ) ;
60- const uuidFixture = 'test-test-test-test-test' ;
61- const etagFixture = uuidFixture . replaceAll ( '-' , '' ) ;
55+ const etagFixture = getExpectedETag ( folderFixture ) ;
6256
63- randomUUIDStub . mockClear ( ) ;
64- randomUUIDStub . mockImplementation ( ( ) => uuidFixture ) ;
6557 const getRequestedResourceStub = vi
6658 . spyOn ( WebDavUtils , 'getRequestedResource' )
6759 . mockResolvedValue ( requestedFolderResource ) ;
@@ -141,11 +133,16 @@ describe('PROPFIND request handler', () => {
141133 } ) ;
142134 const usageFixture = crypto . randomInt ( 2000000000 ) ;
143135 const spaceLimitFixture = crypto . randomInt ( 2000000000 ) ;
144- const uuidFixture = 'test-test-test-test-test' ;
145- const etagFixture = uuidFixture . replaceAll ( '-' , '' ) ;
146-
147- randomUUIDStub . mockClear ( ) ;
148- randomUUIDStub . mockImplementation ( ( ) => uuidFixture ) ;
136+ const etagFixture = getExpectedETag ( folderFixture ) ;
137+ const childEtagFixture = getExpectedETag (
138+ newFolderItem ( {
139+ uuid : paginatedFolder1 . uuid ,
140+ createdAt : new Date ( paginatedFolder1 . createdAt ) ,
141+ updatedAt : new Date ( paginatedFolder1 . updatedAt ) ,
142+ creationTime : new Date ( paginatedFolder1 . creationTime ) ,
143+ modificationTime : new Date ( paginatedFolder1 . modificationTime ) ,
144+ } ) ,
145+ ) ;
149146
150147 const getRequestedResourceStub = vi
151148 . spyOn ( WebDavUtils , 'getRequestedResource' )
@@ -163,7 +160,7 @@ describe('PROPFIND request handler', () => {
163160 await sut . handle ( request , response ) ;
164161 expect ( response . status ) . toHaveBeenCalledWith ( 207 ) ;
165162 expect ( response . send ) . toHaveBeenCalledWith (
166- `<?xml version="1.0" encoding="utf-8" ?><D:multistatus xmlns:D="DAV:"><D:response><D:href>${ XMLUtils . encodeWebDavUri ( '/' ) } </D:href><D:propstat><D:status>HTTP/1.1 200 OK</D:status><D:prop><D:getcontenttype>httpd/unix-directory</D:getcontenttype><D:getetag>"${ etagFixture } "</D:getetag><x1:lastmodified xmlns:x1="SAR:">${ FormatUtils . formatDateForWebDav ( folderFixture . updatedAt ) } </x1:lastmodified><x2:executable xmlns:x2="http://apache.org/dav/props/">F</x2:executable><x3:Win32FileAttributes xmlns:x3="urn:schemas-microsoft-com:">00000030</x3:Win32FileAttributes><D:quota-available-bytes>${ spaceLimitFixture - usageFixture } </D:quota-available-bytes><D:quota-used-bytes>${ usageFixture } </D:quota-used-bytes><D:resourcetype><D:collection/></D:resourcetype></D:prop></D:propstat></D:response><D:response><D:href>${ XMLUtils . encodeWebDavUri ( `/${ paginatedFolder1 . plainName } /` ) } </D:href><D:propstat><D:status>HTTP/1.1 200 OK</D:status><D:prop><D:displayname>${ paginatedFolder1 . plainName } </D:displayname><D:getlastmodified>${ FormatUtils . formatDateForWebDav ( paginatedFolder1 . updatedAt ) } </D:getlastmodified><D:getcontentlength>0</D:getcontentlength><D:getcontenttype>httpd/unix-directory</D:getcontenttype><D:getetag>"${ etagFixture } "</D:getetag><D:resourcetype><D:collection/></D:resourcetype></D:prop></D:propstat></D:response></D:multistatus>` ,
163+ `<?xml version="1.0" encoding="utf-8" ?><D:multistatus xmlns:D="DAV:"><D:response><D:href>${ XMLUtils . encodeWebDavUri ( '/' ) } </D:href><D:propstat><D:status>HTTP/1.1 200 OK</D:status><D:prop><D:getcontenttype>httpd/unix-directory</D:getcontenttype><D:getetag>"${ etagFixture } "</D:getetag><x1:lastmodified xmlns:x1="SAR:">${ FormatUtils . formatDateForWebDav ( folderFixture . updatedAt ) } </x1:lastmodified><x2:executable xmlns:x2="http://apache.org/dav/props/">F</x2:executable><x3:Win32FileAttributes xmlns:x3="urn:schemas-microsoft-com:">00000030</x3:Win32FileAttributes><D:quota-available-bytes>${ spaceLimitFixture - usageFixture } </D:quota-available-bytes><D:quota-used-bytes>${ usageFixture } </D:quota-used-bytes><D:resourcetype><D:collection/></D:resourcetype></D:prop></D:propstat></D:response><D:response><D:href>${ XMLUtils . encodeWebDavUri ( `/${ paginatedFolder1 . plainName } /` ) } </D:href><D:propstat><D:status>HTTP/1.1 200 OK</D:status><D:prop><D:displayname>${ paginatedFolder1 . plainName } </D:displayname><D:getlastmodified>${ FormatUtils . formatDateForWebDav ( paginatedFolder1 . updatedAt ) } </D:getlastmodified><D:getcontentlength>0</D:getcontentlength><D:getcontenttype>httpd/unix-directory</D:getcontenttype><D:getetag>"${ childEtagFixture } "</D:getetag><D:resourcetype><D:collection/></D:resourcetype></D:prop></D:propstat></D:response></D:multistatus>` ,
167164 ) ;
168165 expect ( getRequestedResourceStub ) . toHaveBeenCalledOnce ( ) ;
169166 expect ( getAndSearchItemFromResourceStub ) . toHaveBeenCalledOnce ( ) ;
@@ -224,8 +221,7 @@ describe('PROPFIND request handler', () => {
224221 } ) ;
225222
226223 const fileFixture = newFileItem ( { name : 'file' , type : 'png' } ) ;
227- const uuidFixture = 'test-test-test-test-test' ;
228- const etagFixture = uuidFixture . replaceAll ( '-' , '' ) ;
224+ const etagFixture = getExpectedETag ( fileFixture ) ;
229225 const mimeFixture = 'image/png' ;
230226
231227 const getRequestedResourceStub = vi
@@ -234,8 +230,6 @@ describe('PROPFIND request handler', () => {
234230 const getAndSearchItemFromResourceStub = vi
235231 . spyOn ( WebDavUtils , 'getDriveItemFromResource' )
236232 . mockResolvedValue ( fileFixture ) ;
237- randomUUIDStub . mockClear ( ) ;
238- randomUUIDStub . mockImplementation ( ( ) => uuidFixture ) ;
239233 const mimeLookupStub = vi . spyOn ( mime , 'lookup' ) . mockReturnValue ( mimeFixture ) ;
240234
241235 await sut . handle ( request , response ) ;
@@ -245,7 +239,6 @@ describe('PROPFIND request handler', () => {
245239 ) ;
246240 expect ( getRequestedResourceStub ) . toHaveBeenCalledOnce ( ) ;
247241 expect ( getAndSearchItemFromResourceStub ) . toHaveBeenCalledOnce ( ) ;
248- expect ( randomUUIDStub ) . toHaveBeenCalledOnce ( ) ;
249242 expect ( mimeLookupStub ) . toHaveBeenCalledOnce ( ) ;
250243 } ) ;
251244
0 commit comments