- Added test-monitor.sh for monitoring test execution metrics and generating reports - Created test-data-manager.sh for robust test data management - Added health-check.sh for comprehensive system health verification - Enhanced overall deployment safety and reliability 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
		
			
				
	
	
		
			526 lines
		
	
	
		
			No EOL
		
	
	
		
			21 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable file
		
	
	
	
	
			
		
		
	
	
			526 lines
		
	
	
		
			No EOL
		
	
	
		
			21 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable file
		
	
	
	
	
| #!/bin/bash
 | |
| # test-data-manager.sh - Script to manage test data for the HVAC Community Events plugin
 | |
| # Usage: ./bin/test-data-manager.sh [generate|verify|cleanup|backup|restore] [--suite=name]
 | |
| 
 | |
| set -e
 | |
| 
 | |
| # Colors for output
 | |
| GREEN='\033[0;32m'
 | |
| YELLOW='\033[0;33m'
 | |
| RED='\033[0;31m'
 | |
| NC='\033[0m' # No Color
 | |
| 
 | |
| # Default settings
 | |
| ACTION=""
 | |
| TEST_SUITE="default"
 | |
| CURRENT_DATE=$(date +"%Y-%m-%d")
 | |
| 
 | |
| # Parse arguments
 | |
| for arg in "$@"; do
 | |
|   case $arg in
 | |
|     generate|verify|cleanup|backup|restore)
 | |
|       ACTION="$arg"
 | |
|       shift
 | |
|       ;;
 | |
|     --suite=*)
 | |
|       TEST_SUITE="${arg#*=}"
 | |
|       shift
 | |
|       ;;
 | |
|   esac
 | |
| done
 | |
| 
 | |
| # Check if action is provided
 | |
| if [ -z "$ACTION" ]; then
 | |
|   echo -e "${RED}Error: No action specified. Use: generate, verify, cleanup, backup, or restore${NC}"
 | |
|   exit 1
 | |
| fi
 | |
| 
 | |
| echo -e "${GREEN}=== Test Data Manager - ${ACTION} ===${NC}"
 | |
| echo "Managing test data for suite: ${TEST_SUITE}"
 | |
| 
 | |
| # Check if we're in the right directory
 | |
| if [ ! -d "tests/e2e" ]; then
 | |
|   echo -e "${RED}Error: Please run this script from the wordpress-dev directory${NC}"
 | |
|   exit 1
 | |
| fi
 | |
| 
 | |
| # Create test data directory structure
 | |
| mkdir -p tests/e2e/data
 | |
| mkdir -p tests/e2e/data/backups
 | |
| 
 | |
| # Function to generate test data
 | |
| generate_test_data() {
 | |
|   echo -e "\n${YELLOW}Generating test data for suite: ${TEST_SUITE}${NC}"
 | |
|   
 | |
|   # Create test users first
 | |
|   generate_test_users
 | |
|   
 | |
|   # Create test events based on the suite
 | |
|   case $TEST_SUITE in
 | |
|     "certificate")
 | |
|       generate_certificate_test_data
 | |
|       ;;
 | |
|     "dashboard")
 | |
|       generate_dashboard_test_data
 | |
|       ;;
 | |
|     "login")
 | |
|       # Login suite only needs users, which are already created
 | |
|       echo -e "${GREEN}Login test data created successfully${NC}"
 | |
|       ;;
 | |
|     *)
 | |
|       # Default suite includes all test data
 | |
|       generate_certificate_test_data
 | |
|       generate_dashboard_test_data
 | |
|       echo -e "${GREEN}Default test data created successfully${NC}"
 | |
|       ;;
 | |
|   esac
 | |
| }
 | |
| 
 | |
| # Function to generate test users
 | |
