-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement upload on public shares using dav endpoint v2
Signed-off-by: Ferdinand Thiessen <[email protected]>
- Loading branch information
Showing
3 changed files
with
74 additions
and
4 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,49 @@ | ||
import { beforeEach, describe, expect, test, vi } from 'vitest' | ||
import { Uploader } from '../../lib/uploader.js' | ||
|
||
import type { NextcloudUser } from '@nextcloud/auth' | ||
|
||
const initialState = vi.hoisted(() => ({ loadState: vi.fn() })) | ||
const auth = vi.hoisted(() => ({ getCurrentUser: vi.fn<never, NextcloudUser | null>(() => null) })) | ||
vi.mock('@nextcloud/initial-state', () => initialState) | ||
vi.mock('@nextcloud/auth', () => auth) | ||
|
||
describe('uploader', () => { | ||
beforeEach(() => { | ||
vi.resetAllMocks() | ||
const node = document.getElementById('sharingToken') | ||
if (node) { | ||
document.body.removeChild(node) | ||
} | ||
}) | ||
|
||
test('constructor sets default target folder for user', async () => { | ||
auth.getCurrentUser.mockImplementationOnce(() => ({ uid: 'my-user', displayName: 'User', isAdmin: false })) | ||
const uploader = new Uploader() | ||
expect(uploader.destination.source).match(/\/remote\.php\/dav\/files\/my-user\/?$/) | ||
}) | ||
|
||
test('constructor sets default target folder for public share', async () => { | ||
initialState.loadState.mockImplementationOnce((app, key) => app === 'files_sharing' && key === 'sharingToken' ? 'token-123' : null) | ||
const uploader = new Uploader(true) | ||
expect(uploader.destination.source).match(/\/public\.php\/dav\/files\/token-123\/?$/) | ||
}) | ||
|
||
test('constructor sets default target folder for legacy public share', async () => { | ||
const input = document.createElement('input') | ||
input.id = 'sharingToken' | ||
input.value = 'legacy-token' | ||
document.body.appendChild(input) | ||
const uploader = new Uploader(true) | ||
expect(uploader.destination.source).match(/\/public\.php\/dav\/files\/legacy-token\/?$/) | ||
}) | ||
|
||
test('fails if no sharingToken on public share', async () => { | ||
expect(() => new Uploader(true)).toThrow(/No sharing token found/) | ||
}) | ||
|
||
test('fails if not logged in and not on public share', async () => { | ||
expect(() => new Uploader()).toThrow(/User is not logged in/) | ||
expect(initialState.loadState).not.toBeCalled() | ||
}) | ||
}) |
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