17585: Project change should trigger loader
[arvados-workbench2.git] / src / services / collection-service / collection-service.test.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { AxiosInstance } from 'axios';
6 import { WebDAV } from 'common/webdav';
7 import { ApiActions } from '../api/api-actions';
8 import { AuthService } from '../auth-service/auth-service';
9 import { CollectionService } from './collection-service';
10
11 describe('collection-service', () => {
12     let collectionService: CollectionService;
13     let serverApi;
14     let webdavClient: any;
15     let authService;
16     let actions;
17
18     beforeEach(() => {
19         serverApi = {} as AxiosInstance;
20         webdavClient = {
21             delete: jest.fn(),
22         } as any;
23         authService = {} as AuthService;
24         actions = {} as ApiActions;
25         collectionService = new CollectionService(serverApi, webdavClient, authService, actions);
26         collectionService.update = jest.fn();
27     });
28
29     describe('deleteFiles', () => {
30         it('should remove no files', async () => {
31             // given
32             const filePaths: string[] = [];
33             const collectionUUID = '';
34
35             // when
36             await collectionService.deleteFiles(collectionUUID, filePaths);
37
38             // then
39             expect(webdavClient.delete).not.toHaveBeenCalled();
40         });
41
42         it('should remove only root files', async () => {
43             // given
44             const filePaths: string[] = ['/root/1', '/root/1/100', '/root/1/100/test.txt', '/root/2', '/root/2/200', '/root/3/300/test.txt'];
45             const collectionUUID = '';
46
47             // when
48             await collectionService.deleteFiles(collectionUUID, filePaths);
49
50             // then
51             expect(webdavClient.delete).toHaveBeenCalledTimes(3);
52             expect(webdavClient.delete).toHaveBeenCalledWith("c=/root/3/300/test.txt");
53             expect(webdavClient.delete).toHaveBeenCalledWith("c=/root/2");
54             expect(webdavClient.delete).toHaveBeenCalledWith("c=/root/1");
55         });
56
57         it('should remove files with uuid prefix', async () => {
58             // given
59             const filePaths: string[] = ['/root/1'];
60             const collectionUUID = 'zzzzz-tpzed-5o5tg0l9a57gxxx';
61
62             // when
63             await collectionService.deleteFiles(collectionUUID, filePaths);
64
65             // then
66             expect(webdavClient.delete).toHaveBeenCalledTimes(1);
67             expect(webdavClient.delete).toHaveBeenCalledWith("c=zzzzz-tpzed-5o5tg0l9a57gxxx/root/1");
68         });
69     });
70 });