| generate_test_users() {
 | |
|   echo -e "${YELLOW}Generating test users...${NC}"
 | |
|   
 | |
|   # Create test users TypeScript file
 | |
|   cat > "tests/e2e/data/test-users.ts" << 'EOF'
 | |
| /**
 | |
|  * Test users for E2E testing
 | |
|  */
 | |
| export const TEST_USERS = {
 | |
|   trainer: {
 | |
|     username: 'test_trainer',
 | |
|     password: 'Test123!',
 | |
|     email: 'test_trainer@example.com',
 | |
|     role: 'trainer'
 | |
|   },
 | |
|   admin: {
 | |
|     username: 'admin_trainer',
 | |
|     password: 'Admin123!',
 | |
|     email: 'admin_trainer@example.com',
 | |
|     role: 'administrator'
 | |
|   },
 | |
|   pending: {
 | |
|     username: 'pending_trainer',
 | |
|     password: 'Pending123!',
 | |
|     email: 'pending_trainer@example.com',
 | |
|     role: 'pending'
 | |
|   }
 | |
| };
 | |
| EOF
 | |
|   
 | |
|   echo -e "${GREEN}Test users created in tests/e2e/data/test-users.ts${NC}"
 | |
|   
 | |
|   # Create shell script to create these users on the server
 | |
|   cat > "bin/create-test-users.sh" << 'EOF'
 | |
| #!/bin/bash
 | |
| # Create test users for E2E testing
 | |
| 
 | |
| # Create test_trainer user
 | |
| ssh user@staging-server "cd /path/to/wordpress && wp user create test_trainer test_trainer@example.com --role=subscriber --user_pass=Test123! || wp user update test_trainer --role=subscriber --user_pass=Test123!"
 | |
| 
 | |
| # Add trainer role
 | |
| ssh user@staging-server "cd /path/to/wordpress && wp user meta update test_trainer wp_capabilities '{\"subscriber\":true,\"trainer\":true}'"
 | |
| 
 | |
| # Create admin_trainer user
 | |
| ssh user@staging-server "cd /path/to/wordpress && wp user create admin_trainer admin_trainer@example.com --role=administrator --user_pass=Admin123! || wp user update admin_trainer --role=administrator --user_pass=Admin123!"
 | |
| 
 | |
| # Create pending_trainer user
 | |
| ssh user@staging-server "cd /path/to/wordpress && wp user create pending_trainer pending_trainer@example.com --role=subscriber --user_pass=Pending123! || wp user update pending_trainer --role=subscriber --user_pass=Pending123!"
 | |
| 
 | |
| # Add pending role
 | |
| ssh user@staging-server "cd /path/to/wordpress && wp user meta update pending_trainer wp_capabilities '{\"subscriber\":true,\"pending_trainer\":true}'"
 | |
| 
 | |
| echo "Test users created/updated successfully"
 | |
| EOF
 | |
|   
 | |
|   chmod +x bin/create-test-users.sh
 | |
|   echo -e "${YELLOW}Created bin/create-test-users.sh - Update SSH credentials before using${NC}"
 | |
| }
 | |
| 
 | |
| # Function to generate certificate test data
 | |
