Skip to content

Commit

Permalink
Filter docs without _source
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Jun 8, 2022
1 parent 857448d commit 74aab5b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
34 changes: 34 additions & 0 deletions x-pack/plugins/cases/server/client/alerts/get.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,38 @@ describe('getAlerts', () => {
},
]);
});

it('filters docs without _source correctly', async () => {
esClient.mget.mockResolvedValue({
docs: [
...docs,
{
_index: '.internal.alerts-security.alerts-default-000002',
_id: 'd3869d546717e8c581add9cbf7d24578f34cd3e72cbc8d8b8e9a9330a899f70f',
found: true,
},
],
});
const clientArgs = { alertsService } as unknown as CasesClientArgs;

const res = await getAlerts(
[
{
index: '.internal.alerts-security.alerts-default-000001',
id: 'c3869d546717e8c581add9cbf7d24578f34cd3e72cbc8d8b8e9a9330a899f70f',
},
],
clientArgs
);

expect(res).toEqual([
{
index: '.internal.alerts-security.alerts-default-000001',
id: 'c3869d546717e8c581add9cbf7d24578f34cd3e72cbc8d8b8e9a9330a899f70f',
destination: { mac: 'ff:ff:ff:ff:ff:ff' },
source: { bytes: 444, mac: '11:1f:1e:13:15:14', packets: 6 },
ecs: { version: '8.0.0' },
},
]);
});
});
6 changes: 4 additions & 2 deletions x-pack/plugins/cases/server/client/alerts/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import { CasesClientArgs } from '..';
import { AlertInfo } from '../../common/types';
import { Alert } from '../../services/alerts';

function isAlert(doc?: MgetResponseItem<unknown>): doc is GetGetResult<Alert> {
return Boolean(doc && !('error' in doc));
function isAlert(
doc?: MgetResponseItem<unknown>
): doc is Omit<GetGetResult<Alert>, '_source'> & { _source: Alert } {
return Boolean(doc && !('error' in doc) && '_source' in doc);
}

export const getAlerts = async (
Expand Down

0 comments on commit 74aab5b

Please sign in to comment.