summaryrefslogtreecommitdiffstats
path: root/tests/javascript/unit/services/folder.service.spec.ts
blob: 19b601ee45b895e981c2a8692a19a19b22e006e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { FolderService } from './../../../../src/dataservices/folder.service'
import axios from '@nextcloud/axios'

jest.mock('@nextcloud/axios')

describe('folder.service.ts', () => {
	'use strict'

	beforeEach(() => {
		(axios.get as any).mockReset();
		(axios.post as any).mockReset();
		(axios.delete as any).mockReset()
	})

	describe('fetchAllFolders', () => {
		it('should call GET to retrieve all folders', async () => {
			(axios as any).get.mockResolvedValue({ data: { feeds: [] } })

			await FolderService.fetchAllFolders()

			expect(axios.get).toBeCalled()
		})
	})

	describe('createFolder', () => {
		it('should call POST with folderName param', async () => {
			await FolderService.createFolder({ name: 'abc' })

			expect(axios.post).toBeCalled()
			const args = (axios.post as any).mock.calls[0]

			expect(args[1].folderName).toEqual('abc')
		})
	})

	describe('renameFolder', () => {
		it('should call POST with item id in URL and folderName param', async () => {
			await FolderService.renameFolder({ id: 123, name: 'abc' })

			expect(axios.post).toBeCalled()
			const args = (axios.post as any).mock.calls[0]

			expect(args[0]).toContain('123/rename')
			expect(args[1].folderName).toEqual('abc')
		})
	})

	describe('deleteFolder', () => {
		it('should call POST with item id in URL and read param', async () => {
			await FolderService.deleteFolder({ id: 123 })

			expect(axios.delete).toBeCalled()
			const args = (axios.delete as any).mock.calls[0]

			expect(args[0]).toContain('123')
		})
	})
})