- Add duplicate photo detection (file hash and URL checking) - Add max attempts per photo with UI counter - Simplify penalty system (auto-enable when points > 0) - Prevent scores from going below 0 - Add admin photo deletion functionality - Improve navigation with always-visible logout - Prevent users from guessing their own photos
7.1 KiB
Testing Guide for MirrorMatch
This guide will help you set up and test the MirrorMatch application locally.
Prerequisites Check
Before starting, ensure you have:
- ✅ Node.js 18+ installed (
node --version) - ✅ npm installed (
npm --version) - ✅ PostgreSQL installed and running (
psql --version) - ✅ Git (if cloning the repository)
Step-by-Step Setup
1. Install Dependencies
cd mirrormatch
npm install
This installs all required packages including Next.js, Prisma, NextAuth, etc.
2. Set Up PostgreSQL Database
Option A: Using Docker (Recommended for Quick Testing)
# Start PostgreSQL in Docker
docker run --name mirrormatch-db \
-e POSTGRES_PASSWORD=postgres \
-e POSTGRES_DB=mirrormatch \
-p 5432:5432 \
-d postgres:15
# Wait a few seconds for PostgreSQL to start
Option B: Local PostgreSQL Installation
# Create database (if not exists)
createdb mirrormatch
# Or using psql
psql -U postgres -c "CREATE DATABASE mirrormatch;"
3. Configure Environment Variables
Create a .env file in the project root:
cp env.example .env
Then edit .env and update the following:
# Database - Update with your PostgreSQL credentials
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/mirrormatch?schema=public"
# NextAuth - Generate a secret key
NEXTAUTH_URL="http://localhost:3000"
NEXTAUTH_SECRET="your-secret-key-here"
# Email (optional for dev - uses Ethereal by default)
# Leave SMTP settings empty for development
Generate NEXTAUTH_SECRET:
openssl rand -base64 32
Copy the output and paste it as the NEXTAUTH_SECRET value in .env.
4. Set Up Database Schema
# Generate Prisma Client
npm run db:generate
# Create database tables (choose one method)
npm run db:migrate # Creates migration files (recommended)
# OR
npm run db:push # Pushes schema directly (faster for dev)
5. Seed Initial Data
npm run db:seed
This creates the default admin user:
- Email:
admin@mirrormatch.com - Password:
admin123
⚠️ Important: Change this password after first login!
6. Start the Development Server
npm run dev
The app should start at http://localhost:3000
Testing the Application
Initial Login
- Open http://localhost:3000
- You'll be redirected to
/login - Login with:
- Email:
admin@mirrormatch.com - Password:
admin123
- Email:
Test Admin Features
-
Navigate to Admin Panel:
- Click "Admin" in the navigation bar
- You should see the admin panel
-
Create a Test User:
- Fill in the form:
- Name:
Test User - Email:
test@example.com - Password:
test123 - Role:
USER
- Name:
- Click "Create User"
- Verify the user appears in the user list
- Fill in the form:
-
Reset Password:
- In the user list, enter a new password for any user
- Click "Reset"
- Verify success message
Test User Features
-
Logout and Login as Test User:
- Click "Logout"
- Login with
test@example.com/test123
-
Upload a Photo:
- Navigate to "Upload" in the navigation
- Enter a photo URL (e.g.,
https://via.placeholder.com/800x600) - Enter an answer name (e.g.,
John Doe) - Click "Upload Photo"
- Check the console for email notification logs (dev mode)
-
View Photos:
- Navigate to "Photos"
- You should see the uploaded photo
- Click on a photo to view details
-
Submit a Guess:
- On a photo detail page, enter a guess
- Try wrong guess first (e.g.,
Jane Doe) - See "Wrong guess" message
- Try correct guess (e.g.,
John Doe) - See "Correct!" message and points increment
-
Check Leaderboard:
- Navigate to "Leaderboard"
- Verify users are ranked by points
- Your user should be highlighted
-
Change Password:
- Navigate to "Profile"
- Scroll to "Change Password"
- Enter current password and new password
- Verify success message
Test Email Notifications (Development)
In development mode, emails use Ethereal Email:
- Upload a photo as one user
- Check the console for email logs
- Look for a message like:
Email sent (dev mode): Preview URL: https://ethereal.email/message/... - Open the preview URL to see the email
Common Issues and Solutions
Database Connection Error
Error: Can't reach database server
Solutions:
- Verify PostgreSQL is running:
pg_isreadyordocker ps - Check
DATABASE_URLin.envmatches your PostgreSQL setup - Ensure database exists:
psql -l | grep mirrormatch
Prisma Client Not Generated
Error: @prisma/client did not initialize yet
Solution:
npm run db:generate
Migration Errors
Error: Migration failed
Solutions:
- Reset database (⚠️ deletes all data):
npm run db:push -- --force-reset - Or create fresh migration:
npm run db:migrate
NextAuth Secret Missing
Error: NEXTAUTH_SECRET is not set
Solution:
- Generate secret:
openssl rand -base64 32 - Add to
.env:NEXTAUTH_SECRET="generated-secret"
Port Already in Use
Error: Port 3000 is already in use
Solutions:
- Kill the process using port 3000:
lsof -ti:3000 | xargs kill -9 - Or change port in
package.jsondev script
Testing Checklist
Use this checklist to verify all features:
- Admin can login
- Admin can create users
- Admin can reset user passwords
- Regular user can login
- User can upload photos
- Email notifications are sent (check console)
- User can view photos list
- User can view photo details
- User can submit guesses
- Wrong guesses show error message
- Correct guesses award points
- Leaderboard shows users ranked by points
- User can change password
- User can logout
- Protected routes require authentication
- Admin routes require ADMIN role
Database Management
View Database in Prisma Studio
npm run db:studio
Opens a GUI at http://localhost:5555 to browse and edit data.
Reset Database
⚠️ Warning: This deletes all data!
npm run db:push -- --force-reset
npm run db:seed
View Database Schema
cat prisma/schema.prisma
Development Tips
- Hot Reload: Next.js automatically reloads on file changes
- Console Logs: Check browser console and terminal for errors
- Database Changes: After modifying
schema.prisma, run:npm run db:generate npm run db:push - Email Testing: In dev mode, emails are logged to console or use Ethereal preview URLs
Next Steps
After testing locally:
- Review the codebase structure
- Read
ARCHITECTURE.mdfor system design - Read
CONTRIBUTING.mdfor coding conventions - Read
SECURITY.mdfor security practices - Start developing new features!
Getting Help
- Check
README.mdfor general setup - Check
ARCHITECTURE.mdfor system design questions - Check
CONTRIBUTING.mdfor development workflow - Check console/terminal for error messages
Happy Testing! 🎯