Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fileid definition and fallback #681

Merged
merged 1 commit into from
Jul 4, 2023
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
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
Loading