Skip to content

test(query-persist-client-core/retryStrategies): add tests for 'removeOldestQuery' removing the oldest query#10867

Merged
sukvvon merged 1 commit into
mainfrom
test/query-persist-client-core-remove-oldest-query
Jun 3, 2026
Merged

test(query-persist-client-core/retryStrategies): add tests for 'removeOldestQuery' removing the oldest query#10867
sukvvon merged 1 commit into
mainfrom
test/query-persist-client-core-remove-oldest-query

Conversation

@sukvvon
Copy link
Copy Markdown
Collaborator

@sukvvon sukvvon commented Jun 3, 2026

🎯 Changes

Adds unit tests for the removeOldestQuery predefined retry strategy, which previously had no direct unit test in its defining package.

These tests cover its core behavior: it removes the single query with the oldest dataUpdatedAt, and when several queries share that oldest timestamp only one of them is removed.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test:pr.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Tests
    • Added comprehensive test suite for query removal functionality to ensure correct behavior when managing query cache with timestamp-based ordering.

@sukvvon sukvvon self-assigned this Jun 3, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 3, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds a new test file for the removeOldestQuery function, establishing test coverage for query eviction behavior. The suite uses helper functions to create persisted queries with customizable timestamps and validates two core scenarios: selective removal when timestamps differ, and graceful handling when multiple queries share the oldest timestamp.

Changes

removeOldestQuery Test Coverage

Layer / File(s) Summary
removeOldestQuery test suite with helpers
packages/query-persist-client-core/src/__tests__/retryStrategies.test.ts
New Vitest test module with helper functions (createPersistedQueries, createPersistedClient) to construct persisted query objects and client state. Two test cases verify that removeOldestQuery removes the query with the smallest dataUpdatedAt value, and removes only one query when multiple queries share the oldest timestamp. QueryClient is cleared after each test.

🎯 3 (Moderate) | ⏱️ ~20 minutes

🐰 A test file hops in with helpers bright,
Ensuring queries evict just right—
Old timestamps begone, one at a time,
Tied ages handled, a logical rhyme!
Query persistence now tested with care! 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and specifically describes the main change: adding tests for the removeOldestQuery function with clear details about what behavior is being tested.
Description check ✅ Passed The description follows the template structure with completed sections: Changes section explains the purpose and test coverage, Checklist items are marked appropriately, and Release Impact correctly identifies this as dev-only.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/query-persist-client-core-remove-oldest-query

Comment @coderabbitai help to get the list of available commands and usage tips.

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Jun 3, 2026

View your CI Pipeline Execution ↗ for commit 7080f92

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 1m 38s View ↗

☁️ Nx Cloud last updated this comment at 2026-06-03 14:45:16 UTC

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 3, 2026

🚀 Changeset Version Preview

No changeset entries found. Merging this PR will not cause a version bump for any packages.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Jun 3, 2026

More templates

@tanstack/angular-query-experimental

npm i https://pkg.pr.new/@tanstack/angular-query-experimental@10867

@tanstack/eslint-plugin-query

npm i https://pkg.pr.new/@tanstack/eslint-plugin-query@10867

@tanstack/lit-query

npm i https://pkg.pr.new/@tanstack/lit-query@10867

@tanstack/preact-query

npm i https://pkg.pr.new/@tanstack/preact-query@10867

@tanstack/preact-query-devtools

npm i https://pkg.pr.new/@tanstack/preact-query-devtools@10867

@tanstack/preact-query-persist-client

npm i https://pkg.pr.new/@tanstack/preact-query-persist-client@10867

@tanstack/query-async-storage-persister

npm i https://pkg.pr.new/@tanstack/query-async-storage-persister@10867

@tanstack/query-broadcast-client-experimental

npm i https://pkg.pr.new/@tanstack/query-broadcast-client-experimental@10867

@tanstack/query-core

npm i https://pkg.pr.new/@tanstack/query-core@10867

@tanstack/query-devtools

npm i https://pkg.pr.new/@tanstack/query-devtools@10867

@tanstack/query-persist-client-core

npm i https://pkg.pr.new/@tanstack/query-persist-client-core@10867

@tanstack/query-sync-storage-persister

npm i https://pkg.pr.new/@tanstack/query-sync-storage-persister@10867

@tanstack/react-query

npm i https://pkg.pr.new/@tanstack/react-query@10867

@tanstack/react-query-devtools

npm i https://pkg.pr.new/@tanstack/react-query-devtools@10867

@tanstack/react-query-next-experimental

npm i https://pkg.pr.new/@tanstack/react-query-next-experimental@10867

@tanstack/react-query-persist-client

npm i https://pkg.pr.new/@tanstack/react-query-persist-client@10867

@tanstack/solid-query

npm i https://pkg.pr.new/@tanstack/solid-query@10867

@tanstack/solid-query-devtools

npm i https://pkg.pr.new/@tanstack/solid-query-devtools@10867

@tanstack/solid-query-persist-client

npm i https://pkg.pr.new/@tanstack/solid-query-persist-client@10867

@tanstack/svelte-query

npm i https://pkg.pr.new/@tanstack/svelte-query@10867

@tanstack/svelte-query-devtools

npm i https://pkg.pr.new/@tanstack/svelte-query-devtools@10867

@tanstack/svelte-query-persist-client

npm i https://pkg.pr.new/@tanstack/svelte-query-persist-client@10867

@tanstack/vue-query

npm i https://pkg.pr.new/@tanstack/vue-query@10867

@tanstack/vue-query-devtools

npm i https://pkg.pr.new/@tanstack/vue-query-devtools@10867

commit: 7080f92

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/query-persist-client-core/src/__tests__/retryStrategies.test.ts (1)

41-75: ⚡ Quick win

Consider adding edge case coverage for empty queries.

The current tests effectively cover the main behaviors. However, the implementation returns undefined when the queries array is empty (a distinct code path). Adding a test case for this edge case would improve coverage and document the expected behavior.

📋 Suggested test case
it('should return undefined when there are no queries to remove', () => {
  const persistedClient = createPersistedClient([])

  const result = removeOldestQuery({
    persistedClient,
    error: new Error('full'),
    errorCount: 1,
  })

  expect(result).toBeUndefined()
})
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/query-persist-client-core/src/__tests__/retryStrategies.test.ts`
around lines 41 - 75, Add a test that covers the empty-queries code path by
calling removeOldestQuery with a persisted client created via
createPersistedClient([]) and asserting the result is undefined; this verifies
the function removeOldestQuery returns undefined when
persistedClient.clientState.queries is empty and documents the expected
behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/query-persist-client-core/src/__tests__/retryStrategies.test.ts`:
- Around line 41-75: Add a test that covers the empty-queries code path by
calling removeOldestQuery with a persisted client created via
createPersistedClient([]) and asserting the result is undefined; this verifies
the function removeOldestQuery returns undefined when
persistedClient.clientState.queries is empty and documents the expected
behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9195c565-564b-40a3-a13d-79672f2babb8

📥 Commits

Reviewing files that changed from the base of the PR and between dc0effd and 7080f92.

📒 Files selected for processing (1)
  • packages/query-persist-client-core/src/__tests__/retryStrategies.test.ts

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 3, 2026

size-limit report 📦

Path Size
react full 12.11 KB (0%)
react minimal 9.08 KB (0%)

@sukvvon sukvvon merged commit 64b54a0 into main Jun 3, 2026
11 of 12 checks passed
@sukvvon sukvvon deleted the test/query-persist-client-core-remove-oldest-query branch June 3, 2026 14:57
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.

1 participant