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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ All notable changes to this project will be documented in this file.
* The support for Nextcloud versions below 30 has been removed,
this means some functions like filename validation will now only
work with the capabilities provided by Nextcloud 30 or newer.
* The Node API was changed, the `root` property of any node,
including `File` or `Folder`, is now required.

#### DAV related export
The DAV related exports from the main entry point were deprecated
Expand Down
11 changes: 11 additions & 0 deletions __tests__/files/cloning.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ describe('File cloning', () => {
test('Clone preserves attributes', () => {
const file = new File({
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg',
root: '/files/emma',
mime: 'image/jpeg',
owner: 'emma',
attributes: {
Expand All @@ -59,6 +60,7 @@ describe('File cloning', () => {
test('Clone is independent from original', () => {
const file = new File({
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg',
root: '/files/emma',
mime: 'image/jpeg',
owner: 'emma',
size: 100,
Expand All @@ -85,6 +87,7 @@ describe('File cloning', () => {
test('Clone works with minimal file', () => {
const file = new File({
source: 'https://cloud.domain.com/remote.php/dav/files/emma/file.txt',
root: '/files/emma',
owner: 'emma',
})

Expand All @@ -99,6 +102,7 @@ describe('File cloning', () => {
test('Clone works with remote file', () => {
const file = new File({
source: 'https://domain.com/Photos/picture.jpg',
root: '/',
mime: 'image/jpeg',
owner: null,
})
Expand Down Expand Up @@ -145,6 +149,7 @@ describe('File serialization and deserialization', () => {
test('toString and JSON.parse preserves attributes', () => {
const file = new File({
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg',
root: '/files/emma',
mime: 'image/jpeg',
owner: 'emma',
attributes: {
Expand All @@ -166,6 +171,7 @@ describe('File serialization and deserialization', () => {
test('toString and JSON.parse works with minimal file', () => {
const file = new File({
source: 'https://cloud.domain.com/remote.php/dav/files/emma/file.txt',
root: '/files/emma',
owner: 'emma',
})

Expand All @@ -181,6 +187,7 @@ describe('File serialization and deserialization', () => {
test('toString and JSON.parse is independent from original', () => {
const file = new File({
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg',
root: '/files/emma',
mime: 'image/jpeg',
owner: 'emma',
size: 100,
Expand All @@ -206,6 +213,7 @@ describe('File serialization and deserialization', () => {
test('toString and JSON.parse preserves displayname', () => {
const file = new File({
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg',
root: '/files/emma',
mime: 'image/jpeg',
owner: 'emma',
displayname: 'My Vacation Photo',
Expand All @@ -221,6 +229,7 @@ describe('File serialization and deserialization', () => {
test('toString and JSON.parse works with remote file', () => {
const file = new File({
source: 'https://domain.com/Photos/picture.jpg',
root: '/',
mime: 'image/jpeg',
owner: null,
})
Expand All @@ -245,6 +254,7 @@ describe('File serialization and deserialization', () => {
for (const status of statuses) {
const file = new File({
source: 'https://cloud.domain.com/remote.php/dav/files/emma/file.txt',
root: '/files/emma',
owner: 'emma',
status,
})
Expand All @@ -258,6 +268,7 @@ describe('File serialization and deserialization', () => {
test('toString output is valid JSON', () => {
const file = new File({
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg',
root: '/files/emma',
mime: 'image/jpeg',
owner: 'emma',
size: 12345,
Expand Down
31 changes: 21 additions & 10 deletions __tests__/files/file.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ describe('File creation', () => {
test('Valid dav file', () => {
const file = new File({
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg',
root: '/files/emma/Photos',
mime: 'image/jpeg',
owner: 'emma',
mtime: new Date(Date.UTC(2023, 0, 1, 0, 0, 0)),
Expand Down Expand Up @@ -45,9 +46,9 @@ describe('File creation', () => {
test('Valid dav file with root', () => {
const file = new File({
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg',
root: '/files/emma',
mime: 'image/jpeg',
owner: 'emma',
root: '/files/emma',
})

expect(file).toBeInstanceOf(File)
Expand All @@ -72,6 +73,7 @@ describe('File creation', () => {
test('Valid remote file', () => {
const file = new File({
source: 'https://domain.com/Photos/picture.jpg',
root: '/',
mime: 'image/jpeg',
owner: null,
})
Expand All @@ -89,7 +91,7 @@ describe('File creation', () => {
expect(file.basename).toBe('picture.jpg')
expect(file.extension).toBe('.jpg')
expect(file.dirname).toBe('/Photos')
expect(file.root).toBeNull()
expect(file.root).toBe('/')
expect(file.isDavResource).toBe(false)
expect(file.permissions).toBe(Permission.READ)
})
Expand All @@ -98,45 +100,48 @@ describe('File creation', () => {
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',
source: 'https://cloud.domain.com/remote.php/dav/files/emma/picture.jpg',
root: '/files/emma',
mime: 'image/jpeg',
owner: 'emma',
})

expect(file.basename).toBe('picture.jpg')
expect(file.dirname).toBe('/')
expect(file.root).toBe('/files/emma/Photos')
expect(file.root).toBe('/files/emma')

file.rename('picture-old.jpg')

expect(file.basename).toBe('picture-old.jpg')
expect(file.dirname).toBe('/')
expect(file.source).toBe('https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture-old.jpg')
expect(file.root).toBe('/files/emma/Photos')
expect(file.source).toBe('https://cloud.domain.com/remote.php/dav/files/emma/picture-old.jpg')
expect(file.root).toBe('/files/emma')
})

test('Moving a file', () => {
const file = new File({
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg',
root: '/files/emma',
mime: 'image/jpeg',
owner: 'emma',
})

expect(file.basename).toBe('picture.jpg')
expect(file.dirname).toBe('/')
expect(file.root).toBe('/files/emma/Photos')
expect(file.dirname).toBe('/Photos')
expect(file.root).toBe('/files/emma')

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('/')
expect(file.dirname).toBe('/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')
expect(file.root).toBe('/files/emma')
})

test('Moving a file to an invalid destination throws', () => {
const file = new File({
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg',
root: '/files/emma',
mime: 'image/jpeg',
owner: 'emma',
mtime: new Date(Date.UTC(2023, 0, 1, 0, 0, 0)),
Expand Down Expand Up @@ -184,6 +189,7 @@ describe('Altering attributes does NOT updates mtime', () => {
test('mtime is updated on existing attribute', () => {
const file = new File({
source: 'https://cloud.domain.com/remote.php/dav/files/emma',
root: '/files/emma',
mime: 'image/jpeg',
owner: 'emma',
mtime: new Date(Date.UTC(1990, 0, 1, 0, 0, 0)),
Expand All @@ -202,6 +208,7 @@ describe('Altering attributes does NOT updates mtime', () => {
test('mtime is NOT updated on new attribute', () => {
const file = new File({
source: 'https://cloud.domain.com/remote.php/dav/files/emma',
root: '/files/emma',
mime: 'image/jpeg',
owner: 'emma',
mtime: new Date(Date.UTC(1990, 0, 1, 0, 0, 0)),
Expand All @@ -217,6 +224,7 @@ describe('Altering attributes does NOT updates mtime', () => {
test('mtime is NOT updated on deleted attribute', () => {
const file = new File({
source: 'https://cloud.domain.com/remote.php/dav/files/emma',
root: '/files/emma',
mime: 'image/jpeg',
owner: 'emma',
mtime: new Date(Date.UTC(1990, 0, 1, 0, 0, 0)),
Expand All @@ -235,6 +243,7 @@ describe('Altering attributes does NOT updates mtime', () => {
test('mtime is NOT updated if not initially defined', () => {
const file = new File({
source: 'https://cloud.domain.com/remote.php/dav/files/emma',
root: '/files/emma',
mime: 'image/jpeg',
owner: 'emma',
permissions: Permission.READ,
Expand All @@ -254,6 +263,7 @@ describe('Altering top-level properties updates mtime', () => {
test('mtime is updated on permissions change', () => {
const file = new File({
source: 'https://cloud.domain.com/remote.php/dav/files/emma',
root: '/files/emma',
mime: 'image/jpeg',
owner: 'emma',
mtime: new Date(Date.UTC(1990, 0, 1, 0, 0, 0)),
Expand All @@ -271,6 +281,7 @@ describe('Altering top-level properties updates mtime', () => {
test('mtime is updated on size change', () => {
const file = new File({
source: 'https://cloud.domain.com/remote.php/dav/files/emma',
root: '/files/emma',
mime: 'image/jpeg',
owner: 'emma',
mtime: new Date(Date.UTC(1990, 0, 1, 0, 0, 0)),
Expand Down
6 changes: 5 additions & 1 deletion __tests__/files/folder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ describe('Folder creation', () => {
test('Valid dav folder', () => {
const folder = new Folder({
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/',
root: '/files/emma',
owner: 'emma',
})

Expand Down Expand Up @@ -61,6 +62,7 @@ describe('Folder creation', () => {
test('Valid remote folder', () => {
const folder = new Folder({
source: 'https://domain.com/Photos/',
root: '/',
owner: null,
})

Expand All @@ -77,7 +79,7 @@ describe('Folder creation', () => {
expect(folder.basename).toBe('Photos')
expect(folder.extension).toBeNull()
expect(folder.dirname).toBe('/')
expect(folder.root).toBeNull()
expect(folder.root).toBe('/')
expect(folder.isDavResource).toBe(false)
expect(folder.permissions).toBe(Permission.READ)
})
Expand All @@ -87,6 +89,7 @@ describe('Folder data change', () => {
test('Rename a folder', () => {
const folder = new Folder({
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos',
root: '/files/emma',
owner: 'emma',
})

Expand All @@ -105,6 +108,7 @@ describe('Folder data change', () => {
test('Moving a folder', () => {
const folder = new Folder({
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/',
root: '/files/emma',
owner: 'emma',
})

Expand Down
Loading