test: delete of folder does not delete unintended folders

This commit is contained in:
Marc-Roig 2023-05-17 17:32:00 +02:00
parent 008d82f8f7
commit 15e71b69b0
No known key found for this signature in database
GPG Key ID: FB4E2C43A0BEE249

View File

@ -220,6 +220,33 @@ describe('Bulk actions for folders & files', () => {
const existingfoldersIds = resFolder.body.data.map((f) => f.id);
expect(existingfoldersIds).toEqual(expect.not.arrayContaining([folder.id]));
});
test('Can delete folders without deleting others with similar name', async () => {
// Ensure the folder algo does not only delete by folders that start with the same path (startswith /1 matches /10 too)
// Delete all previous folders, so first file path is /1
await rq
.get('/upload/folders')
.then((res) => res.body.data.map((f) => f.id))
.then((folderIds) => rq.post('/upload/actions/bulk-delete', { body: { folderIds } }));
// Create folders
const folder1 = await createFolder('folderToDelete', null);
data.folders = await Promise.all(
Array.from({ length: 20 }).map((_, i) => createFolder(`${i}`, null))
);
// Delete folder1
await rq.post('/upload/actions/bulk-delete', { body: { folderIds: [folder1.id] } });
const afterFolderIds = await rq
.get('/upload/folders')
.then((res) => res.body.data.map((f) => f.id));
// Should include all folders except the one we deleted
expect(afterFolderIds.length).toBe(20);
expect(afterFolderIds).toEqual(expect.not.arrayContaining([folder1.id]));
});
});
describe('move', () => {