blob: 678c0eebf2a0f840ab828ca7bb2b6339d42e6f5c (
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
|
import { ShareService } from './../../../../src/dataservices/share.service'
import axios from '@nextcloud/axios'
jest.mock('@nextcloud/axios')
describe('share.service.ts', () => {
'use strict'
beforeEach(() => {
(axios.get as any).mockReset();
(axios.post as any).mockReset()
})
describe('fetchUsers', () => {
it('should call GET to retrieve users', async () => {
(axios as any).get.mockResolvedValue({ data: { feeds: [] } })
await ShareService.fetchUsers('abc')
expect(axios.get).toBeCalled()
const args = (axios.get as any).mock.calls[0]
expect(args[0]).toContain('search=abc')
})
})
describe('share', () => {
it('should call POST for each user passed', async () => {
await ShareService.share(123, ['share-user'])
expect(axios.post).toBeCalledTimes(1)
let args = (axios.post as any).mock.calls[0]
expect(args[0]).toContain('123/share/share-user')
await ShareService.share(345, ['share-user', 'share2'])
expect(axios.post).toBeCalledTimes(3)
args = (axios.post as any).mock.calls[1]
expect(args[0]).toContain('345/share/share-user')
args = (axios.post as any).mock.calls[2]
expect(args[0]).toContain('345/share/share2')
})
})
})
|