Skip to content

[Test Improver] Add unit tests for AcceptOrRejectSocketMessage - #114

Draft
github-actions[bot] wants to merge 1 commit into
masterfrom
test-assist/accept-or-reject-socket-message-b9e2dd2b9b1b3f7f
Draft

[Test Improver] Add unit tests for AcceptOrRejectSocketMessage#114
github-actions[bot] wants to merge 1 commit into
masterfrom
test-assist/accept-or-reject-socket-message-b9e2dd2b9b1b3f7f

Conversation

@github-actions

Copy link
Copy Markdown

🤖 This PR was created by Test Improver, an automated AI assistant focused on improving test coverage.

Goal and Rationale

shell/plugins/steve/accept-or-reject-socket-message.ts had no test coverage. This class is responsible for deciding which WebSocket messages the Steve store should accept or reject — a critical correctness boundary for real-time resource updates. It has multiple branches across 6 methods:

  • typeIsNamespaced / typeIsPaginated: detect whether a resource type is namespace-scoped or paginated
  • filteredNamespaces: returns the active namespace cache from the root store
  • subscribeNamespace: decides whether to subscribe to all changes (returns undefined) or a specific namespace list
  • validChange: validates a single resource change against namespace and pagination filters
  • validateBatchChange: filters an entire batch of WebSocket changes, caching per-type lookups for efficiency

Approach

  • Constructed a makeCtx helper to produce mock { getters, rootGetters } objects, keeping test setup minimal.
  • Imported the singleton export default directly — no module-level mocking needed since the class holds no internal state.
  • Used jest.fn() for all getter functions to assert delegation and call counts.

Tests (23 total)

Group Tests
typeIsNamespaced non-empty array → true; empty array → false; undefined → false; calls with correct type
typeIsPaginated truthy object → true; null → false; undefined → false; calls with correct type
filteredNamespaces returns activeNamespaceCache
subscribeNamespace single ns → undefined; multiple ns → undefined; empty array → []
validChange neither → true; ns in cache → true; ns missing → false; paginated id found → true; paginated id missing → false; ns-then-pagination order
validateBatchChange no filter → unchanged; ns filter removes out-of-scope; pagination filter removes missing ids; non-namespaced schema skips ns check; per-type caching (called once)

Coverage Impact

accept-or-reject-socket-message.ts moves from 0% → ~100% statement/branch coverage across all 6 methods.

Trade-offs

  • Tests mock getters inline, consistent with other Steve store tests in this repo.
  • No new dependencies.

Reproducibility

YARN_IGNORE_ENGINES=true NODE_OPTIONS=--max_old_space_size=8192 yarn test:ci --testPathPattern=shell/plugins/steve/__tests__/accept-or-reject-socket-message

Test Status

✅ All 23 tests pass. ESLint: 0 warnings.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • download.cypress.io

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "download.cypress.io"

See Network Configuration for more information.

Generated by Daily Test Improver · ● 5.4M ·

Test the class that filters WebSocket resource changes against
the active namespace cache and paginated page state.

- typeIsNamespaced: non-empty vs empty/undefined haveNamespace result
- typeIsPaginated: truthy vs falsy havePage result
- filteredNamespaces: returns activeNamespaceCache
- subscribeNamespace: non-empty array → undefined (sub to all); empty array → []
- validChange: non-ns/non-paginated → true; ns in cache → true; ns missing → false;
  paginated id found → true; paginated id missing → false; ns-then-pagination precedence
- validateBatchChange: no filter; ns filter removes out-of-scope entries; pagination
  filter removes missing ids; non-namespaced schema skips ns check; per-type
  caching (haveNamespace/havePage called once per type)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants