# Testing Fitness Profile Feature

## Overview

This guide provides step-by-step instructions for manually testing the Fitness Profile feature in the FitAI mobile app.

## Prerequisites

1. **Admin API running**: 
   ```bash
   cd apps/admin
   npm run dev
   ```
   Server should be running at `http://localhost:3000`

2. **Mobile app running**:
   ```bash
   cd apps/mobile
   npx expo start
   ```
   Choose your platform (iOS/Android/Web)

3. **User account**: Have a Clerk user account created and verified

4. **Database**: Ensure the `fitness_profiles` table exists
   ```bash
   cd packages/database
   npm run db:push
   ```

## Test Scenarios

### Test 1: Create New Fitness Profile

**Steps:**
1. Open the mobile app
2. Sign in with your Clerk account
3. Navigate to Home screen (should be automatic after sign-in)
4. Locate the "Quick Actions" section
5. Tap the "Fitness Profile" button (pink fitness icon)
6. Verify the screen loads with empty form fields

**Expected Result:**
- Fitness Profile screen opens
- All fields are empty
- No errors displayed

### Test 2: Fill Out Basic Information

**Steps:**
1. In the "Basic Information" section, fill in:
   - Height: `175` (cm)
   - Weight: `70` (kg)
   - Age: `25`
   - Gender: Select `Male` from dropdown

**Expected Result:**
- All fields accept input correctly
- Dropdowns open and allow selection
- No validation errors

### Test 3: Set Fitness Goals

**Steps:**
1. In the "Fitness Goals" section, fill in:
   - Primary Goal: Select `Muscle Gain`
   - Activity Level: Select `Moderately Active`

**Expected Result:**
- Dropdowns work correctly
- Selected values are displayed

### Test 4: Add Health Information (Optional)

**Steps:**
1. In the "Health Information" section, fill in:
   - Medical Conditions: `None`
   - Allergies: `Peanuts`
   - Injuries: `Previous knee injury in 2023`

**Expected Result:**
- Multi-line text areas accept input
- Text wraps properly

### Test 5: Save Profile

**Steps:**
1. Scroll to bottom of form
2. Tap "Save Profile" button
3. Wait for API response

**Expected Result:**
- Loading indicator appears on button
- Success alert: "Fitness profile saved successfully!"
- Alert has "OK" button
- Tapping "OK" returns to Home screen

### Test 6: Verify Data Persistence

**Steps:**
1. From Home screen, tap "Fitness Profile" again
2. Wait for profile to load

**Expected Result:**
- Loading indicator shows briefly
- All previously entered data is displayed correctly:
  - Height: 175
  - Weight: 70
  - Age: 25
  - Gender: Male
  - Primary Goal: Muscle Gain
  - Activity Level: Moderately Active
  - Medical Conditions: None
  - Allergies: Peanuts
  - Injuries: Previous knee injury in 2023

### Test 7: Update Existing Profile

**Steps:**
1. Change some values:
   - Weight: `72`
   - Primary Goal: Change to `Weight Loss`
2. Tap "Save Profile"

**Expected Result:**
- Success alert: "Fitness profile saved successfully!"
- Data is updated in database

### Test 8: Verify Update Persistence

**Steps:**
1. Navigate back to Home
2. Return to Fitness Profile
3. Verify updated values are shown

**Expected Result:**
- Weight shows `72`
- Primary Goal shows `Weight Loss`
- All other fields remain unchanged

### Test 9: Back Button Navigation

**Steps:**
1. On Fitness Profile screen
2. Tap the back arrow (←) in top-left corner

**Expected Result:**
- Returns to Home screen
- No data loss (changes not saved unless "Save Profile" was tapped)

### Test 10: Partial Data Entry

**Steps:**
1. Create a new user or delete existing profile
2. Fill in only Height: `180` and Gender: `Female`
3. Leave all other fields empty
4. Tap "Save Profile"

**Expected Result:**
- Profile saves successfully
- Only filled fields are stored
- Empty fields remain null/empty in database

## Database Verification

### Check Profile in Database

```bash
cd apps/admin
npm run db:studio
```

Then:
1. Navigate to `fitness_profiles` table
2. Find your user's profile (match `user_id` with Clerk user ID)
3. Verify all fields match what you entered

### SQL Query (Alternative)

If you have SQLite CLI access:

```bash
cd apps/admin/data
sqlite3 fitai.db
```

```sql
-- View all fitness profiles
SELECT * FROM fitness_profiles;

-- View specific user's profile
SELECT * FROM fitness_profiles WHERE user_id = 'user_YOUR_CLERK_ID';

-- Check profile count
SELECT COUNT(*) FROM fitness_profiles;
```

## API Testing

### Test GET Endpoint

```bash
# Get your Clerk token first (from Clerk Dashboard or mobile app)
export CLERK_TOKEN="your_token_here"

curl -X GET http://localhost:3000/api/fitness-profile \
  -H "Authorization: Bearer $CLERK_TOKEN"
```

**Expected Response:**
```json
{
  "profile": {
    "id": "fp_...",
    "user_id": "user_...",
    "height": 175,
    "weight": 70,
    ...
  }
}
```

### Test POST Endpoint

```bash
curl -X POST http://localhost:3000/api/fitness-profile \
  -H "Authorization: Bearer $CLERK_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "height": 175,
    "weight": 70,
    "age": 25,
    "gender": "male",
    "fitnessGoal": "muscle_gain",
    "activityLevel": "moderately_active"
  }'
```

**Expected Response:**
```json
{
  "message": "Fitness profile created successfully",
  "profileId": "fp_..."
}
```

## Error Scenarios

### Test 1: Unauthorized Access

**Steps:**
1. Sign out from mobile app
2. Attempt to access Fitness Profile (should not be possible)

**Expected Result:**
- User is redirected to sign-in screen
- Fitness Profile is not accessible without authentication

### Test 2: Network Error

**Steps:**
1. Stop the admin API server
2. Try to save profile in mobile app

**Expected Result:**
- Error alert: "Failed to save fitness profile"
- User can retry after restarting server

### Test 3: Invalid Data Types

**Steps:**
1. Enter letters in Height field: `abc`
2. Try to save

**Expected Result:**
- Numeric keyboard prevents letter entry (on mobile)
- Or validation error if somehow entered

## Common Issues & Solutions

### Issue: Profile doesn't load
**Solution:** 
- Check admin API is running
- Verify `EXPO_PUBLIC_API_URL` is set correctly
- Check browser/app console for errors

### Issue: Save button doesn't work
**Solution:**
- Check network connection
- Verify Clerk authentication token is valid
- Check admin API logs for errors

### Issue: Data not persisting
**Solution:**
- Verify database migration ran successfully
- Check `fitness_profiles` table exists
- Verify write permissions on SQLite database

### Issue: Picker dropdowns don't open
**Solution:**
- Ensure `@react-native-picker/picker` is installed
- Run `npx expo start -c` to clear cache
- Restart app

## Performance Testing

### Test Loading Speed

1. Time from tapping "Fitness Profile" to screen fully loaded
   - **Target:** < 500ms with existing profile
   - **Target:** < 200ms for new profile (no data to load)

2. Time from tapping "Save" to success message
   - **Target:** < 1 second

### Test Responsiveness

1. Scroll performance: Smooth scrolling on all devices
2. Input lag: Immediate feedback when typing
3. Picker responsiveness: Opens/closes without delay

## Sign-off Checklist

- [ ] Can create new fitness profile
- [ ] Can update existing profile
- [ ] Data persists across app restarts
- [ ] All dropdowns work correctly
- [ ] All text inputs accept data
- [ ] Save button works and shows loading state
- [ ] Success message displays correctly
- [ ] Back button navigation works
- [ ] Data visible in database
- [ ] API endpoints respond correctly
- [ ] Authentication required and working
- [ ] Error handling works for network issues
- [ ] Optional fields can be left empty
- [ ] Profile unique per user (one profile per user)

## Next Steps

After completing these tests:
1. Document any bugs found in issue tracker
2. Verify fixes for any issues
3. Request code review
4. Plan automated test implementation
5. Deploy to staging environment for QA testing