Skip to content

test: add coverage for auth/me, credentials, and user profile endpoints (#202)#251

Merged
3m1n3nc3 merged 3 commits intogeevapp:mainfrom
BigBen-7:feat/202-auth-user-test-coverage
Mar 29, 2026
Merged

test: add coverage for auth/me, credentials, and user profile endpoints (#202)#251
3m1n3nc3 merged 3 commits intogeevapp:mainfrom
BigBen-7:feat/202-auth-user-test-coverage

Conversation

@BigBen-7
Copy link
Copy Markdown
Contributor

Summary

Closes #202. Adds unit test coverage for the three critical paths that had zero automated tests:

  • tests/api/auth.test.tsGET /api/auth/me

    • Returns 401 when no session / session has no user id
    • Returns 404 when session user is not found in DB
    • Returns 200 with full user shape on valid session
    • Falls back to default newcomer rank when rank is null
    • Flattens badges from the UserBadge join table
  • tests/api/auth-credentials.test.ts — NextAuth Credentials authorize callback (login + register logic)

    • Register: valid signature + username → creates user in DB
    • Register: with email → email stored on new user
    • Login: valid signature, existing user → returns user without creating
    • Invalid signature → returns null (→ 401)
    • Login attempt for non-existent user (no username) → returns null (→ 401)
    • Empty credentials → returns null
    • Malformed wallet key (Keypair.fromPublicKey throws) → returns null
  • tests/api/users.test.tsGET /PATCH /api/users/[id]

    • GET: 200 with profile, 404 for unknown user
    • GET: isFollowing flag set correctly for authenticated and anonymous requests
    • PATCH: 401 when unauthenticated, 403 when updating another user's profile
    • PATCH: 200 on own-profile update, 409 on username/email conflict

Approach

Follows the exact patterns from tests/api/posts.test.ts and tests/api/interactions.unit.test.ts:

  • vi.mock / vi.hoisted for all external dependencies (Prisma, auth, Stellar SDK, PrismaAdapter)
  • createMockRequest / parseResponse from tests/helpers/api.ts
  • All mock data defined inline — no real DB calls

Test plan

  • pnpm --filter app test passes locally
  • All new test cases reported as passing in CI

Covers the three uncovered critical paths identified in issue #202:
- GET /api/auth/me: 401 with no/invalid session, 404 user not in DB, 200 happy path, rank fallback, badge flattening
- Auth Credentials authorize: register new user, login existing user, invalid signature, missing user on login, malformed key
- GET/PATCH /api/users/[id]: 404 unknown user, isFollowing flag, 401/403/409 guards, own-profile update
@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 26, 2026

@BigBen-7 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

Copy link
Copy Markdown
Contributor

@3m1n3nc3 3m1n3nc3 left a comment

Choose a reason for hiding this comment

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

Please fix the failing tests

- Fix parse error in users.test.ts caused by apostrophe in single-quoted string
- Fix auth-credentials tests accessing the default stub authorize instead of
  the real implementation: in NextAuth v5 beta.30, Credentials() stores the
  user-provided config at .options, so authorize is at .options.authorize
The route was moved from app/api/auth/me/route.ts to (auth)/me/route.ts
in upstream main (commit 4ac1a9c). Update the test import accordingly.
@BigBen-7
Copy link
Copy Markdown
Contributor Author

@3m1n3nc3 fixed

@3m1n3nc3 3m1n3nc3 merged commit efbaf6d into geevapp:main Mar 29, 2026
2 checks passed
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.

Add test coverage for auth routes, user endpoints, and entry management

2 participants