Skip to content

[Alerting] Add shared getRulesClientMockParams test helper#280910

Draft
cnasikas wants to merge 2 commits into
elastic:mainfrom
cnasikas:alerting_mock_rule_client_params
Draft

[Alerting] Add shared getRulesClientMockParams test helper#280910
cnasikas wants to merge 2 commits into
elastic:mainfrom
cnasikas:alerting_mock_rule_client_params

Conversation

@cnasikas

Copy link
Copy Markdown
Member

Summary

Every alerting server unit test that instantiates a RulesClient used to declare its own
const rulesClientParams: jest.Mocked<ConstructorOptions> literal along with the full set of
mock constructor mocks. As a result, whenever a new RulesClient constructor 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 existing
unit tests to use it.

  • Adds x-pack/platform/plugins/shared/alerting/server/test_utils/rules_client_mock.ts exporting
    getRulesClientMockParams(overrides?), re-exported from the top-level server/test_utils.
    • Returns the assembled rulesClientParams plus the individual strongly-typed mocks
      (taskManager, ruleTypeRegistry, unsecuredSavedObjectsClient, authorization, auditLogger, …)
      so tests can still drive mock behaviour.
    • Per-test differences are expressed via the overrides argument
      (e.g. getRulesClientMockParams({ kibanaVersion: 'v8.0.0', isServerless: true })).
  • Migrates 45 unit test files across rules_client, application/rule/methods, rule_template,
    gaps, and backfill to the helper, removing the duplicated param literals and now-unused mock imports.

Net effect: +280 / −2296 lines. Adding a new RulesClient constructor param now only requires
updating 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 0
  • node scripts/eslint <changed files> → 0 errors
  • node scripts/jest <changed test files>45 suites, 734 tests, 232 snapshots — all passing

Checklist

Identify risks

  • Test-only refactor; no production code paths are affected. Risk is limited to test setup regressions,
    mitigated by type-check + full Jest sweep of all changed suites passing.

cnasikas and others added 2 commits July 25, 2026 14:33
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>
@infra-vault-gh-plugin-prod

infra-vault-gh-plugin-prod Bot commented Jul 25, 2026

Copy link
Copy Markdown
🤖 Jobs for this PR can be triggered through checkboxes. 🚧

ℹ️ To trigger the CI, please tick the checkbox below 👇

  • Click to trigger kibana-pull-request for this PR!
  • Click to trigger kibana-deploy-project-from-pr for this PR!
  • Click to trigger kibana-deploy-cloud-from-pr for this PR!
  • Click to trigger kibana-entity-store-performance-from-pr for this PR!
  • Click to trigger kibana-storybooks-from-pr for this PR!

@kibanamachine

Copy link
Copy Markdown
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] Scout Lane #1 - stateful-classic / default / local-stateful-classic - Discover ES|QL columns - initial columns - renders initial columns for non-transformational commands
  • [job] [logs] Scout Lane #15 - stateful-classic / default / local-stateful-classic - Memory CRUD API - smoke: create, read, search, categories, soft-delete, and restore by name

Metrics [docs]

✅ unchanged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants