-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f191876
commit 0860b34
Showing
8 changed files
with
306 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
x-pack/plugins/observability_solution/apm/server/routes/alerts/alerting_es_client.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { APMEventESSearchRequestParams, alertingEsClient } from './alerting_es_client'; | ||
import { RuleExecutorServices } from '@kbn/alerting-plugin/server'; | ||
import { ElasticsearchClient, IUiSettingsClient } from '@kbn/core/server'; | ||
import { ESSearchResponse } from '@kbn/es-types'; | ||
|
||
describe('alertingEsClient', () => { | ||
let scopedClusterClientMock: jest.Mocked<{ | ||
asCurrentUser: jest.Mocked<ElasticsearchClient>; | ||
}>; | ||
|
||
let uiSettingsClientMock: jest.Mocked<IUiSettingsClient>; | ||
|
||
beforeEach(() => { | ||
scopedClusterClientMock = { | ||
asCurrentUser: { | ||
search: jest.fn(), | ||
} as unknown as jest.Mocked<ElasticsearchClient>, | ||
}; | ||
|
||
uiSettingsClientMock = { | ||
get: jest.fn(), | ||
} as unknown as jest.Mocked<IUiSettingsClient>; | ||
}); | ||
|
||
afterEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
it('should call search with filters containing excluded data tiers', async () => { | ||
const excludedDataTiers = ['data_warm', 'data_cold']; | ||
uiSettingsClientMock.get.mockResolvedValue(excludedDataTiers); | ||
|
||
const params = { | ||
body: { | ||
size: 10, | ||
track_total_hits: true, | ||
query: { | ||
match: { field: 'value' }, | ||
}, | ||
}, | ||
}; | ||
|
||
scopedClusterClientMock.asCurrentUser.search.mockResolvedValue({ | ||
hits: { | ||
total: { value: 1, relation: 'eq' }, | ||
hits: [{ _source: {}, _index: '' }], | ||
max_score: 1, | ||
}, | ||
took: 1, | ||
_shards: { total: 1, successful: 1, skipped: 0, failed: 0 }, | ||
timed_out: false, | ||
} as unknown as ESSearchResponse<unknown, typeof params>); | ||
|
||
await alertingEsClient({ | ||
scopedClusterClient: scopedClusterClientMock as unknown as RuleExecutorServices< | ||
never, | ||
never, | ||
never | ||
>['scopedClusterClient'], | ||
uiSettingsClient: uiSettingsClientMock, | ||
params, | ||
}); | ||
|
||
const searchParams = scopedClusterClientMock.asCurrentUser.search.mock | ||
.calls[0][0] as APMEventESSearchRequestParams; | ||
expect(searchParams?.body?.query?.bool).toEqual({ | ||
filter: { bool: { must_not: [{ terms: { _tier: ['data_warm', 'data_cold'] } }] } }, | ||
must: [{ match: { field: 'value' } }], | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.