diff --git a/x-pack/plugins/cases/common/constants/files.ts b/x-pack/plugins/cases/common/constants/files.ts index 7f3f355aff1a9..2043d3f79a41e 100644 --- a/x-pack/plugins/cases/common/constants/files.ts +++ b/x-pack/plugins/cases/common/constants/files.ts @@ -10,4 +10,4 @@ export const FILE_ATTACHMENT_TYPE = '.files'; export const MAX_FILE_SIZE = 100 * 1024 * 1024; // 100 MiB export const MAX_IMAGE_FILE_SIZE = 10 * 1024 * 1024; // 10 MiB export const MAX_FILES_PER_CASE = 100; -export const MAX_DELETE_FILES = 50; +export const MAX_DELETE_FILES = 10; diff --git a/x-pack/plugins/cases/server/client/attachments/bulk_delete.test.ts b/x-pack/plugins/cases/server/client/attachments/bulk_delete.test.ts index 49a12c904eb63..a5188b6a7b803 100644 --- a/x-pack/plugins/cases/server/client/attachments/bulk_delete.test.ts +++ b/x-pack/plugins/cases/server/client/attachments/bulk_delete.test.ts @@ -9,9 +9,32 @@ import { loggerMock } from '@kbn/logging-mocks'; import pReflect from 'p-reflect'; import type { File } from '@kbn/files-plugin/common'; import { FileNotFoundError } from '@kbn/files-plugin/server/file_service/errors'; -import { retrieveFilesIgnoringNotFound } from './bulk_delete'; +import { bulkDeleteFileAttachments, retrieveFilesIgnoringNotFound } from './bulk_delete'; +import { MAX_DELETE_FILES } from '../../../common/constants'; +import { createCasesClientMock, createCasesClientMockArgs } from '../mocks'; describe('bulk_delete', () => { + describe('bulkDeleteFileAttachments', () => { + describe('errors', () => { + const casesClient = createCasesClientMock(); + const clientArgs = createCasesClientMockArgs(); + + beforeEach(() => { + jest.clearAllMocks(); + }); + + it(`throws 400 when trying to delete more than ${MAX_DELETE_FILES} files at a time`, async () => { + const fileIds = new Array(MAX_DELETE_FILES + 1).fill('fake-ids'); + + await expect( + bulkDeleteFileAttachments({ caseId: 'mock-id-4', fileIds }, clientArgs, casesClient) + ).rejects.toThrowError( + 'Failed to delete file attachments for case: mock-id-4: Error: array must be of length <= 10' + ); + }); + }); + }); + describe('retrieveFilesIgnoringNotFound', () => { const mockLogger = loggerMock.create();