Skip to content

feat(profile): added profile viewing with validated data layer and tests - #18

Open
minli13 wants to merge 1 commit into
mainfrom
feat/profile-view-data-layer
Open

minli13 wants to merge 1 commit into
mainfrom
feat/profile-view-data-layer

Conversation

@minli13

@minli13 minli13 commented Oct 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

Resolves #12: Build profile viewing and validated data layer.

New files:

  • src/features/profile/api/profile.types.ts - Profile types.
  • src/features/profile/api/profile.schema.ts - Zod schema for validating the backend profile response.
  • src/features/profile/api/profile.mapper.ts - Maps backend data to Profile and parseProfile as the shared entry point for validation and mapping.
  • src/features/profile/api/profile.errors.ts - Network, invalid data, and session expired errors.
  • src/features/profile/api/profile.gateway.ts - ProfileGateway interface.
  • src/features/profile/api/fakeProfileGateway.ts - Fake gateway with student, mentor, missing-data, failure, invalid-data, and session-expired scenarios, and failTimes for retry testing. Sample data is clearly fake (sample.*, .invalid email).
  • src/features/profile/api/ApiProfileGateway.ts - Structure for a future ApiProfileGateway.
  • src/features/profile/api/gatewayProvider.ts - Exports the gateway the app uses (currently the fake).
  • src/features/profile/hooks/useProfile.ts - TanStack Query hook that loads the profile through the gateway.
  • test/profile.schema.test.ts, test/profile.mapper.test.ts, test/fakeProfileGateway.test.ts, test/ProfileScreen.test.tsx - Tests for the new code.

Updated files:

  • app/(app)/(tabs)/profile.tsx - Name and role now come from useProfile instead of the session. Added a "Profile" details card (username, role, school, grade level, location). Missing values show "Not provided", and location is omitted when unavailable. Added loading, error (with retry), invalid-data, and expired-session states. Sign Out works in every state. Stats, badges, and menu rows remain the visual mock.
  • test/navigation.test.tsx - The profile assertion now expects the fake gateway's name ("Sample Student") instead of the old hardcoded session name ("Mock Student").

The screen calls useProfile(), which calls the ProfileGateway, and the gateway validates the data with Zod and converts it with the mapper. Connecting the real gateway later is a change in gatewayProvider.ts and ApiProfileGateway.ts.

Screenshots

Student Profile
student
Mentor Profile
mentor
Profile with missing data
missing_data
Loading screen
failure

Tests

Run the new tests with: npm run test -- ./test/ProfileScreen.test.tsx ./test/profile.schema.test.ts ./test/profile.mapper.test.ts ./test/fakeProfileGateway.test.ts
This should be result:
test_1
test_2
test__3
test_4

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.

Profile: Build profile viewing and validated data layer

1 participant