| generate_certificate_test_data() {
 | |
|   echo -e "${YELLOW}Generating certificate test data...${NC}"
 | |
|   
 | |
|   # Create test events TypeScript file with attendees for certificate testing
 | |
|   cat > "tests/e2e/data/test-events.ts" << 'EOF'
 | |
| /**
 | |
|  * Test events for E2E testing
 | |
|  * Includes event data specifically designed for certificate testing
 | |
|  */
 | |
| export const TEST_EVENTS = {
 | |
|   basicEvent: {
 | |
|     title: 'Basic HVAC Training',
 | |
|     description: 'A basic training event for HVAC technicians.',
 | |
|     venue: 'Test Venue',
 | |
|     organizer: 'Test Organizer',
 | |
|     startDate: getTomorrowDate(),
 | |
|     endDate: getTomorrowDate(),
 | |
|     startTime: '09:00',
 | |
|     endTime: '17:00',
 | |
|     cost: '99.99',
 | |
|     capacity: '25'
 | |
|   },
 | |
|   certificateEvent: {
 | |
|     title: 'Certificate Training Course',
 | |
|     description: 'A training event that issues certificates upon completion.',
 | |
|     venue: 'Certificate Test Venue',
 | |
|     organizer: 'Certificate Test Organizer',
 | |
|     startDate: getYesterdayDate(), // Past event for certificate generation
 | |
|     endDate: getYesterdayDate(),
 | |
|     startTime: '08:00',
 | |
|     endTime: '16:00',
 | |
|     cost: '149.99',
 | |
|     capacity: '20',
 | |
|     issueCertificates: true
 | |
|   },
 | |
|   multiDayEvent: {
 | |
|     title: 'Advanced HVAC Workshop',
 | |
|     description: 'A multi-day workshop covering advanced HVAC topics.',
 | |
|     venue: 'Advanced Test Venue',
 | |
|     organizer: 'Advanced Test Organizer',
 | |
|     startDate: getTomorrowDate(),
 | |
|     endDate: getFutureDateDays(3), // 3 days in the future
 | |
|     startTime: '09:00',
 | |
|     endTime: '17:00',
 | |
|     cost: '299.99',
 | |
|     capacity: '15'
 | |
|   }
 | |
| };
 | |
| 
 | |
| // Test attendees for certificate testing
 | |
| export const TEST_ATTENDEES = {
 | |
|   complete: {
 | |
|     firstName: 'John',
 | |
|     lastName: 'Smith',
 | |
|     email: 'john.smith@example.com',
 | |
|     company: 'HVAC Testing Inc.',
 | |
|     checkedIn: true
 | |
|   },
 | |
|   notCheckedIn: {
 | |
|     firstName: 'Jane',
 | |
|     lastName: 'Doe',
 | |
|     email: 'jane.doe@example.com',
 | |
|     company: 'HVAC Services',
 | |
|     checkedIn: false
 | |
|   },
 | |
|   specialChars: {
 | |
|     firstName: 'Jörg',
 | |
|     lastName: "O'Neill-Müller",
 | |
|     email: 'jorg.oneill@example.com',
 | |
|     company: 'Special HVAC & Co.',
 | |
|     checkedIn: true
 | |
|   }
 | |
| };
 | |
| 
 | |
| // Helper functions for dates
 | |
| function getTomorrowDate() {
 | |
|   const tomorrow = new Date();
 | |
|   tomorrow.setDate(tomorrow.getDate() + 1);
 | |
|   return formatDate(tomorrow);
 | |
| }
 | |
| 
 | |
| function getYesterdayDate() {
 | |
|   const yesterday = new Date();
 | |
|   yesterday.setDate(yesterday.getDate() - 1);
 | |
|   return formatDate(yesterday);
 | |
| }
 | |
| 
 | |
| function getFutureDateDays(days) {
 | |
|   const future = new Date();
 | |
|   future.setDate(future.getDate() + days);
 | |
|   return formatDate(future);
 | |
| }
 | |
| 
 | |
| function formatDate(date) {
 | |
|   return date.toISOString().split('T')[0]; // YYYY-MM-DD format
 | |
| }
 | |
| EOF
 | |
|   
 | |
|   echo -e "${GREEN}Certificate test data created in tests/e2e/data/test-events.ts${NC}"
 | |
|   
 | |
|   # Create shell script to create these events on the server
 | |
|   cat > "bin/create-test-data-with-checkins.sh" << 'EOF'
 | |
| #!/bin/bash
 | |
| # Create test events and attendees for certificate testing
 | |
| 
 | |
| # Create the certificate test event
 | |
| ssh user@staging-server "cd /path/to/wordpress && wp post create --post_type=tribe_events --post_title='Certificate Training Course' --post_content='A training event that issues certificates upon completion.' --post_status=publish --meta_input='{\"_EventStartDate\":\"$(date -d \"yesterday\" +\"%Y-%m-%d 08:00:00\")\",\"_EventEndDate\":\"$(date -d \"yesterday\" +\"%Y-%m-%d 16:00:00\")\",\"_EventVenue\":\"Certificate Test Venue\",\"_EventCost\":\"149.99\",\"_tribe_events_issue_certificates\":\"1\"}' --porcelain"
 | |
| 
 | |
| # Get the event ID
 | |
| EVENT_ID=$(ssh user@staging-server "cd /path/to/wordpress && wp post list --post_type=tribe_events --post_status=publish --posts_per_page=1 --post_title='Certificate Training Course' --field=ID")
 | |
| 
 | |
| # Create attendees
 | |
| ATTENDEE1_ID=$(ssh user@staging-server "cd /path/to/wordpress && wp post create --post_type=tribe_attendee --post_title='John Smith' --post_status=publish --meta_input='{\"_tribe_tickets_first_name\":\"John\",\"_tribe_tickets_last_name\":\"Smith\",\"_tribe_tickets_email\":\"john.smith@example.com\",\"_tribe_tickets_checkin\":\"1\",\"_tribe_rsvp_event\":\"$EVENT_ID\",\"_tribe_tickets_attendee_company\":\"HVAC Testing Inc.\"}' --porcelain")
 | |
| 
 | |
| ATTENDEE2_ID=$(ssh user@staging-server "cd /path/to/wordpress && wp post create --post_type=tribe_attendee --post_title='Jane Doe' --post_status=publish --meta_input='{\"_tribe_tickets_first_name\":\"Jane\",\"_tribe_tickets_last_name\":\"Doe\",\"_tribe_tickets_email\":\"jane.doe@example.com\",\"_tribe_tickets_checkin\":\"0\",\"_tribe_rsvp_event\":\"$EVENT_ID\",\"_tribe_tickets_attendee_company\":\"HVAC Services\"}' --porcelain")
 | |
| 
 | |
| ATTENDEE3_ID=$(ssh user@staging-server "cd /path/to/wordpress && wp post create --post_type=tribe_attendee --post_title='Jörg O'Neill-Müller' --post_status=publish --meta_input='{\"_tribe_tickets_first_name\":\"Jörg\",\"_tribe_tickets_last_name\":\"O'Neill-Müller\",\"_tribe_tickets_email\":\"jorg.oneill@example.com\",\"_tribe_tickets_checkin\":\"1\",\"_tribe_rsvp_event\":\"$EVENT_ID\",\"_tribe_tickets_attendee_company\":\"Special HVAC & Co.\"}' --porcelain")
 | |
| 
 | |
| echo "Certificate test data created successfully"
 | |
| echo "Event ID: $EVENT_ID"
 | |
| echo "Attendees: $ATTENDEE1_ID, $ATTENDEE2_ID, $ATTENDEE3_ID"
 | |
| EOF
 | |
|   
 | |
|   chmod +x bin/create-test-data-with-checkins.sh
 | |
|   echo -e "${YELLOW}Created bin/create-test-data-with-checkins.sh - Update SSH credentials before using${NC}"
 | |
| }
 | |
