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);
28 describe('deleteFiles', () => {
29 it('should remove no files', async () => {
31 const filePaths: string[] = [];
32 const collectionUUID = '';
35 await collectionService.deleteFiles(collectionUUID, filePaths);
38 expect(webdavClient.delete).not.toHaveBeenCalled();
41 it('should remove only root files', async () => {
43 const filePaths: string[] = ['/root/1', '/root/1/100', '/root/1/100/test.txt', '/root/2', '/root/2/200', '/root/3/300/test.txt'];
44 const collectionUUID = '';
47 await collectionService.deleteFiles(collectionUUID, filePaths);
50 expect(webdavClient.delete).toHaveBeenCalledTimes(3);
51 expect(webdavClient.delete).toHaveBeenCalledWith("c=/root/3/300/test.txt");
52 expect(webdavClient.delete).toHaveBeenCalledWith("c=/root/2");
53 expect(webdavClient.delete).toHaveBeenCalledWith("c=/root/1");
56 it('should remove files with uuid prefix', async () => {
58 const filePaths: string[] = ['/root/1'];
59 const collectionUUID = 'zzzzz-tpzed-5o5tg0l9a57gxxx';
62 await collectionService.deleteFiles(collectionUUID, filePaths);
65 expect(webdavClient.delete).toHaveBeenCalledTimes(1);
66 expect(webdavClient.delete).toHaveBeenCalledWith("c=zzzzz-tpzed-5o5tg0l9a57gxxx/root/1");