Skip to content

Latest commit

 

History

History
335 lines (261 loc) · 8.64 KB

File metadata and controls

335 lines (261 loc) · 8.64 KB

🚀 Issue #49 - Startup & Testing Guide

This guide will help you start up the project and test the relationship features I just implemented.

📋 Prerequisites Check

Before starting, ensure you have:

  • ✅ Node.js >= 18.0.0
  • ✅ MongoDB running (local or Docker)
  • ✅ Git repository cloned

🔧 Quick Setup (5 minutes)

Step 1: Install Dependencies

# In the root directory
cd C:\Drip\muse-fullstack-dapp

# Install all dependencies
npm install

# Install backend dependencies
cd apps\backend
npm install

Step 2: Setup MongoDB

Option A: Using Docker (Recommended)

# Start MongoDB in Docker
docker run -d -p 27017:27017 --name muse-mongo mongo:6

# Verify it's running
docker ps

Option B: Check if MongoDB is already running

# Check if MongoDB process is running
Get-Process | Where-Object {$_.Name -like "*mongo*"}

# Or try to connect
mongosh --eval "db.version()"

Option C: Install MongoDB locally

Step 3: Create Environment Files

# In backend directory
cd C:\Drip\muse-fullstack-dapp\apps\backend

# Create .env file for development
@"
# Server
PORT=3001
NODE_ENV=development

# Database
MONGODB_URI=mongodb://localhost:27017/muse

# Authentication (use any 32+ char string for testing)
JWT_SECRET=test_secret_key_for_development_min_32_chars_12345

# Blockchain (optional for testing relationships)
STELLAR_NETWORK=testnet
STELLAR_RPC_URL=https://soroban-testnet.stellar.org

# AI Services (optional for testing relationships)
OPENAI_API_KEY=sk-test
STABILITY_API_KEY=sk-test
"@ | Out-File -FilePath .env -Encoding utf8

# Create .env.test file for testing
@"
# Test Database
MONGODB_URI_TEST=mongodb://localhost:27017/muse-test

# Test Settings
NODE_ENV=test
PORT=5001
JWT_SECRET=test_secret_key_for_testing_min_32_chars_12345
"@ | Out-File -FilePath .env.test -Encoding utf8

✅ Testing the Changes

Quick Test (Recommended - No MongoDB needed)

Just check for TypeScript/syntax errors:

cd C:\Drip\muse-fullstack-dapp\apps\backend

# Check for compilation errors
npm run build

If this succeeds with no errors, the code is valid! ✨

Unit Tests (Requires MongoDB)

Run the comprehensive test suite I created:

cd C:\Drip\muse-fullstack-dapp\apps\backend

# Run all tests including the new relationship tests
npm test

# Or run only the relationship tests
npm test -- relationships.test.ts

Expected output:

PASS  src/tests/relationships.test.ts
  Relationship Helpers
    Virtual Relationships
      ✓ should populate user created artworks (XX ms)
    toggleLike
      ✓ should add like when not exists (XX ms)
      ✓ should remove like when exists (XX ms)
    toggleFavorite
      ✓ should add favorite and update user stats (XX ms)
      ✓ should remove favorite and update user stats (XX ms)
    toggleFollow
      ✓ should create follow relationship and update stats (XX ms)
      ✓ should remove follow relationship and update stats (XX ms)
    Artwork Cascade Delete
      ✓ should delete all related data when artwork is deleted (XX ms)
    Query Helpers
      ✓ should get user created artworks with pagination (XX ms)
      ✓ should get artwork with all relationships (XX ms)
    Relationship Status Checks
      ✓ should check if user liked artwork (XX ms)
      ✓ should check if user is following another user (XX ms)

Test Suites: 1 passed, 1 total
Tests:       12 passed, 12 total

Run the Migration (Optional but Recommended)

This validates existing data and updates statistics:

cd C:\Drip\muse-fullstack-dapp\apps\backend

# Run the migration
npm run migrate

Expected output:

Starting relationship support migration...
Validating artwork references in transactions...
Found 0 transactions with invalid artwork references
Validating artwork references in bids...
Found 0 bids with invalid artwork references
...
Relationship support migration completed successfully!

Start the Development Server

# Terminal 1 - Start Backend
cd C:\Drip\muse-fullstack-dapp\apps\backend
npm run dev

# You should see:
# Server is running on port 3001
# Connected to MongoDB
# Environment: development

