Skip to content

test: re-work some brittle atproto mocks#2798

Open
serhalp wants to merge 1 commit into
mainfrom
serhalp/test/fix-atproto-mocks
Open

test: re-work some brittle atproto mocks#2798
serhalp wants to merge 1 commit into
mainfrom
serhalp/test/fix-atproto-mocks

Conversation

@serhalp
Copy link
Copy Markdown
Member

@serhalp serhalp commented May 26, 2026

🔗 Linked issue

N/A

🧭 Context

I dunno, these started failing on a completely unrelated branch and simplifying them like this fixed it 😅.

📚 Description

  • Don't configure different behaviour in test than elsewhere.
  • Stop mocking useAtproto in a few tests, instead mocking the auth endpoint. These tests were brittle because they mocked with partial or otherwise not-quite-valid data, leading to difficult to debug failures.

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 26, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
npmx.dev Ready Ready Preview, Comment May 30, 2026 3:05am
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
docs.npmx.dev Ignored Ignored Preview May 30, 2026 3:05am
npmx-lunaria Ignored Ignored May 30, 2026 3:05am

Request Review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 26, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

Tests were refactored to replace hoisted useAtproto mocks with a registered /api/auth/session test endpoint driven by authSessionHandler; like endpoint mocks were adapted to endpoint objects; the atproto disconnect test now asserts a DELETE session handler; useAtproto no longer sets immediate: !import.meta.test on its fetch.

Changes

Auth-session endpoint driven test refactor

Layer / File(s) Summary
Package/Likes tests: endpoint-driven auth and like mock
test/nuxt/components/Package/Likes.spec.ts
Replaced hoisted useAtproto mock with authSessionHandler and registered /api/auth/session; updated /api/social/like mock to { method: 'POST', handler }; added an assertion that authSessionRequests > 0.
ProfileInviteSection tests: auth loading and owner/non-owner flows
test/nuxt/components/ProfileInviteSection.spec.ts
Removed hoisted useAtproto mock, registered /api/auth/session returned by authSessionHandler; tests cover auth-loading, non-owner (other-user) and owner (test-handle) flows and wait for auth resolution before asserting UI.
useCommandPaletteCommands tests: endpoint auth and disconnect assertion
test/nuxt/composables/use-command-palette-commands.spec.ts
Switched from module-scoped useAtproto stubs to a top-level /api/auth/session registration delegating to authSessionHandler; captureCommandPalette configures the handler per test; afterEach resets it; disconnect test registers and asserts a DELETE /api/auth/session handler call.
useAtproto composable: fetch option tweak
app/composables/atproto/useAtproto.ts
Removed immediate: !import.meta.test from the useFetch('/api/auth/session', ...) call.

Possibly related PRs

  • npmx-dev/npmx.dev#2459: Introduced the topLikedRank badge behaviour in the Package/Likes component that this PR's test refactoring now supports with endpoint-driven session mocking.

Suggested reviewers

  • graphieros
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarises the main change: refactoring brittle atproto mocks in tests to use runtime composable state instead.
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.
Description check ✅ Passed The pull request description clearly explains the motivation and changes: stopping brittle useAtproto mocks in favour of mocking the auth endpoint instead, with specific context about why this improves test reliability.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch serhalp/test/fix-atproto-mocks

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@codecov
Copy link
Copy Markdown

codecov Bot commented May 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

Stop mocking `useAtproto` in a few tests and instead set the shared
composable state that the app reads at runtime. These tests were brittle
because they mocked with partial or otherwise not-quite-valid data,
leading to difficult to debug failures.
@serhalp serhalp force-pushed the serhalp/test/fix-atproto-mocks branch from e1889a1 to b56aed5 Compare May 30, 2026 03:03
@serhalp serhalp marked this pull request as ready for review May 30, 2026 16:59
@serhalp serhalp added the needs review This PR is waiting for a review from a maintainer label May 30, 2026
@serhalp serhalp requested a review from a team May 30, 2026 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs review This PR is waiting for a review from a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant