[Alerting] Add shared getRulesClientMockParams test helper#280910
Draft
cnasikas wants to merge 2 commits into
Draft
[Alerting] Add shared getRulesClientMockParams test helper#280910cnasikas wants to merge 2 commits into
cnasikas wants to merge 2 commits into
Conversation
Introduce a `getRulesClientMockParams` helper in the alerting server `test_utils` module that centralises construction of the `RulesClient` `ConstructorOptions` used across unit tests. Adding a new rule client param now only requires updating this single helper instead of every unit test file. Migrate the first rules_client/tests suites (mute_all, unmute_all, unsnooze_instance) to use it. Verification (scoped to changed files): - node scripts/eslint: 0 errors - node scripts/type_check --project .../alerting/tsconfig.json: 0 errors - node scripts/jest (migrated suites): all pass Co-authored-by: Cursor <cursoragent@cursor.com>
Replace the duplicated `jest.Mocked<ConstructorOptions>` rulesClientParams literals across 42 alerting server unit test files with the shared `getRulesClientMockParams` helper. Per-test differences are expressed via the helper's `overrides` argument, so adding a new RulesClient constructor param now only requires updating the helper instead of every test file. No test logic, assertions, or snapshots were changed. Verification: - node scripts/type_check --project x-pack/platform/plugins/shared/alerting/tsconfig.json -> exit 0 - node scripts/eslint <changed files> -> 0 errors - node scripts/jest <changed test files> -> 45 suites, 734 tests, 232 snapshots passing Co-authored-by: Cursor <cursoragent@cursor.com>
|
🤖 Jobs for this PR can be triggered through checkboxes. 🚧
ℹ️ To trigger the CI, please tick the checkbox below 👇
|
Contributor
💛 Build succeeded, but was flaky
Failed CI StepsTest Failures
Metrics [docs]
|
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Every alerting server unit test that instantiates a
RulesClientused to declare its ownconst rulesClientParams: jest.Mocked<ConstructorOptions>literal along with the full set ofmock constructor mocks. As a result, whenever a new
RulesClientconstructor param is added,every one of these test files has to be touched, producing large, noisy PRs.
This PR introduces a single shared helper,
getRulesClientMockParams, and migrates the existingunit tests to use it.
x-pack/platform/plugins/shared/alerting/server/test_utils/rules_client_mock.tsexportinggetRulesClientMockParams(overrides?), re-exported from the top-levelserver/test_utils.rulesClientParamsplus the individual strongly-typed mocks(
taskManager,ruleTypeRegistry,unsecuredSavedObjectsClient,authorization,auditLogger, …)so tests can still drive mock behaviour.
overridesargument(e.g.
getRulesClientMockParams({ kibanaVersion: 'v8.0.0', isServerless: true })).rules_client,application/rule/methods,rule_template,gaps, andbackfillto the helper, removing the duplicated param literals and now-unused mock imports.Net effect: +280 / −2296 lines. Adding a new
RulesClientconstructor param now only requiresupdating the single helper instead of every test file.
No test logic, assertions, snapshots, or descriptions were changed — this is a behaviour-preserving refactor.
Verification
node scripts/type_check --project x-pack/platform/plugins/shared/alerting/tsconfig.json→ exit 0node scripts/eslint <changed files>→ 0 errorsnode scripts/jest <changed test files>→ 45 suites, 734 tests, 232 snapshots — all passingChecklist
Identify risks
mitigated by type-check + full Jest sweep of all changed suites passing.