| 
 | |
| # Function to generate dashboard test data
 | |
| generate_dashboard_test_data() {
 | |
|   echo -e "${YELLOW}Generating dashboard test data...${NC}"
 | |
|   
 | |
|   # Create additional test events for dashboard testing
 | |
|   cat > "bin/create-test-events-admin.sh" << 'EOF'
 | |
| #!/bin/bash
 | |
| # Create test events for dashboard testing
 | |
| 
 | |
| # Create multiple events with different statuses
 | |
| ssh user@staging-server "cd /path/to/wordpress && wp post create --post_type=tribe_events --post_title='Published HVAC Training' --post_content='A published training event for dashboard testing.' --post_status=publish --meta_input='{\"_EventStartDate\":\"$(date -d \"+5 days\" +\"%Y-%m-%d 09:00:00\")\",\"_EventEndDate\":\"$(date -d \"+5 days\" +\"%Y-%m-%d 17:00:00\")\",\"_EventVenue\":\"Dashboard Test Venue\",\"_EventCost\":\"99.99\"}' --porcelain"
 | |
| 
 | |
| ssh user@staging-server "cd /path/to/wordpress && wp post create --post_type=tribe_events --post_title='Draft HVAC Training' --post_content='A draft training event for dashboard testing.' --post_status=draft --meta_input='{\"_EventStartDate\":\"$(date -d \"+7 days\" +\"%Y-%m-%d 09:00:00\")\",\"_EventEndDate\":\"$(date -d \"+7 days\" +\"%Y-%m-%d 17:00:00\")\",\"_EventVenue\":\"Dashboard Test Venue\",\"_EventCost\":\"79.99\"}' --porcelain"
 | |
| 
 | |
| ssh user@staging-server "cd /path/to/wordpress && wp post create --post_type=tribe_events --post_title='Private HVAC Training' --post_content='A private training event for dashboard testing.' --post_status=private --meta_input='{\"_EventStartDate\":\"$(date -d \"+10 days\" +\"%Y-%m-%d 09:00:00\")\",\"_EventEndDate\":\"$(date -d \"+10 days\" +\"%Y-%m-%d 17:00:00\")\",\"_EventVenue\":\"Dashboard Test Venue\",\"_EventCost\":\"129.99\"}' --porcelain"
 | |
| 
 | |
| ssh user@staging-server "cd /path/to/wordpress && wp post create --post_type=tribe_events --post_title='Pending HVAC Training' --post_content='A pending training event for dashboard testing.' --post_status=pending --meta_input='{\"_EventStartDate\":\"$(date -d \"+15 days\" +\"%Y-%m-%d 09:00:00\")\",\"_EventEndDate\":\"$(date -d \"+15 days\" +\"%Y-%m-%d 17:00:00\")\",\"_EventVenue\":\"Dashboard Test Venue\",\"_EventCost\":\"149.99\"}' --porcelain"
 | |
| 
 | |
| # Create a past event
 | |
| ssh user@staging-server "cd /path/to/wordpress && wp post create --post_type=tribe_events --post_title='Past HVAC Training' --post_content='A past training event for dashboard testing.' --post_status=publish --meta_input='{\"_EventStartDate\":\"$(date -d \"-3 days\" +\"%Y-%m-%d 09:00:00\")\",\"_EventEndDate\":\"$(date -d \"-3 days\" +\"%Y-%m-%d 17:00:00\")\",\"_EventVenue\":\"Dashboard Test Venue\",\"_EventCost\":\"99.99\"}' --porcelain"
 | |
| 
 | |
| echo "Dashboard test events created successfully"
 | |
| EOF
 | |
|   
 | |
|   chmod +x bin/create-test-events-admin.sh
 | |
|   echo -e "${YELLOW}Created bin/create-test-events-admin.sh - Update SSH credentials before using${NC}"
 | |
| }
 | |
