-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: John Molakvoæ (skjnldsv) <[email protected]>
- Loading branch information
Showing
10 changed files
with
690 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { File } from '../../lib/files/file' | ||
import { FileType } from '../../lib/files/node' | ||
import { Permission } from '../../lib/permissions' | ||
|
||
describe('File creation', () => { | ||
test('Valid dav file', () => { | ||
const file = new File({ | ||
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg', | ||
mime: 'image/jpeg', | ||
owner: 'emma' | ||
}) | ||
|
||
expect(file).toBeInstanceOf(File) | ||
expect(file.type).toBe(FileType.File) | ||
|
||
// various data | ||
expect(file.mime).toBe('image/jpeg') | ||
expect(file.owner).toBe('emma') | ||
expect(file.size).toBeUndefined() | ||
expect(file.attributes).toStrictEqual({}) | ||
|
||
// path checks | ||
expect(file.basename).toBe('picture.jpg') | ||
expect(file.extension).toBe('.jpg') | ||
expect(file.dirname).toBe('https://cloud.domain.com/remote.php/dav/files/emma/Photos') | ||
expect(file.root).toBe('/files/emma/Photos') | ||
expect(file.isDavRessource).toBe(true) | ||
expect(file.permissions).toBe(Permission.READ) | ||
}) | ||
|
||
test('Valid remote file', () => { | ||
const file = new File({ | ||
source: 'https://domain.com/Photos/picture.jpg', | ||
mime: 'image/jpeg', | ||
owner: null | ||
}) | ||
|
||
expect(file).toBeInstanceOf(File) | ||
expect(file.type).toBe(FileType.File) | ||
|
||
// various data | ||
expect(file.mime).toBe('image/jpeg') | ||
expect(file.owner).toBeNull() | ||
expect(file.size).toBeUndefined() | ||
expect(file.attributes).toStrictEqual({}) | ||
|
||
// path checks | ||
expect(file.basename).toBe('picture.jpg') | ||
expect(file.extension).toBe('.jpg') | ||
expect(file.dirname).toBe('https://domain.com/Photos') | ||
expect(file.root).toBeNull() | ||
expect(file.isDavRessource).toBe(false) | ||
expect(file.permissions).toBe(Permission.READ) | ||
}) | ||
}) | ||
|
||
describe('File data change', () => { | ||
test('Rename a file', () => { | ||
const file = new File({ | ||
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg', | ||
mime: 'image/jpeg', | ||
owner: 'emma' | ||
}) | ||
|
||
expect(file.basename).toBe('picture.jpg') | ||
expect(file.dirname).toBe('https://cloud.domain.com/remote.php/dav/files/emma/Photos') | ||
expect(file.root).toBe('/files/emma/Photos') | ||
|
||
file.rename('picture-old.jpg') | ||
|
||
expect(file.basename).toBe('picture-old.jpg') | ||
expect(file.dirname).toBe('https://cloud.domain.com/remote.php/dav/files/emma/Photos') | ||
expect(file.source).toBe('https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture-old.jpg') | ||
expect(file.root).toBe('/files/emma/Photos') | ||
}) | ||
|
||
test('Changing source', () => { | ||
const file = new File({ | ||
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg', | ||
mime: 'image/jpeg', | ||
owner: 'emma' | ||
}) | ||
|
||
expect(file.basename).toBe('picture.jpg') | ||
expect(file.dirname).toBe('https://cloud.domain.com/remote.php/dav/files/emma/Photos') | ||
expect(file.root).toBe('/files/emma/Photos') | ||
|
||
file.move('https://cloud.domain.com/remote.php/dav/files/emma/Pictures/picture-old.jpg') | ||
|
||
expect(file.basename).toBe('picture-old.jpg') | ||
expect(file.dirname).toBe('https://cloud.domain.com/remote.php/dav/files/emma/Pictures') | ||
expect(file.source).toBe('https://cloud.domain.com/remote.php/dav/files/emma/Pictures/picture-old.jpg') | ||
expect(file.root).toBe('/files/emma/Pictures') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { Folder } from '../../lib/files/folder' | ||
import { FileType } from '../../lib/files/node' | ||
import { Permission } from '../../lib/permissions' | ||
|
||
describe('File creation', () => { | ||
test('Valid dav folder', () => { | ||
const folder = new Folder({ | ||
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/', | ||
owner: 'emma' | ||
}) | ||
|
||
expect(folder).toBeInstanceOf(Folder) | ||
expect(folder.type).toBe(FileType.Folder) | ||
|
||
// various data | ||
expect(folder.mime).toBe('httpd/unix-directory') | ||
expect(folder.owner).toBe('emma') | ||
expect(folder.size).toBeUndefined() | ||
expect(folder.attributes).toStrictEqual({}) | ||
|
||
// path checks | ||
expect(folder.basename).toBe('Photos') | ||
expect(folder.extension).toBeNull() | ||
expect(folder.dirname).toBe('https://cloud.domain.com/remote.php/dav/files/emma') | ||
expect(folder.root).toBe('/files/emma') | ||
expect(folder.isDavRessource).toBe(true) | ||
expect(folder.permissions).toBe(Permission.READ) | ||
}) | ||
|
||
test('Valid remote folder', () => { | ||
const folder = new Folder({ | ||
source: 'https://domain.com/Photos/', | ||
owner: null | ||
}) | ||
|
||
expect(folder).toBeInstanceOf(Folder) | ||
expect(folder.type).toBe(FileType.Folder) | ||
|
||
// various data | ||
expect(folder.mime).toBe('httpd/unix-directory') | ||
expect(folder.owner).toBeNull() | ||
expect(folder.size).toBeUndefined() | ||
expect(folder.attributes).toStrictEqual({}) | ||
|
||
// path checks | ||
expect(folder.basename).toBe('Photos') | ||
expect(folder.extension).toBeNull() | ||
expect(folder.dirname).toBe('https://domain.com') | ||
expect(folder.root).toBeNull() | ||
expect(folder.isDavRessource).toBe(false) | ||
expect(folder.permissions).toBe(Permission.READ) | ||
}) | ||
}) | ||
|
||
describe('Folder data change', () => { | ||
test('Rename a folder', () => { | ||
const folder = new Folder({ | ||
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos', | ||
owner: 'emma' | ||
}) | ||
|
||
expect(folder.basename).toBe('Photos') | ||
expect(folder.dirname).toBe('https://cloud.domain.com/remote.php/dav/files/emma') | ||
expect(folder.root).toBe('/files/emma') | ||
|
||
folder.rename('Pictures') | ||
|
||
expect(folder.basename).toBe('Pictures') | ||
expect(folder.dirname).toBe('https://cloud.domain.com/remote.php/dav/files/emma') | ||
expect(folder.source).toBe('https://cloud.domain.com/remote.php/dav/files/emma/Pictures') | ||
expect(folder.root).toBe('/files/emma') | ||
}) | ||
|
||
test('Changing source', () => { | ||
const folder = new Folder({ | ||
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/', | ||
owner: 'emma' | ||
}) | ||
|
||
expect(folder.basename).toBe('Photos') | ||
expect(folder.dirname).toBe('https://cloud.domain.com/remote.php/dav/files/emma') | ||
expect(folder.root).toBe('/files/emma') | ||
|
||
folder.move('https://cloud.domain.com/remote.php/dav/files/emma/Pictures/') | ||
|
||
expect(folder.basename).toBe('Pictures') | ||
expect(folder.dirname).toBe('https://cloud.domain.com/remote.php/dav/files/emma') | ||
expect(folder.source).toBe('https://cloud.domain.com/remote.php/dav/files/emma/Pictures') | ||
expect(folder.root).toBe('/files/emma') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import { File } from '../../lib/files/file' | ||
import { Folder } from '../../lib/files/folder' | ||
import NodeData, { Attribute } from '../../lib/files/nodeData' | ||
|
||
describe('Node testing', () => { | ||
test('Root null fallback', () => { | ||
const file = new File({ | ||
source: 'https://cloud.domain.com/remote.php/dav/picture.jpg', | ||
mime: 'image/jpeg', | ||
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' | ||
}) | ||
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' | ||
}) | ||
expect(() => file.rename('new/folder')).toThrowError('Invalid basename') | ||
}) | ||
}) | ||
|
||
describe('Sanity checks', () => { | ||
test('Invalid id', () => { | ||
expect(() => new File({ | ||
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg', | ||
mime: 'image/jpeg', | ||
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', () => { | ||
expect(() => new File({} as unknown as NodeData)).toThrowError('Missing mandatory source') | ||
expect(() => new File({ | ||
source: 'cloud.domain.com/remote.php/dav/Photos', | ||
mime: 'image/jpeg', | ||
owner: 'emma' | ||
})).toThrowError('Invalid source') | ||
expect(() => new File({ | ||
source: '/remote.php/dav/files/emma/Photos/picture.jpg', | ||
mime: 'image/jpeg', | ||
owner: 'emma' | ||
})).toThrowError('Invalid source') | ||
|
||
}) | ||
|
||
test('Invalid mtime', () => { | ||
expect(() => new File({ | ||
source: 'https://cloud.domain.com/remote.php/dav/Photos', | ||
mime: 'image', | ||
owner: 'emma', | ||
mtime: 'invalid' as unknown as Date | ||
})).toThrowError('Invalid mtime type') | ||
}) | ||
|
||
|
||
test('Invalid crtime', () => { | ||
expect(() => new File({ | ||
source: 'https://cloud.domain.com/remote.php/dav/Photos', | ||
mime: 'image', | ||
owner: 'emma', | ||
crtime: 'invalid' as unknown as Date | ||
})).toThrowError('Invalid crtime type') | ||
}) | ||
|
||
test('Invalid mime', () => { | ||
expect(() => new File({ | ||
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg', | ||
mime: 'image', | ||
owner: 'emma' | ||
})).toThrowError('Missing or invalid mandatory mime') | ||
}) | ||
|
||
test('Invalid attributes', () => { | ||
expect(() => new File({ | ||
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg', | ||
mime: 'image/jpeg', | ||
owner: 'emma', | ||
attributes: 'test' as unknown as Attribute, | ||
})).toThrowError('Invalid attributes format') | ||
}) | ||
|
||
test('Invalid permissions', () => { | ||
expect(() => new File({ | ||
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg', | ||
mime: 'image/jpeg', | ||
owner: 'emma', | ||
permissions: 324, | ||
})).toThrowError('Invalid permissions') | ||
}) | ||
|
||
test('Invalid size', () => { | ||
expect(() => new File({ | ||
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg', | ||
mime: 'image/jpeg', | ||
owner: 'emma', | ||
size: 'test' as unknown as number, | ||
})).toThrowError('Invalid size type') | ||
}) | ||
|
||
test('Invalid owner', () => { | ||
expect(() => new File({ | ||
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg', | ||
mime: 'image/jpeg', | ||
owner: true as unknown as string, | ||
})).toThrowError('Invalid owner') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* @copyright Copyright (c) 2022 John Molakvoæ <[email protected]> | ||
* | ||
* @author John Molakvoæ <[email protected]> | ||
* | ||
* @license AGPL-3.0-or-later | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
import Node, {FileType} from './node' | ||
|
||
export class File extends Node { | ||
get type(): FileType { | ||
return FileType.File | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* @copyright Copyright (c) 2022 John Molakvoæ <[email protected]> | ||
* | ||
* @author John Molakvoæ <[email protected]> | ||
* | ||
* @license AGPL-3.0-or-later | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
import Node, { FileType } from './node' | ||
import NodeData from './nodeData' | ||
|
||
export class Folder extends Node { | ||
constructor(data: NodeData) { | ||
// enforcing mimes | ||
super({ | ||
...data, | ||
mime: 'httpd/unix-directory' | ||
}) | ||
} | ||
|
||
get type(): FileType { | ||
return FileType.Folder | ||
} | ||
|
||
get extension(): string|null { | ||
return null | ||
} | ||
|
||
get mime(): string { | ||
return 'httpd/unix-directory' | ||
} | ||
} |
Oops, something went wrong.