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
feat!: add NodeData.encodedSource
Signed-off-by: Daniel Kesselberg <[email protected]>
  • Loading branch information
kesselb committed Oct 2, 2023
commit b6c9b920731bb0622baecdbce6e5d44b9bf804f2
14 changes: 14 additions & 0 deletions __tests__/dav/dav.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ describe('davResultToNode', () => {
expect(node.basename).toBe(result.basename)
expect(node.extension).toBe('.md')
expect(node.source).toBe('https://localhost/dav/files/test/New folder/Neue Textdatei.md')
expect(node.encodedSource).toBe('https://localhost/dav/files/test/New%20folder/Neue%20Textdatei.md')
expect(node.root).toBe(davRootPath)
expect(node.path).toBe('/New folder/Neue Textdatei.md')
expect(node.dirname).toBe('/New folder')
Expand All @@ -65,6 +66,7 @@ describe('davResultToNode', () => {
expect(node.extension).toBe('.md')
expect(node.root).toBe('/root')
expect(node.source).toBe('https://localhost/dav/root/New folder/Neue Textdatei.md')
expect(node.encodedSource).toBe('https://localhost/dav/root/New%20folder/Neue%20Textdatei.md')
expect(node.path).toBe('/New folder/Neue Textdatei.md')
expect(node.dirname).toBe('/New folder')
})
Expand All @@ -75,9 +77,21 @@ describe('davResultToNode', () => {
expect(node.basename).toBe(remoteResult.basename)
expect(node.extension).toBe('.md')
expect(node.source).toBe('http://example.com/dav/root/New folder/Neue Textdatei.md')
expect(node.encodedSource).toBe('http://example.com/dav/root/New%20folder/Neue%20Textdatei.md')
expect(node.path).toBe('/New folder/Neue Textdatei.md')
expect(node.dirname).toBe('/New folder')
})

test('encode special characters', () => {
const remoteResult = { ...result, basename: 'realy #1\'s.md', filename: '/root/~⛰️ shot of a $[big} mountain/realy #1\'s.md' }
const node = davResultToNode(remoteResult, '/root', 'http://example.com/dav')
expect(node.basename).toBe(remoteResult.basename)
expect(node.extension).toBe('.md')
expect(node.source).toBe('http://example.com/dav/root/~⛰️ shot of a $[big} mountain/realy #1\'s.md')
expect(node.encodedSource).toBe('http://example.com/dav/root/~%E2%9B%B0%EF%B8%8F%20shot%20of%20a%20%24%5Bbig%7D%20mountain/realy%20%231\'s.md')
expect(node.path).toBe('/~⛰️ shot of a $[big} mountain/realy #1\'s.md')
expect(node.dirname).toBe('/~⛰️ shot of a $[big} mountain')
})
})

describe('DAV requests', () => {
Expand Down
12 changes: 12 additions & 0 deletions __tests__/files/file.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,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',
encodedSource: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg',
mime: 'image/jpeg',
owner: 'emma',
mtime: new Date(Date.UTC(2023, 0, 1, 0, 0, 0)),
Expand Down Expand Up @@ -43,6 +44,7 @@ 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',
encodedSource: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg',
mime: 'image/jpeg',
owner: 'emma',
root: '/files/emma',
Expand Down Expand Up @@ -70,6 +72,7 @@ describe('File creation', () => {
test('Valid remote file', () => {
const file = new File({
source: 'https://domain.com/Photos/picture.jpg',
encodedSource: 'https://domain.com/Photos/picture.jpg',
mime: 'image/jpeg',
owner: null,
})
Expand Down Expand Up @@ -97,6 +100,7 @@ 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',
encodedSource: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg',
mime: 'image/jpeg',
owner: 'emma',
mtime: new Date(Date.UTC(2023, 0, 1, 0, 0, 0)),
Expand All @@ -121,6 +125,7 @@ describe('File data change', () => {
test('Moving a file', () => {
const file = new File({
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg',
encodedSource: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg',
mime: 'image/jpeg',
owner: 'emma',
mtime: new Date(Date.UTC(2023, 0, 1, 0, 0, 0)),
Expand All @@ -145,6 +150,7 @@ describe('File data change', () => {
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',
encodedSource: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg',
mime: 'image/jpeg',
owner: 'emma',
mtime: new Date(Date.UTC(2023, 0, 1, 0, 0, 0)),
Expand All @@ -157,6 +163,7 @@ describe('File data change', () => {
test('Moving a file to a different folder with root', () => {
const file = new File({
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg',
encodedSource: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg',
mime: 'image/jpeg',
owner: 'emma',
root: '/files/emma',
Expand All @@ -177,6 +184,7 @@ describe('File data change', () => {
test('Changing status', () => {
const file = new File({
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg',
encodedSource: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg',
mime: 'image/jpeg',
owner: 'emma',
root: '/files/emma',
Expand All @@ -192,6 +200,7 @@ describe('Altering attributes updates mtime', () => {
test('mtime is updated on existing attribute', () => {
const file = new File({
source: 'https://cloud.domain.com/remote.php/dav/files/emma',
encodedSource: 'https://cloud.domain.com/remote.php/dav/files/emma',
mime: 'image/jpeg',
owner: 'emma',
mtime: new Date(Date.UTC(1990, 0, 1, 0, 0, 0)),
Expand All @@ -210,6 +219,7 @@ describe('Altering attributes updates mtime', () => {
test('mtime is updated on new attribute', () => {
const file = new File({
source: 'https://cloud.domain.com/remote.php/dav/files/emma',
encodedSource: 'https://cloud.domain.com/remote.php/dav/files/emma',
mime: 'image/jpeg',
owner: 'emma',
mtime: new Date(Date.UTC(1990, 0, 1, 0, 0, 0)),
Expand All @@ -225,6 +235,7 @@ describe('Altering attributes updates mtime', () => {
test('mtime is updated on deleted attribute', () => {
const file = new File({
source: 'https://cloud.domain.com/remote.php/dav/files/emma',
encodedSource: 'https://cloud.domain.com/remote.php/dav/files/emma',
mime: 'image/jpeg',
owner: 'emma',
mtime: new Date(Date.UTC(1990, 0, 1, 0, 0, 0)),
Expand All @@ -243,6 +254,7 @@ describe('Altering attributes 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',
encodedSource: 'https://cloud.domain.com/remote.php/dav/files/emma',
mime: 'image/jpeg',
owner: 'emma',
attributes: {
Expand Down
6 changes: 6 additions & 0 deletions __tests__/files/folder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ describe('Folder creation', () => {
test('Valid dav folder', () => {
const folder = new Folder({
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/',
encodedSource: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/',
owner: 'emma',
})

Expand All @@ -32,6 +33,7 @@ describe('Folder creation', () => {
test('Valid dav folder with root', () => {
const folder = new Folder({
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/Berlin',
encodedSource: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/Berlin',
owner: 'emma',
root: '/files/emma',
})
Expand All @@ -57,6 +59,7 @@ describe('Folder creation', () => {
test('Valid remote folder', () => {
const folder = new Folder({
source: 'https://domain.com/Photos/',
encodedSource: 'https://domain.com/Photos/',
owner: null,
})

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

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

Expand All @@ -119,6 +124,7 @@ describe('Folder data change', () => {
test('Moving a folder to a different location with root', () => {
const folder = new Folder({
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/',
encodedSource: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/',
owner: 'emma',
root: '/files/emma',
})
Expand Down
Loading