Skip to content
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
18 changes: 11 additions & 7 deletions __tests__/files/node.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ describe('FileId attribute', () => {
expect(file.fileid).toBe(1234)
})

// Mostly used when a node is unavailable
test('FileId negative 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/',
Expand All @@ -73,13 +84,6 @@ describe('Sanity checks', () => {
owner: 'emma',
id: '1234' as unknown as number,
})).toThrowError('Invalid id type of value')

expect(() => new File({
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg',
mime: 'image/jpeg',
owner: 'emma',
id: -1234,
})).toThrowError('Invalid id type of value')
})

test('Invalid source', () => {
Expand Down
2 changes: 1 addition & 1 deletion lib/files/nodeData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const isDavRessource = function(source: string, davService: RegExp): bool
* @param davService Pattern to check if source is DAV ressource
*/
export const validateData = (data: NodeData, davService: RegExp) => {
if (data.id && (typeof data.id !== 'number' || data.id < 0)) {
if (data.id && typeof data.id !== 'number') {
throw new Error('Invalid id type of value')
}

Expand Down