# Test Data Generation Scripts This directory contains scripts to help manage test data for the webstore backend. ## Available Scripts ### 0. Generate Placeholder Images Creates placeholder JPEG images for all 17 products used in seeding. **File:** `generate-placeholder-images.js` **What it does:** - Generates 17 placeholder product images (400x300px) - Saves images to `../images/` directory - Creates `uploads/` directory for user-uploaded images **Usage:** ```bash # Using npm script npm run generate-images # Or directly with Node node scripts/generate-placeholder-images.js ``` **When to run:** - First time setting up development environment - When `/images` route returns 404 (images not found) - After cleaning up the images directory **Images created (17 total):** - Shoes: street-runner.jpg, trail-edge.jpg, urban-sprint.jpg, classic-comfort.jpg - Bags: urban-tote.jpg, backpack-pro.jpg, crossbody.jpg, duffle.jpg - Accessories: classic-cap.jpg, silk-scarf.jpg, leather-belt.jpg, watch-straps.jpg - Clothing: cotton-tshirt.jpg, denim-jacket.jpg, yoga-leggings.jpg - Electronics: earbuds.jpg, usb-hub.jpg --- ### 1. Seed Script (Automatic) Runs automatically when the backend starts in development mode. **File:** `../prisma/seed.js` **What it does:** - Creates 5 product categories (Shoes, Bags, Accessories, Clothing, Electronics) - Creates 16 sample products across all categories - Creates 3 test user accounts **Test User Credentials:** ``` Email: admin@test.com Password: admin123 Email: john@test.com Password: password123 Email: jane@test.com Password: password123 ``` --- ## 2. Generate Test Data Script Generates additional bulk test data on demand. ### Usage Options #### Option A: Windows Batch File (Recommended for Windows) ```bash # Generate default test data (10 products, 5 orders) scripts\generate-test-data.bat # Generate 20 products instead of 10 scripts\generate-test-data.bat --products 20 # Generate 20 products and 10 orders scripts\generate-test-data.bat --products 20 --orders 10 # DANGEROUS: Reset database and regenerate all data scripts\generate-test-data.bat --reset --products 50 --orders 20 ``` #### Option B: NPM Script ```bash # Generate default test data npm run generate-data # With arguments (from project root) npm run generate-data -- --products 30 --orders 15 ``` #### Option C: Direct Node.js ```bash # From project root node scripts/generate-test-data.js --products 25 --orders 10 ``` ### Command-line Options | Option | Description | Default | |--------|-------------|---------| | `--products N` | Number of additional products to generate | 10 | | `--orders N` | Number of test orders to generate | 5 | | `--reset` | ⚠️ **DANGEROUS**: Delete all data first | (not set) | ### Examples ```bash # Quick test: Generate 5 products and 2 orders scripts\generate-test-data.bat --products 5 --orders 2 # Moderate data: 30 products and 10 orders npm run generate-data -- --products 30 --orders 10 # Heavy load test: 100 products and 50 orders scripts\generate-test-data.bat --products 100 --orders 50 # Start fresh: Reset and generate 50 products and 20 orders scripts\generate-test-data.bat --reset --products 50 --orders 20 ``` ## What Gets Generated ### Products - Random product names with auto-incrementing counters - Random prices between 5,990 and 24,990 HUF - Random stock quantities (5-55 units) - Random category assignment - Placeholder image URLs ### Test Users - 5 additional test user accounts - Email: `user[1-5]@test.com` - Password: `password123` ### Orders - Random customer names - Random customer emails - Random order items (1-3 products per order) - Automatically calculated total prices ## Important Notes ⚠️ **WARNING**: The `--reset` flag will delete: - All orders and order items - All products - All categories - All users Only use `--reset` if you know what you're doing! ## Troubleshooting ### "Node.js is not installed or not in PATH" - Install Node.js from https://nodejs.org/ - Make sure it's in your system PATH ### "Database connection error" - Ensure the database is running - Check `.env` file has correct `DATABASE_URL` - Run migrations first: `npm run prisma:push` ### "Unique constraint failed" errors - Product names must be unique - The script skips duplicates automatically - Use `--reset` to start fresh ## Docker Compose Integration The test data generation automatically runs in docker-compose: ```bash # Start backend (will seed data automatically) docker-compose up api # The initial data is seeded when the container first starts ``` For production, you may want to disable auto-seeding in the `docker-compose.yml` file.