Skip to content

Commit 7b5c05e

Browse files
committed
refactor(Node)!: make Node.root a required attribute
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent f442781 commit 7b5c05e

9 files changed

Lines changed: 191 additions & 150 deletions

File tree

__tests__/files/cloning.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ describe('File cloning', () => {
3939
test('Clone preserves attributes', () => {
4040
const file = new File({
4141
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg',
42+
root: '/files/emma',
4243
mime: 'image/jpeg',
4344
owner: 'emma',
4445
attributes: {
@@ -59,6 +60,7 @@ describe('File cloning', () => {
5960
test('Clone is independent from original', () => {
6061
const file = new File({
6162
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg',
63+
root: '/files/emma',
6264
mime: 'image/jpeg',
6365
owner: 'emma',
6466
size: 100,
@@ -85,6 +87,7 @@ describe('File cloning', () => {
8587
test('Clone works with minimal file', () => {
8688
const file = new File({
8789
source: 'https://cloud.domain.com/remote.php/dav/files/emma/file.txt',
90+
root: '/files/emma',
8891
owner: 'emma',
8992
})
9093

@@ -99,6 +102,7 @@ describe('File cloning', () => {
99102
test('Clone works with remote file', () => {
100103
const file = new File({
101104
source: 'https://domain.com/Photos/picture.jpg',
105+
root: '/',
102106
mime: 'image/jpeg',
103107
owner: null,
104108
})
@@ -145,6 +149,7 @@ describe('File serialization and deserialization', () => {
145149
test('toString and JSON.parse preserves attributes', () => {
146150
const file = new File({
147151
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg',
152+
root: '/files/emma',
148153
mime: 'image/jpeg',
149154
owner: 'emma',
150155
attributes: {
@@ -166,6 +171,7 @@ describe('File serialization and deserialization', () => {
166171
test('toString and JSON.parse works with minimal file', () => {
167172
const file = new File({
168173
source: 'https://cloud.domain.com/remote.php/dav/files/emma/file.txt',
174+
root: '/files/emma',
169175
owner: 'emma',
170176
})
171177

@@ -181,6 +187,7 @@ describe('File serialization and deserialization', () => {
181187
test('toString and JSON.parse is independent from original', () => {
182188
const file = new File({
183189
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg',
190+
root: '/files/emma',
184191
mime: 'image/jpeg',
185192
owner: 'emma',
186193
size: 100,
@@ -206,6 +213,7 @@ describe('File serialization and deserialization', () => {
206213
test('toString and JSON.parse preserves displayname', () => {
207214
const file = new File({
208215
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg',
216+
root: '/files/emma',
209217
mime: 'image/jpeg',
210218
owner: 'emma',
211219
displayname: 'My Vacation Photo',
@@ -221,6 +229,7 @@ describe('File serialization and deserialization', () => {
221229
test('toString and JSON.parse works with remote file', () => {
222230
const file = new File({
223231
source: 'https://domain.com/Photos/picture.jpg',
232+
root: '/',
224233
mime: 'image/jpeg',
225234
owner: null,
226235
})
@@ -245,6 +254,7 @@ describe('File serialization and deserialization', () => {
245254
for (const status of statuses) {
246255
const file = new File({
247256
source: 'https://cloud.domain.com/remote.php/dav/files/emma/file.txt',
257+
root: '/files/emma',
248258
owner: 'emma',
249259
status,
250260
})
@@ -258,6 +268,7 @@ describe('File serialization and deserialization', () => {
258268
test('toString output is valid JSON', () => {
259269
const file = new File({
260270
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg',
271+
root: '/files/emma',
261272
mime: 'image/jpeg',
262273
owner: 'emma',
263274
size: 12345,

__tests__/files/file.spec.ts

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ describe('File creation', () => {
1111
test('Valid dav file', () => {
1212
const file = new File({
1313
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg',
14+
root: '/files/emma/Photos',
1415
mime: 'image/jpeg',
1516
owner: 'emma',
1617
mtime: new Date(Date.UTC(2023, 0, 1, 0, 0, 0)),
@@ -45,9 +46,9 @@ describe('File creation', () => {
4546
test('Valid dav file with root', () => {
4647
const file = new File({
4748
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg',
49+
root: '/files/emma',
4850
mime: 'image/jpeg',
4951
owner: 'emma',
50-
root: '/files/emma',
5152
})
5253

5354
expect(file).toBeInstanceOf(File)
@@ -72,6 +73,7 @@ describe('File creation', () => {
7273
test('Valid remote file', () => {
7374
const file = new File({
7475
source: 'https://domain.com/Photos/picture.jpg',
76+
root: '/',
7577
mime: 'image/jpeg',
7678
owner: null,
7779
})
@@ -89,7 +91,7 @@ describe('File creation', () => {
8991
expect(file.basename).toBe('picture.jpg')
9092
expect(file.extension).toBe('.jpg')
9193
expect(file.dirname).toBe('/Photos')
92-
expect(file.root).toBeNull()
94+
expect(file.root).toBe('/')
9395
expect(file.isDavResource).toBe(false)
9496
expect(file.permissions).toBe(Permission.READ)
9597
})
@@ -98,45 +100,48 @@ describe('File creation', () => {
98100
describe('File data change', () => {
99101
test('Rename a file', () => {
100102
const file = new File({
101-
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg',
103+
source: 'https://cloud.domain.com/remote.php/dav/files/emma/picture.jpg',
104+
root: '/files/emma',
102105
mime: 'image/jpeg',
103106
owner: 'emma',
104107
})
105108

106109
expect(file.basename).toBe('picture.jpg')
107110
expect(file.dirname).toBe('/')
108-
expect(file.root).toBe('/files/emma/Photos')
111+
expect(file.root).toBe('/files/emma')
109112

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

112115
expect(file.basename).toBe('picture-old.jpg')
113116
expect(file.dirname).toBe('/')
114-
expect(file.source).toBe('https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture-old.jpg')
115-
expect(file.root).toBe('/files/emma/Photos')
117+
expect(file.source).toBe('https://cloud.domain.com/remote.php/dav/files/emma/picture-old.jpg')
118+
expect(file.root).toBe('/files/emma')
116119
})
117120

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

125129
expect(file.basename).toBe('picture.jpg')
126-
expect(file.dirname).toBe('/')
127-
expect(file.root).toBe('/files/emma/Photos')
130+
expect(file.dirname).toBe('/Photos')
131+
expect(file.root).toBe('/files/emma')
128132

129133
file.move('https://cloud.domain.com/remote.php/dav/files/emma/Pictures/picture-old.jpg')
130134

131135
expect(file.basename).toBe('picture-old.jpg')
132-
expect(file.dirname).toBe('/')
136+
expect(file.dirname).toBe('/Pictures')
133137
expect(file.source).toBe('https://cloud.domain.com/remote.php/dav/files/emma/Pictures/picture-old.jpg')
134-
expect(file.root).toBe('/files/emma/Pictures')
138+
expect(file.root).toBe('/files/emma')
135139
})
136140

137141
test('Moving a file to an invalid destination throws', () => {
138142
const file = new File({
139143
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg',
144+
root: '/files/emma',
140145
mime: 'image/jpeg',
141146
owner: 'emma',
142147
mtime: new Date(Date.UTC(2023, 0, 1, 0, 0, 0)),
@@ -184,6 +189,7 @@ describe('Altering attributes does NOT updates mtime', () => {
184189
test('mtime is updated on existing attribute', () => {
185190
const file = new File({
186191
source: 'https://cloud.domain.com/remote.php/dav/files/emma',
192+
root: '/files/emma',
187193
mime: 'image/jpeg',
188194
owner: 'emma',
189195
mtime: new Date(Date.UTC(1990, 0, 1, 0, 0, 0)),
@@ -202,6 +208,7 @@ describe('Altering attributes does NOT updates mtime', () => {
202208
test('mtime is NOT updated on new attribute', () => {
203209
const file = new File({
204210
source: 'https://cloud.domain.com/remote.php/dav/files/emma',
211+
root: '/files/emma',
205212
mime: 'image/jpeg',
206213
owner: 'emma',
207214
mtime: new Date(Date.UTC(1990, 0, 1, 0, 0, 0)),
@@ -217,6 +224,7 @@ describe('Altering attributes does NOT updates mtime', () => {
217224
test('mtime is NOT updated on deleted attribute', () => {
218225
const file = new File({
219226
source: 'https://cloud.domain.com/remote.php/dav/files/emma',
227+
root: '/files/emma',
220228
mime: 'image/jpeg',
221229
owner: 'emma',
222230
mtime: new Date(Date.UTC(1990, 0, 1, 0, 0, 0)),
@@ -235,6 +243,7 @@ describe('Altering attributes does NOT updates mtime', () => {
235243
test('mtime is NOT updated if not initially defined', () => {
236244
const file = new File({
237245
source: 'https://cloud.domain.com/remote.php/dav/files/emma',
246+
root: '/files/emma',
238247
mime: 'image/jpeg',
239248
owner: 'emma',
240249
permissions: Permission.READ,
@@ -254,6 +263,7 @@ describe('Altering top-level properties updates mtime', () => {
254263
test('mtime is updated on permissions change', () => {
255264
const file = new File({
256265
source: 'https://cloud.domain.com/remote.php/dav/files/emma',
266+
root: '/files/emma',
257267
mime: 'image/jpeg',
258268
owner: 'emma',
259269
mtime: new Date(Date.UTC(1990, 0, 1, 0, 0, 0)),
@@ -271,6 +281,7 @@ describe('Altering top-level properties updates mtime', () => {
271281
test('mtime is updated on size change', () => {
272282
const file = new File({
273283
source: 'https://cloud.domain.com/remote.php/dav/files/emma',
284+
root: '/files/emma',
274285
mime: 'image/jpeg',
275286
owner: 'emma',
276287
mtime: new Date(Date.UTC(1990, 0, 1, 0, 0, 0)),

__tests__/files/folder.spec.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ describe('Folder creation', () => {
1212
test('Valid dav folder', () => {
1313
const folder = new Folder({
1414
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/',
15+
root: '/files/emma',
1516
owner: 'emma',
1617
})
1718

@@ -61,6 +62,7 @@ describe('Folder creation', () => {
6162
test('Valid remote folder', () => {
6263
const folder = new Folder({
6364
source: 'https://domain.com/Photos/',
65+
root: '/',
6466
owner: null,
6567
})
6668

@@ -77,7 +79,7 @@ describe('Folder creation', () => {
7779
expect(folder.basename).toBe('Photos')
7880
expect(folder.extension).toBeNull()
7981
expect(folder.dirname).toBe('/')
80-
expect(folder.root).toBeNull()
82+
expect(folder.root).toBe('/')
8183
expect(folder.isDavResource).toBe(false)
8284
expect(folder.permissions).toBe(Permission.READ)
8385
})
@@ -87,6 +89,7 @@ describe('Folder data change', () => {
8789
test('Rename a folder', () => {
8890
const folder = new Folder({
8991
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos',
92+
root: '/files/emma',
9093
owner: 'emma',
9194
})
9295

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

0 commit comments

Comments
 (0)