| 
 | |
| # Function to verify test data
 | |
| verify_test_data() {
 | |
|   echo -e "\n${YELLOW}Verifying test data for suite: ${TEST_SUITE}${NC}"
 | |
|   
 | |
|   # Verify test user files exist
 | |
|   if [ -f "tests/e2e/data/test-users.ts" ]; then
 | |
|     echo -e "${GREEN}✓ Test users file exists${NC}"
 | |
|   else
 | |
|     echo -e "${RED}✗ Test users file missing${NC}"
 | |
|   fi
 | |
|   
 | |
|   # Verify test events files exist
 | |
|   if [ -f "tests/e2e/data/test-events.ts" ]; then
 | |
|     echo -e "${GREEN}✓ Test events file exists${NC}"
 | |
|   else
 | |
|     echo -e "${RED}✗ Test events file missing${NC}"
 | |
|   fi
 | |
|   
 | |
|   # Verify test data on server (if scripts exist)
 | |
|   if [ -f "bin/verify-test-data.sh" ]; then
 | |
|     echo -e "${YELLOW}Running server-side test data verification...${NC}"
 | |
|     bash bin/verify-test-data.sh
 | |
|   else
 | |
|     echo -e "${YELLOW}Creating server-side verification script...${NC}"
 | |
|     
 | |
|     # Create verification script
 | |
|     cat > "bin/verify-test-data.sh" << 'EOF'
 | |
| #!/bin/bash
 | |
| # Verify test data exists on the server
 | |
| 
 | |
| # Check test users
 | |
| echo "Verifying test users..."
 | |
| TEST_TRAINER=$(ssh user@staging-server "cd /path/to/wordpress && wp user get test_trainer --field=ID 2>/dev/null || echo 'missing'")
 | |
| ADMIN_TRAINER=$(ssh user@staging-server "cd /path/to/wordpress && wp user get admin_trainer --field=ID 2>/dev/null || echo 'missing'")
 | |
| PENDING_TRAINER=$(ssh user@staging-server "cd /path/to/wordpress && wp user get pending_trainer --field=ID 2>/dev/null || echo 'missing'")
 | |
| 
 | |
| if [ "$TEST_TRAINER" != "missing" ] && [ "$ADMIN_TRAINER" != "missing" ]; then
 | |
|   echo "✓ Test users verified"
 | |
| else
 | |
|   echo "✗ Test users missing"
 | |
|   echo "  - test_trainer: ${TEST_TRAINER}"
 | |
|   echo "  - admin_trainer: ${ADMIN_TRAINER}"
 | |
|   echo "  - pending_trainer: ${PENDING_TRAINER}"
 | |
| fi
 | |
| 
 | |
| # Check test events
 | |
| echo "Verifying test events..."
 | |
| CERTIFICATE_EVENT=$(ssh user@staging-server "cd /path/to/wordpress && wp post list --post_type=tribe_events --post_status=publish --posts_per_page=1 --post_title='Certificate Training Course' --field=ID 2>/dev/null || echo 'missing'")
 | |
| DASHBOARD_EVENTS=$(ssh user@staging-server "cd /path/to/wordpress && wp post list --post_type=tribe_events --field=ID | wc -l 2>/dev/null || echo '0'")
 | |
| 
 | |
| if [ "$CERTIFICATE_EVENT" != "missing" ] && [ "$DASHBOARD_EVENTS" -gt 0 ]; then
 | |
|   echo "✓ Test events verified"
 | |
|   echo "  - Certificate event: ${CERTIFICATE_EVENT}"
 | |
|   echo "  - Total events: ${DASHBOARD_EVENTS}"
 | |
| else
 | |
|   echo "✗ Test events missing"
 | |
|   echo "  - Certificate event: ${CERTIFICATE_EVENT}"
 | |
|   echo "  - Total events: ${DASHBOARD_EVENTS}"
 | |
| fi
 | |
| 
 | |
| # Check attendees
 | |
| echo "Verifying test attendees..."
 | |
| if [ "$CERTIFICATE_EVENT" != "missing" ]; then
 | |
|   ATTENDEES=$(ssh user@staging-server "cd /path/to/wordpress && wp post list --post_type=tribe_attendee --meta_key=_tribe_rsvp_event --meta_value=${CERTIFICATE_EVENT} --field=ID 2>/dev/null | wc -l || echo '0'")
 | |
|   
 | |
|   if [ "$ATTENDEES" -gt 0 ]; then
 | |
|     echo "✓ Test attendees verified: ${ATTENDEES} attendees found"
 | |
|   else
 | |
|     echo "✗ Test attendees missing for certificate event"
 | |
|   fi
 | |
| fi
 | |
| 
 | |
| echo "Test data verification complete"
 | |
| EOF
 | |
|     
 | |
|     chmod +x bin/verify-test-data.sh
 | |
|     echo -e "${YELLOW}Created bin/verify-test-data.sh - Update SSH credentials before using${NC}"
 | |
|   fi
 | |
| }
 | |
