1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
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';
11 describe('collection-service', () => {
12 let collectionService: CollectionService;
14 let webdavClient: any;
19 serverApi = {} as AxiosInstance;
23 authService = {} as AuthService;
24 actions = {} as ApiActions;
25 collectionService = new CollectionService(serverApi, webdavClient, authService, actions);
26 collectionService.update = jest.fn();
29 describe('deleteFiles', () => {
30 it('should remove no files', async () => {
32 const filePaths: string[] = [];
33 const collectionUUID = '';
36 await collectionService.deleteFiles(collectionUUID, filePaths);
39 expect(webdavClient.delete).not.toHaveBeenCalled();
42 it('should remove only root files', async () => {
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 = '';
48 await collectionService.deleteFiles(collectionUUID, filePaths);
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");
57 it('should remove files with uuid prefix', async () => {
59 const filePaths: string[] = ['/root/1'];
60 const collectionUUID = 'zzzzz-tpzed-5o5tg0l9a57gxxx';
63 await collectionService.deleteFiles(collectionUUID, filePaths);
66 expect(webdavClient.delete).toHaveBeenCalledTimes(1);
67 expect(webdavClient.delete).toHaveBeenCalledWith("c=zzzzz-tpzed-5o5tg0l9a57gxxx/root/1");