Skip to content

test: re-work some brittle atproto mocks - #2798

Merged
ghostdevv merged 1 commit into
mainfrom
serhalp/test/fix-atproto-mocks
May 31, 2026
Merged

test: re-work some brittle atproto mocks#2798
ghostdevv merged 1 commit into
mainfrom
serhalp/test/fix-atproto-mocks

Conversation

@serhalp

@serhalpserhalp commented May 26, 2026

Copy link
Copy Markdown
Member

🔗 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

vercelBot commented May 26, 2026

Copy link
Copy Markdown
Contributor

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

ProjectDeploymentActionsUpdated (UTC)
npmx.devReadyReadyPreview, CommentMay 30, 2026 3:05am
2 Skipped Deployments
ProjectDeploymentActionsUpdated (UTC)
docs.npmx.devIgnoredIgnoredPreviewMay 30, 2026 3:05am
npmx-lunariaIgnoredIgnoredMay 30, 2026 3:05am

Request Review

@coderabbitai

coderabbitaiBot commented May 26, 2026

Copy link
Copy Markdown
Contributor

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 nameStatusExplanation
Title check✅ PassedThe title accurately summarises the main change: refactoring brittle atproto mocks in tests to use runtime composable state instead.
Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
Out of Scope Changes check✅ PassedCheck skipped because no linked issues were found for this pull request.
Description check✅ PassedThe 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

codecovBot commented May 26, 2026

Copy link
Copy Markdown

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
serhalpforce-pushed the serhalp/test/fix-atproto-mocks branch from e1889a1 to b56aed5CompareMay 30, 2026 03:03
@serhalp
serhalp marked this pull request as ready for review May 30, 2026 16:59
@serhalpserhalp 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 teamMay 30, 2026 18:31
@ghostdevvghostdevv removed the needs review This PR is waiting for a review from a maintainer label May 31, 2026
@ghostdevv
ghostdevv added this pull request to the merge queueMay 31, 2026
Merged via the queue into main with commit 6909832May 31, 2026
29 checks passed
@ghostdevv
ghostdevv deleted the serhalp/test/fix-atproto-mocks branch May 31, 2026 14:03
@github-actionsgithub-actionsBot mentioned this pull request May 31, 2026
ayo-run pushed a commit to ayo-run/npmx.dev that referenced this pull request Aug 5, 2026
Sign up for freeto 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

@serhalp@ghostdevv