Skip to content

Commit

Permalink
Filter out empty alets
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Jan 16, 2023
1 parent 82c69bc commit 5f48d8d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
28 changes: 28 additions & 0 deletions x-pack/plugins/cases/server/services/alerts/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,32 @@ describe('updateAlertsStatus', () => {
expect(res).toBe(undefined);
});
});

describe('bulkUpdateCases', () => {
const alerts = [
{
id: 'c3869d546717e8c581add9cbf7d24578f34cd3e72cbc8d8b8e9a9330a899f70f',
index: '.internal.alerts-security.alerts-default-000001',
},
];
const caseIds = ['test-case'];

it('update case info', async () => {
await alertService.bulkUpdateCases({ alerts, caseIds });

expect(alertsClient.bulkUpdateCases).toBeCalledWith({ alerts, caseIds });
});

it('filters out alerts with empty id', async () => {
await alertService.bulkUpdateCases({ alerts: [{ id: '', index: 'test-index' }], caseIds });

expect(alertsClient.bulkUpdateCases).toBeCalledWith({ alerts: [], caseIds });
});

it('filters out alerts with empty index', async () => {
await alertService.bulkUpdateCases({ alerts: [{ id: 'test-id', index: '' }], caseIds });

expect(alertsClient.bulkUpdateCases).toBeCalledWith({ alerts: [], caseIds });
});
});
});
4 changes: 3 additions & 1 deletion x-pack/plugins/cases/server/services/alerts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,10 @@ export class AlertService {

public async bulkUpdateCases({ alerts, caseIds }: UpdateAlertCasesRequest): Promise<void> {
try {
const nonEmptyAlerts = alerts.filter((alert) => !AlertService.isEmptyAlert(alert));

await this.alertsClient.bulkUpdateCases({
alerts,
alerts: nonEmptyAlerts,
caseIds,
});
} catch (error) {
Expand Down

0 comments on commit 5f48d8d

Please sign in to comment.