Test the API manually:

# In a new terminal, test the health endpoint
curl http://localhost:3001/health

# Or in PowerShell:
Invoke-WebRequest -Uri http://localhost:3001/health

🔍 Verify the Changes

Check Model Files Have Been Updated

# Check User model has virtual relationships
Select-String -Path "apps\backend\src\models\User.ts" -Pattern "virtual\("

# Check Artwork model has cascade delete
Select-String -Path "apps\backend\src\models\Artwork.ts" -Pattern "pre\('deleteOne'"

# Check relationship helpers exist
Test-Path "apps\backend\src\utils\relationshipHelpers.ts"

# Check migration exists
Test-Path "apps\backend\src\migrations\003_add_relationship_support.ts"

View the Implementation

# Open files to review changes
code apps\backend\src\models\User.ts
code apps\backend\src\models\Artwork.ts
code apps\backend\src\utils\relationshipHelpers.ts
code apps\backend\src\migrations\003_add_relationship_support.ts

📊 What Was Implemented

✅ Files Modified/Created:

  1. User.ts - Added 13 virtual relationships
  2. Artwork.ts - Added 6 virtual relationships + cascade delete
  3. Transaction.ts - Enabled virtual serialization
  4. Bid.ts - Enabled virtual serialization
  5. Collection.ts - Enabled virtual serialization
  6. Like.ts - Enabled virtual serialization
  7. Favorite.ts - Enabled virtual serialization
  8. Follow.ts - Enabled virtual serialization
  9. Notification.ts - Enabled virtual serialization
  10. relationshipHelpers.ts - NEW: 20+ helper functions
  11. 003_add_relationship_support.ts - NEW: Migration script
  12. relationships.test.ts - NEW: Comprehensive test suite

✅ Features Tested:

  • ✓ Virtual relationships (populate)
  • ✓ Toggle like (add/remove)
  • ✓ Toggle favorite (add/remove with stats)
  • ✓ Toggle follow (add/remove with stats)
  • ✓ Cascade delete (cleanup related data)
  • ✓ Query helpers (pagination, filtering)
  • ✓ Status checks (hasLiked, isFollowing)
  • ✓ Activity feeds

🎯 Testing Checklist

Run through this checklist to fully verify:

  • TypeScript Compilation: npm run build succeeds
  • No Syntax Errors: Code compiles without errors
  • MongoDB Connection: Can connect to MongoDB
  • Unit Tests Pass: All 12 tests pass
  • Migration Runs: Migration completes successfully
  • Server Starts: Backend starts without errors
  • API Responds: Health check endpoint works

🐛 Troubleshooting

MongoDB Connection Error

Error: connect ECONNREFUSED ::1:27017

Solution: Make sure MongoDB is running

# Check if MongoDB is running
docker ps | Select-String mongo

# Or start it
docker start muse-mongo

Test Database Error

MongoServerError: Authentication failed

Solution: Use connection string without auth for local testing

MONGODB_URI_TEST=mongodb://localhost:27017/muse-test

Module Not Found Error

Cannot find module '../utils/relationshipHelpers'

Solution: Rebuild the project

npm run build

Port Already in Use

Error: listen EADDRINUSE: address already in use :::3001

Solution: Kill the process using that port

# Find process on port 3001
Get-NetTCPConnection -LocalPort 3001 | Select-Object -Property OwningProcess

# Kill it (replace XXXX with process ID)
Stop-Process -Id XXXX -Force

📚 Next Steps

After verifying everything works:

  1. Review the documentation: Check ISSUE_49_RESOLUTION.md
  2. Explore the API: Import relationship helpers in controllers
  3. Test in real app: Try the features in the frontend
  4. Run full test suite: npm test to ensure nothing broke

🎉 Success Criteria

You've successfully tested the implementation if:

  • ✅ All TypeScript files compile without errors
  • ✅ All unit tests pass (12/12)
  • ✅ Migration runs successfully
  • ✅ Backend starts and connects to MongoDB
  • ✅ No console errors or warnings

💡 Quick Verification (30 seconds)

Don't want to set up MongoDB? Just run this:

cd C:\Drip\muse-fullstack-dapp\apps\backend
npm run build

If you see:

Successfully compiled TypeScript

Then the implementation is syntactically correct and ready to use! 🎊


Questions? Check the main documentation in ISSUE_49_RESOLUTION.md