diff --git a/__tests__/files/node.spec.ts b/__tests__/files/node.spec.ts index 77f4c5f9..42ecc844 100644 --- a/__tests__/files/node.spec.ts +++ b/__tests__/files/node.spec.ts @@ -8,7 +8,7 @@ describe('Node testing', () => { const file = new File({ source: 'https://cloud.domain.com/remote.php/dav/picture.jpg', mime: 'image/jpeg', - owner: 'emma' + owner: 'emma', }) expect(file.root).toBeNull() }) @@ -16,7 +16,7 @@ describe('Node testing', () => { test('Remove source ending slash', () => { const file = new Folder({ source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/', - owner: 'emma' + owner: 'emma', }) expect(file.source).toBe('https://cloud.domain.com/remote.php/dav/files/emma/Photos') }) @@ -24,7 +24,7 @@ describe('Node testing', () => { test('Invalid rename', () => { const file = new Folder({ source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/', - owner: 'emma' + owner: 'emma', }) expect(() => file.rename('new/folder')).toThrowError('Invalid basename') }) @@ -35,19 +35,29 @@ describe('FileId attribute', () => { const file = new File({ source: 'https://cloud.domain.com/remote.php/dav/picture.jpg', mime: 'image/jpeg', - owner: 'emma' + owner: 'emma', }) expect(file.fileid).toBeUndefined() }) - test('FileId source ending slash', () => { + test('FileId null fallback', () => { + const file = new File({ + source: 'https://cloud.domain.com/remote.php/dav/picture.jpg', + mime: 'image/jpeg', + owner: 'emma', + id: 1234, + }) + expect(file.fileid).toBe(1234) + }) + + test('FileId attributes fallback', () => { const file = new Folder({ source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/', mime: 'image/jpeg', owner: 'emma', attributes: { - fileid: 1234 - } + fileid: 1234, + }, }) expect(file.fileid).toBe(1234) }) diff --git a/lib/files/node.ts b/lib/files/node.ts index ebafd918..550c30ed 100644 --- a/lib/files/node.ts +++ b/lib/files/node.ts @@ -203,10 +203,11 @@ export abstract class Node { } /** - * Get the file id if defined in attributes + * Get the node id if defined. + * Will look for the fileid in attributes if undefined. */ get fileid(): number|undefined { - return this.attributes?.fileid + return this._data?.id || this.attributes?.fileid } /**