| 
 | |
| # Function to cleanup test data
 | |
| cleanup_test_data() {
 | |
|   echo -e "\n${YELLOW}Cleaning up test data for suite: ${TEST_SUITE}${NC}"
 | |
|   
 | |
|   # Check if cleanup script exists
 | |
|   if [ -f "bin/cleanup-test-data.sh" ]; then
 | |
|     echo -e "${YELLOW}Running test data cleanup...${NC}"
 | |
|     bash bin/cleanup-test-data.sh
 | |
|   else
 | |
|     echo -e "${YELLOW}Creating cleanup script...${NC}"
 | |
|     
 | |
|     # Create cleanup script
 | |
|     cat > "bin/cleanup-test-data.sh" << 'EOF'
 | |
| #!/bin/bash
 | |
| # Clean up test data from the server
 | |
| 
 | |
| echo "Cleaning up test data..."
 | |
| 
 | |
| # Clean up test events
 | |
| echo "Removing test events..."
 | |
| ssh user@staging-server "cd /path/to/wordpress && wp post delete \$(wp post list --post_type=tribe_events --post_title='Certificate Training Course' --field=ID) --force 2>/dev/null || echo 'No certificate event to remove'"
 | |
| ssh user@staging-server "cd /path/to/wordpress && wp post delete \$(wp post list --post_type=tribe_events --post_title='Published HVAC Training' --field=ID) --force 2>/dev/null || echo 'No published event to remove'"
 | |
| ssh user@staging-server "cd /path/to/wordpress && wp post delete \$(wp post list --post_type=tribe_events --post_title='Draft HVAC Training' --field=ID) --force 2>/dev/null || echo 'No draft event to remove'"
 | |
| ssh user@staging-server "cd /path/to/wordpress && wp post delete \$(wp post list --post_type=tribe_events --post_title='Private HVAC Training' --field=ID) --force 2>/dev/null || echo 'No private event to remove'"
 | |
| ssh user@staging-server "cd /path/to/wordpress && wp post delete \$(wp post list --post_type=tribe_events --post_title='Pending HVAC Training' --field=ID) --force 2>/dev/null || echo 'No pending event to remove'"
 | |
| ssh user@staging-server "cd /path/to/wordpress && wp post delete \$(wp post list --post_type=tribe_events --post_title='Past HVAC Training' --field=ID) --force 2>/dev/null || echo 'No past event to remove'"
 | |
| 
 | |
| # Clean up attendees - remove all test attendees 
 | |
| echo "Removing test attendees..."
 | |
| ssh user@staging-server "cd /path/to/wordpress && wp post delete \$(wp post list --post_type=tribe_attendee --meta_key=_tribe_tickets_email --meta_value='john.smith@example.com' --field=ID) --force 2>/dev/null || echo 'No John Smith attendee to remove'"
 | |
| ssh user@staging-server "cd /path/to/wordpress && wp post delete \$(wp post list --post_type=tribe_attendee --meta_key=_tribe_tickets_email --meta_value='jane.doe@example.com' --field=ID) --force 2>/dev/null || echo 'No Jane Doe attendee to remove'"
 | |
| ssh user@staging-server "cd /path/to/wordpress && wp post delete \$(wp post list --post_type=tribe_attendee --meta_key=_tribe_tickets_email --meta_value='jorg.oneill@example.com' --field=ID) --force 2>/dev/null || echo 'No Jorg attendee to remove'"
 | |
| 
 | |
| # Keep test users (just reset their data)
 | |
| echo "Resetting test users..."
 | |
| ssh user@staging-server "cd /path/to/wordpress && wp user meta delete test_trainer hvac_test_data 2>/dev/null || echo 'No test data to remove for test_trainer'"
 | |
| ssh user@staging-server "cd /path/to/wordpress && wp user meta delete admin_trainer hvac_test_data 2>/dev/null || echo 'No test data to remove for admin_trainer'"
 | |
| ssh user@staging-server "cd /path/to/wordpress && wp user meta delete pending_trainer hvac_test_data 2>/dev/null || echo 'No test data to remove for pending_trainer'"
 | |
| 
 | |
| echo "Test data cleanup complete"
 | |
| EOF
 | |
|     
 | |
|     chmod +x bin/cleanup-test-data.sh
 | |
|     echo -e "${YELLOW}Created bin/cleanup-test-data.sh - Update SSH credentials before using${NC}"
 | |
|   fi
 | |
| }
 | |
