Skip to content

Commit

Permalink
fix: fileid definition and fallback
Browse files Browse the repository at this point in the history
Signed-off-by: John Molakvoæ <[email protected]>
  • Loading branch information
skjnldsv committed Jul 4, 2023
1 parent 4629f39 commit f5dd53f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
24 changes: 17 additions & 7 deletions __tests__/files/node.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ 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()
})

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')
})

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')
})
Expand All @@ -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)
})
Expand Down
5 changes: 3 additions & 2 deletions lib/files/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/**
Expand Down

0 comments on commit f5dd53f

Please sign in to comment.