Test: add vitest tests for GET and PUT /api/profiles/me routes#76
Open
Dipti45sktech wants to merge 2 commits into
Open
Test: add vitest tests for GET and PUT /api/profiles/me routes#76Dipti45sktech wants to merge 2 commits into
Dipti45sktech wants to merge 2 commits into
Conversation
Author
|
Hi @ShantKhatri, would really appreciate if you could review my PR whenever available. |
ShantKhatri
reviewed
May 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Picked up issue #3 to add proper Vitest tests for the authenticated GET and PUT /api/profiles/me endpoints. Reviewed profiles.ts to understand how the user ID is extracted from JWT and how Prisma queries are handled.
Also checked validators.ts, focusing on the accentColor zod validation for correct failure cases.Set up a reusable buildApp() helper that creates a Fastify instance with Prisma and auth mocked using vi.fn(). This avoids needing a real database while keeping tests close to real behavior.
Wrote 5 test cases covering all required scenarios. These include successful profile fetch and update flows. Handled edge cases like 404 for missing user and 409 for duplicate username. Also added a 400 test for invalid accentColor input.
Ensured sensitive fields like provider and providerId are not returned in responses.
All tests pass locally.
Closes #3
Type of Change
What Changed
apps/backend/src/__tests__/profiles.test.tswith full test coverageapp.prisma.user.findUnique,findFirst, andupdateusingvi.fn()buildApp()helper that spins up a test Fastify instance with mocked auth and prismaHow to Test
pnpm installpnpm --filter @devcard/backend testChecklist
pnpm -r run lintpasses).pnpm -r run typecheck).pnpm -r run test).console.logor debug statements left in the code.Additional Context
Prisma and authentication are fully mocked so no database setup is needed to run these tests. The
buildApp()helper can be reused in future test files for other routes.