| 
 | |
| # Function to backup test data
 | |
| backup_test_data() {
 | |
|   echo -e "\n${YELLOW}Backing up test data for suite: ${TEST_SUITE}${NC}"
 | |
|   
 | |
|   # Create backup directory
 | |
|   BACKUP_DIR="tests/e2e/data/backups/${CURRENT_DATE}_${TEST_SUITE}"
 | |
|   mkdir -p "$BACKUP_DIR"
 | |
|   
 | |
|   # Backup test user data
 | |
|   if [ -f "tests/e2e/data/test-users.ts" ]; then
 | |
|     cp "tests/e2e/data/test-users.ts" "$BACKUP_DIR/"
 | |
|     echo -e "${GREEN}✓ Test users backed up${NC}"
 | |
|   fi
 | |
|   
 | |
|   # Backup test event data
 | |
|   if [ -f "tests/e2e/data/test-events.ts" ]; then
 | |
|     cp "tests/e2e/data/test-events.ts" "$BACKUP_DIR/"
 | |
|     echo -e "${GREEN}✓ Test events backed up${NC}"
 | |
|   fi
 | |
|   
 | |
|   # Backup any other test data files
 | |
|   if [ -f "tests/e2e/data/test-config.ts" ]; then
 | |
|     cp "tests/e2e/data/test-config.ts" "$BACKUP_DIR/"
 | |
|     echo -e "${GREEN}✓ Test config backed up${NC}"
 | |
|   fi
 | |
|   
 | |
|   # Compress backup
 | |
|   tar -czf "$BACKUP_DIR.tar.gz" "$BACKUP_DIR"
 | |
|   echo -e "${GREEN}Backup created: ${BACKUP_DIR}.tar.gz${NC}"
 | |
|   
 | |
|   # Remove uncompressed backup
 | |
|   rm -rf "$BACKUP_DIR"
 | |
| }
 | |
