aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/src/services/SharingService.spec.ts
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_sharing/src/services/SharingService.spec.ts')
-rw-r--r--apps/files_sharing/src/services/SharingService.spec.ts87
1 files changed, 44 insertions, 43 deletions
diff --git a/apps/files_sharing/src/services/SharingService.spec.ts b/apps/files_sharing/src/services/SharingService.spec.ts
index ba0591a765a..bd0e018db7a 100644
--- a/apps/files_sharing/src/services/SharingService.spec.ts
+++ b/apps/files_sharing/src/services/SharingService.spec.ts
@@ -3,29 +3,35 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import type { OCSResponse } from '@nextcloud/typings/ocs'
-import { expect } from '@jest/globals'
-import { Type } from '@nextcloud/sharing'
-import * as auth from '@nextcloud/auth'
-import axios from '@nextcloud/axios'
-import { getContents } from './SharingService'
import { File, Folder } from '@nextcloud/files'
+import { ShareType } from '@nextcloud/sharing'
+import { beforeAll, beforeEach, describe, expect, test, vi } from 'vitest'
+
+import { getContents } from './SharingService'
+import * as auth from '@nextcloud/auth'
import logger from './logger'
-window.OC = {
- ...window.OC,
- TAG_FAVORITE: '_$!<Favorite>!$_',
-}
+const TAG_FAVORITE = '_$!<Favorite>!$_'
+
+const axios = vi.hoisted(() => ({ get: vi.fn() }))
+vi.mock('@nextcloud/auth')
+vi.mock('@nextcloud/axios', () => ({ default: axios }))
-// Mock webroot variable
+// Mock web root variable
beforeAll(() => {
+ window.OC = {
+ ...window.OC,
+ TAG_FAVORITE,
+ }
// eslint-disable-next-line @typescript-eslint/no-explicit-any
- (window as any)._oc_webroot = ''
+ ;(window as any)._oc_webroot = ''
})
describe('SharingService methods definitions', () => {
- beforeAll(() => {
- jest.spyOn(axios, 'get').mockImplementation(async (): Promise<any> => {
+ beforeEach(() => {
+ vi.resetAllMocks()
+ axios.get.mockImplementation(async (): Promise<unknown> => {
return {
data: {
ocs: {
@@ -36,20 +42,16 @@ describe('SharingService methods definitions', () => {
},
data: [],
},
- } as OCSResponse<any>,
+ } as OCSResponse,
}
})
})
- afterAll(() => {
- jest.restoreAllMocks()
- })
-
test('Shared with you', async () => {
await getContents(true, false, false, false, [])
expect(axios.get).toHaveBeenCalledTimes(2)
- expect(axios.get).toHaveBeenNthCalledWith(1, 'http://localhost/ocs/v2.php/apps/files_sharing/api/v1/shares', {
+ expect(axios.get).toHaveBeenNthCalledWith(1, 'http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/shares', {
headers: {
'Content-Type': 'application/json',
},
@@ -58,7 +60,7 @@ describe('SharingService methods definitions', () => {
include_tags: true,
},
})
- expect(axios.get).toHaveBeenNthCalledWith(2, 'http://localhost/ocs/v2.php/apps/files_sharing/api/v1/remote_shares', {
+ expect(axios.get).toHaveBeenNthCalledWith(2, 'http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/remote_shares', {
headers: {
'Content-Type': 'application/json',
},
@@ -72,7 +74,7 @@ describe('SharingService methods definitions', () => {
await getContents(false, true, false, false, [])
expect(axios.get).toHaveBeenCalledTimes(1)
- expect(axios.get).toHaveBeenCalledWith('http://localhost/ocs/v2.php/apps/files_sharing/api/v1/shares', {
+ expect(axios.get).toHaveBeenCalledWith('http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/shares', {
headers: {
'Content-Type': 'application/json',
},
@@ -87,7 +89,7 @@ describe('SharingService methods definitions', () => {
await getContents(false, false, true, false, [])
expect(axios.get).toHaveBeenCalledTimes(2)
- expect(axios.get).toHaveBeenNthCalledWith(1, 'http://localhost/ocs/v2.php/apps/files_sharing/api/v1/shares/pending', {
+ expect(axios.get).toHaveBeenNthCalledWith(1, 'http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/shares/pending', {
headers: {
'Content-Type': 'application/json',
},
@@ -95,7 +97,7 @@ describe('SharingService methods definitions', () => {
include_tags: true,
},
})
- expect(axios.get).toHaveBeenNthCalledWith(2, 'http://localhost/ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending', {
+ expect(axios.get).toHaveBeenNthCalledWith(2, 'http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending', {
headers: {
'Content-Type': 'application/json',
},
@@ -109,7 +111,7 @@ describe('SharingService methods definitions', () => {
await getContents(false, true, false, false, [])
expect(axios.get).toHaveBeenCalledTimes(1)
- expect(axios.get).toHaveBeenCalledWith('http://localhost/ocs/v2.php/apps/files_sharing/api/v1/shares', {
+ expect(axios.get).toHaveBeenCalledWith('http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/shares', {
headers: {
'Content-Type': 'application/json',
},
@@ -121,7 +123,7 @@ describe('SharingService methods definitions', () => {
})
test('Unknown owner', async () => {
- jest.spyOn(auth, 'getCurrentUser').mockReturnValue(null)
+ vi.spyOn(auth, 'getCurrentUser').mockReturnValue(null)
const results = await getContents(false, true, false, false, [])
expect(results.folder.owner).toEqual(null)
@@ -129,8 +131,9 @@ describe('SharingService methods definitions', () => {
})
describe('SharingService filtering', () => {
- beforeAll(() => {
- jest.spyOn(axios, 'get').mockImplementation(async (): Promise<any> => {
+ beforeEach(() => {
+ vi.resetAllMocks()
+ axios.get.mockImplementation(async (): Promise<unknown> => {
return {
data: {
ocs: {
@@ -142,7 +145,7 @@ describe('SharingService filtering', () => {
data: [
{
id: '62',
- share_type: Type.SHARE_TYPE_USER,
+ share_type: ShareType.User,
uid_owner: 'test',
displayname_owner: 'test',
permissions: 31,
@@ -168,12 +171,8 @@ describe('SharingService filtering', () => {
})
})
- afterAll(() => {
- jest.restoreAllMocks()
- })
-
test('Shared with others filtering', async () => {
- const shares = await getContents(false, true, false, false, [Type.SHARE_TYPE_USER])
+ const shares = await getContents(false, true, false, false, [ShareType.User])
expect(axios.get).toHaveBeenCalledTimes(1)
expect(shares.contents).toHaveLength(1)
@@ -182,7 +181,7 @@ describe('SharingService filtering', () => {
})
test('Shared with others filtering empty', async () => {
- const shares = await getContents(false, true, false, false, [Type.SHARE_TYPE_LINK])
+ const shares = await getContents(false, true, false, false, [ShareType.Link])
expect(axios.get).toHaveBeenCalledTimes(1)
expect(shares.contents).toHaveLength(0)
@@ -275,11 +274,13 @@ describe('SharingService share to Node mapping', () => {
mail_send: 0,
hide_download: 0,
attributes: null,
- tags: [window.OC.TAG_FAVORITE],
+ tags: [TAG_FAVORITE],
}
+ beforeEach(() => { vi.resetAllMocks() })
+
test('File', async () => {
- jest.spyOn(axios, 'get').mockReturnValueOnce(Promise.resolve({
+ axios.get.mockReturnValueOnce(Promise.resolve({
data: {
ocs: {
data: [shareFile],
@@ -295,7 +296,7 @@ describe('SharingService share to Node mapping', () => {
const file = shares.contents[0] as File
expect(file).toBeInstanceOf(File)
expect(file.fileid).toBe(530936)
- expect(file.source).toBe('http://localhost/remote.php/dav/files/test/document.md')
+ expect(file.source).toBe('http://nextcloud.local/remote.php/dav/files/test/document.md')
expect(file.owner).toBe('test')
expect(file.mime).toBe('text/markdown')
expect(file.mtime).toBeInstanceOf(Date)
@@ -308,7 +309,7 @@ describe('SharingService share to Node mapping', () => {
})
test('Folder', async () => {
- jest.spyOn(axios, 'get').mockReturnValueOnce(Promise.resolve({
+ axios.get.mockReturnValueOnce(Promise.resolve({
data: {
ocs: {
data: [shareFolder],
@@ -324,7 +325,7 @@ describe('SharingService share to Node mapping', () => {
const folder = shares.contents[0] as Folder
expect(folder).toBeInstanceOf(Folder)
expect(folder.fileid).toBe(531080)
- expect(folder.source).toBe('http://localhost/remote.php/dav/files/test/Folder')
+ expect(folder.source).toBe('http://nextcloud.local/remote.php/dav/files/test/Folder')
expect(folder.owner).toBe('test')
expect(folder.mime).toBe('httpd/unix-directory')
expect(folder.mtime).toBeInstanceOf(Date)
@@ -338,8 +339,8 @@ describe('SharingService share to Node mapping', () => {
})
test('Empty', async () => {
- jest.spyOn(logger, 'error').mockImplementationOnce(() => {})
- jest.spyOn(axios, 'get').mockReturnValueOnce(Promise.resolve({
+ vi.spyOn(logger, 'error').mockImplementationOnce(() => {})
+ axios.get.mockReturnValueOnce(Promise.resolve({
data: {
ocs: {
data: [],
@@ -353,8 +354,8 @@ describe('SharingService share to Node mapping', () => {
})
test('Error', async () => {
- jest.spyOn(logger, 'error').mockImplementationOnce(() => {})
- jest.spyOn(axios, 'get').mockReturnValueOnce(Promise.resolve({
+ vi.spyOn(logger, 'error').mockImplementationOnce(() => {})
+ axios.get.mockReturnValueOnce(Promise.resolve({
data: {
ocs: {
data: [null],