|
| 1 | +/*! |
| 2 | + * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors |
| 3 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 4 | + */ |
| 5 | + |
| 6 | +import { join } from '@nextcloud/paths' |
| 7 | +import { expect, test } from 'vitest' |
| 8 | +import { defaultRemoteURL, defaultRootPath } from '../dav/dav.ts' |
| 9 | +import { scopedGlobals } from '../globalScope.ts' |
| 10 | +import { Folder } from '../node/folder.ts' |
| 11 | +import { getUploader } from './getUploader.ts' |
| 12 | +import { Uploader } from './uploader/Uploader.ts' |
| 13 | + |
| 14 | +test('getUploader - should return the uploader instance from the global scope', async () => { |
| 15 | + const uploader = new Uploader(false, new Folder({ owner: 'test', root: defaultRootPath, source: join(defaultRemoteURL, defaultRootPath) })) |
| 16 | + scopedGlobals.uploader = uploader |
| 17 | + const returnedUploader = getUploader() |
| 18 | + expect(returnedUploader).toBe(uploader) |
| 19 | +}) |
| 20 | + |
| 21 | +test('getUploader - should return the same instance on multiple calls', async () => { |
| 22 | + const uploader1 = getUploader() |
| 23 | + const uploader2 = getUploader() |
| 24 | + expect(uploader1).toBe(uploader2) |
| 25 | +}) |
| 26 | + |
| 27 | +test('getUploader - should not return the same instance on multiple calls with forceRecreate', async () => { |
| 28 | + const uploader1 = getUploader(true) |
| 29 | + const uploader2 = getUploader(true, true) |
| 30 | + expect(uploader1).not.toBe(uploader2) |
| 31 | +}) |
0 commit comments