| 
 | |
| # Function to restore test data
 | |
| restore_test_data() {
 | |
|   echo -e "\n${YELLOW}Restoring test data for suite: ${TEST_SUITE}${NC}"
 | |
|   
 | |
|   # Find most recent backup for the suite
 | |
|   LATEST_BACKUP=$(ls -t tests/e2e/data/backups/*_${TEST_SUITE}.tar.gz 2>/dev/null | head -1)
 | |
|   
 | |
|   if [ -z "$LATEST_BACKUP" ]; then
 | |
|     echo -e "${RED}No backup found for suite: ${TEST_SUITE}${NC}"
 | |
|     return 1
 | |
|   fi
 | |
|   
 | |
|   echo -e "${YELLOW}Restoring from backup: ${LATEST_BACKUP}${NC}"
 | |
|   
 | |
|   # Create temp directory
 | |
|   TEMP_DIR="tests/e2e/data/temp_restore"
 | |
|   mkdir -p "$TEMP_DIR"
 | |
|   
 | |
|   # Extract backup
 | |
|   tar -xzf "$LATEST_BACKUP" -C "$TEMP_DIR"
 | |
|   
 | |
|   # Find extracted directory
 | |
|   EXTRACTED_DIR=$(find "$TEMP_DIR" -type d -depth 1)
 | |
|   
 | |
|   # Restore files
 | |
|   if [ -f "$EXTRACTED_DIR/test-users.ts" ]; then
 | |
|     cp "$EXTRACTED_DIR/test-users.ts" "tests/e2e/data/"
 | |
|     echo -e "${GREEN}✓ Test users restored${NC}"
 | |
|   fi
 | |
|   
 | |
|   if [ -f "$EXTRACTED_DIR/test-events.ts" ]; then
 | |
|     cp "$EXTRACTED_DIR/test-events.ts" "tests/e2e/data/"
 | |
|     echo -e "${GREEN}✓ Test events restored${NC}"
 | |
|   fi
 | |
|   
 | |
|   if [ -f "$EXTRACTED_DIR/test-config.ts" ]; then
 | |
|     cp "$EXTRACTED_DIR/test-config.ts" "tests/e2e/data/"
 | |
|     echo -e "${GREEN}✓ Test config restored${NC}"
 | |
|   fi
 | |
|   
 | |
|   # Clean up
 | |
|   rm -rf "$TEMP_DIR"
 | |
|   echo -e "${GREEN}Restore completed from: ${LATEST_BACKUP}${NC}"
 | |
| }
 | |
| 
 | |
| # Execute action
 | |
| case $ACTION in
 | |
|   "generate")
 | |
|     generate_test_data
 | |
|     ;;
 | |
|   "verify")
 | |
|     verify_test_data
 | |
|     ;;
 | |
|   "cleanup")
 | |
|     cleanup_test_data
 | |
|     ;;
 | |
|   "backup")
 | |
|     backup_test_data
 | |
|     ;;
 | |
|   "restore")
 | |
|     restore_test_data
 | |
|     ;;
 | |
|   *)
 | |
|     echo -e "${RED}Invalid action: ${ACTION}${NC}"
 | |
|     exit 1
 | |
|     ;;
 | |
| esac
 | |
| 
 | |
| echo -e "\n${GREEN}=== Test Data Manager Complete ===${NC}"
 | |
| echo "Action '${ACTION}' completed for suite: ${TEST_SUITE}"
 | |
| exit 0 |