From 7ac4d4b853ff3094268feb55b669f506d825c7bd Mon Sep 17 00:00:00 2001 From: bengizmo Date: Wed, 21 May 2025 20:12:38 -0300 Subject: [PATCH] feat: Add test user creation and plugin verification scripts --- wordpress-dev/bin/create-test-events-admin.sh | 122 ++++++++++++++++++ wordpress-dev/bin/create-test-users.sh | 90 +++++++++++++ .../tests/e2e/verify-plugin-status.test.ts | 113 ++++++++++++++++ 3 files changed, 325 insertions(+) create mode 100755 wordpress-dev/bin/create-test-events-admin.sh create mode 100755 wordpress-dev/bin/create-test-users.sh create mode 100644 wordpress-dev/tests/e2e/verify-plugin-status.test.ts diff --git a/wordpress-dev/bin/create-test-events-admin.sh b/wordpress-dev/bin/create-test-events-admin.sh new file mode 100755 index 00000000..53dc9527 --- /dev/null +++ b/wordpress-dev/bin/create-test-events-admin.sh @@ -0,0 +1,122 @@ +#!/bin/bash + +# Load environment variables +if [ -f "./.env" ]; then + source ./.env +else + echo "Error: .env file not found!" + exit 1 +fi + +# Configuration +SSH_USER="${UPSKILL_STAGING_SSH_USER}" +SSH_HOST="${UPSKILL_STAGING_IP}" +SSH_PASS="${UPSKILL_STAGING_PASS}" +SITE_PATH="${UPSKILL_STAGING_PATH:-/home/974670.cloudwaysapps.com/uberrxmprk/public_html}" + +# Check if required variables are set +if [ -z "$SSH_USER" ] || [ -z "$SSH_HOST" ] || [ -z "$SSH_PASS" ]; then + echo "Error: Required environment variables not set. Please check your .env file." + exit 1 +fi + +# Create a test event for the test_trainer user +echo "=== Creating test event for test_trainer ===" +sshpass -p "$SSH_PASS" ssh -o StrictHostKeyChecking=no "$SSH_USER@$SSH_HOST" "cd $SITE_PATH && wp post create --post_type=tribe_events --post_title='HVAC Training Workshop' --post_content='This is a test event for HVAC training.' --post_status=publish --post_author=18 --meta_input='{\"_EventStartDate\":\"$(date -v+1d "+%Y-%m-%d 10:00:00")\",\"_EventEndDate\":\"$(date -v+1d "+%Y-%m-%d 16:00:00")\",\"_EventVenueID\":\"auto\",\"_EventURL\":\"https://upskill-staging.measurequick.com\",\"_EventCurrencySymbol\":\"$\",\"_EventCurrencyPosition\":\"prefix\",\"_EventCost\":\"99.99\",\"_EventTimezone\":\"America/New_York\"}'" + +# Create another event with a different date +echo "=== Creating second test event for test_trainer ===" +sshpass -p "$SSH_PASS" ssh -o StrictHostKeyChecking=no "$SSH_USER@$SSH_HOST" "cd $SITE_PATH && wp post create --post_type=tribe_events --post_title='Advanced HVAC Certification' --post_content='An advanced certification course for HVAC professionals.' --post_status=publish --post_author=18 --meta_input='{\"_EventStartDate\":\"$(date -v+7d "+%Y-%m-%d 09:00:00")\",\"_EventEndDate\":\"$(date -v+8d "+%Y-%m-%d 17:00:00")\",\"_EventVenueID\":\"auto\",\"_EventURL\":\"https://upskill-staging.measurequick.com\",\"_EventCurrencySymbol\":\"$\",\"_EventCurrencyPosition\":\"prefix\",\"_EventCost\":\"299.99\",\"_EventTimezone\":\"America/New_York\"}'" + +# Create an event for admin_trainer +echo "=== Creating test event for admin_trainer ===" +sshpass -p "$SSH_PASS" ssh -o StrictHostKeyChecking=no "$SSH_USER@$SSH_HOST" "cd $SITE_PATH && wp post create --post_type=tribe_events --post_title='HVAC Business Management' --post_content='Learn how to manage your HVAC business effectively.' --post_status=publish --post_author=19 --meta_input='{\"_EventStartDate\":\"$(date -v+14d "+%Y-%m-%d 13:00:00")\",\"_EventEndDate\":\"$(date -v+14d "+%Y-%m-%d 17:00:00")\",\"_EventVenueID\":\"auto\",\"_EventURL\":\"https://upskill-staging.measurequick.com\",\"_EventCurrencySymbol\":\"$\",\"_EventCurrencyPosition\":\"prefix\",\"_EventCost\":\"149.99\",\"_EventTimezone\":\"America/New_York\"}'" + +# Create test attendees +echo "=== Creating test attendees for the first event ===" +# We would normally use The Events Calendar's ticket system for this +# For now, we'll create a custom script to simulate attendees + +cat > /tmp/create_attendees.php << 'EOL' + 'tribe_events', + 'author' => 18, + 'posts_per_page' => 1, + 'orderby' => 'date', + 'order' => 'DESC' +)); + +if (empty($events)) { + echo "No events found for test_trainer\n"; + exit(1); +} + +$event_id = $events[0]->ID; +echo "Creating attendees for event: " . $events[0]->post_title . " (ID: $event_id)\n"; + +// Test attendee data +$attendees = array( + array( + 'name' => 'John Smith', + 'email' => 'john.smith@example.com', + 'phone' => '555-123-4567', + 'paid' => 99.99, + 'status' => 'checked-in' + ), + array( + 'name' => 'Jane Doe', + 'email' => 'jane.doe@example.com', + 'phone' => '555-987-6543', + 'paid' => 99.99, + 'status' => 'checked-in' + ), + array( + 'name' => 'Bob Johnson', + 'email' => 'bob.johnson@example.com', + 'phone' => '555-456-7890', + 'paid' => 99.99, + 'status' => 'not-checked-in' + ) +); + +// Create attendees (this is a simplified example - actual implementation depends on The Events Calendar) +foreach ($attendees as $attendee_data) { + // Check if we need to integrate with a specific ticket system + // For now, we'll just create custom post meta to simulate attendees + + // Create a unique ID for this attendee + $attendee_id = 'test_' . md5($attendee_data['email'] . time()); + + // Add attendee to event (simplified approach) + add_post_meta($event_id, '_tribe_attendee_' . $attendee_id, array( + 'name' => $attendee_data['name'], + 'email' => $attendee_data['email'], + 'phone' => $attendee_data['phone'], + 'paid' => $attendee_data['paid'], + 'status' => $attendee_data['status'], + 'created' => current_time('mysql') + )); + + echo "Created attendee: " . $attendee_data['name'] . "\n"; +} + +// Update attendee count in event meta +$attendee_count = count($attendees); +update_post_meta($event_id, '_tribe_attendee_count', $attendee_count); +echo "Updated attendee count to $attendee_count\n"; + +echo "Done creating test attendees\n"; +EOL + +# Upload and run the PHP script +sshpass -p "$SSH_PASS" scp -o StrictHostKeyChecking=no /tmp/create_attendees.php "$SSH_USER@$SSH_HOST:$SITE_PATH/create_attendees.php" +sshpass -p "$SSH_PASS" ssh -o StrictHostKeyChecking=no "$SSH_USER@$SSH_HOST" "cd $SITE_PATH && php create_attendees.php" +sshpass -p "$SSH_PASS" ssh -o StrictHostKeyChecking=no "$SSH_USER@$SSH_HOST" "cd $SITE_PATH && rm create_attendees.php" + +echo "=== Test events and attendees created successfully ===" +echo "You can view these events on the HVAC dashboard or in the WordPress admin" \ No newline at end of file diff --git a/wordpress-dev/bin/create-test-users.sh b/wordpress-dev/bin/create-test-users.sh new file mode 100755 index 00000000..574c0dbf --- /dev/null +++ b/wordpress-dev/bin/create-test-users.sh @@ -0,0 +1,90 @@ +#!/bin/bash + +# Load environment variables +if [ -f "./.env" ]; then + source ./.env +else + echo "Error: .env file not found!" + exit 1 +fi + +# Configuration +SSH_USER="${UPSKILL_STAGING_SSH_USER}" +SSH_HOST="${UPSKILL_STAGING_IP}" +SSH_PASS="${UPSKILL_STAGING_PASS}" +SITE_PATH="${UPSKILL_STAGING_PATH:-/home/974670.cloudwaysapps.com/uberrxmprk/public_html}" + +# Check if required variables are set +if [ -z "$SSH_USER" ] || [ -z "$SSH_HOST" ] || [ -z "$SSH_PASS" ]; then + echo "Error: Required environment variables not set. Please check your .env file." + exit 1 +fi + +# Function to create a user with the trainer role +create_test_user() { + local username=$1 + local email=$2 + local password=$3 + local first_name=$4 + local last_name=$5 + local role=$6 + local business_name=$7 + local business_phone=$8 + local business_email=$9 + + echo "Creating user: $username ($email) with role: $role" + + # Check if user already exists + USER_EXISTS=$(sshpass -p "$SSH_PASS" ssh -o StrictHostKeyChecking=no "$SSH_USER@$SSH_HOST" "cd $SITE_PATH && wp user get $username --field=ID 2>/dev/null || echo ''") + + if [ -n "$USER_EXISTS" ]; then + echo "User $username already exists with ID: $USER_EXISTS" + + # Update user if exists + sshpass -p "$SSH_PASS" ssh -o StrictHostKeyChecking=no "$SSH_USER@$SSH_HOST" "cd $SITE_PATH && wp user update $USER_EXISTS --user_pass='$password' --first_name='$first_name' --last_name='$last_name' --role='$role'" + echo "Updated user password, name, and role" + else + # Create user + USER_ID=$(sshpass -p "$SSH_PASS" ssh -o StrictHostKeyChecking=no "$SSH_USER@$SSH_HOST" "cd $SITE_PATH && wp user create $username $email --user_pass='$password' --first_name='$first_name' --last_name='$last_name' --role='$role' --porcelain") + + if [ -z "$USER_ID" ]; then + echo "Error: Failed to create user $username" + return 1 + fi + + echo "Created user $username with ID: $USER_ID" + fi + + # Add user meta for business details + if [ -n "$business_name" ]; then + sshpass -p "$SSH_PASS" ssh -o StrictHostKeyChecking=no "$SSH_USER@$SSH_HOST" "cd $SITE_PATH && wp user meta update $username business_name '$business_name'" + fi + + if [ -n "$business_phone" ]; then + sshpass -p "$SSH_PASS" ssh -o StrictHostKeyChecking=no "$SSH_USER@$SSH_HOST" "cd $SITE_PATH && wp user meta update $username business_phone '$business_phone'" + fi + + if [ -n "$business_email" ]; then + sshpass -p "$SSH_PASS" ssh -o StrictHostKeyChecking=no "$SSH_USER@$SSH_HOST" "cd $SITE_PATH && wp user meta update $username business_email '$business_email'" + fi + + echo "Updated business details for $username" + return 0 +} + +# Create test_trainer user +echo "=== Creating test trainer user ===" +create_test_user "test_trainer" "test_trainer@example.com" "Test123!" "Test" "Trainer" "hvac_trainer" "Test HVAC Training" "555-0123" "business@testtraining.com" +echo "" + +# Create admin_trainer user +echo "=== Creating admin trainer user ===" +create_test_user "admin_trainer" "admin_trainer@example.com" "Admin123!" "Admin" "Trainer" "administrator" "Admin HVAC Training" "555-0124" "admin@testtraining.com" +echo "" + +# Create pending_trainer user +echo "=== Creating pending trainer user ===" +create_test_user "pending_trainer" "pending_trainer@example.com" "Pending123!" "Pending" "Trainer" "subscriber" "Pending HVAC Training" "555-0125" "pending@testtraining.com" +echo "" + +echo "Test users created successfully!" \ No newline at end of file diff --git a/wordpress-dev/tests/e2e/verify-plugin-status.test.ts b/wordpress-dev/tests/e2e/verify-plugin-status.test.ts new file mode 100644 index 00000000..914dd286 --- /dev/null +++ b/wordpress-dev/tests/e2e/verify-plugin-status.test.ts @@ -0,0 +1,113 @@ +import { test, expect } from '@playwright/test'; + +test.describe('Plugin Status Verification', () => { + test('verify HVAC Community Events plugin status on staging', async ({ page }) => { + console.log('Starting plugin status verification...'); + + // First check if we can access the site + await page.goto('https://upskill-staging.measurequick.com/'); + await expect(page).toHaveTitle(/Upskill HVAC/); + console.log('✓ Site is accessible'); + + // Try to access WordPress admin + await page.goto('https://upskill-staging.measurequick.com/wp-admin/'); + + // Check if we're redirected to login + await page.waitForLoadState('networkidle'); + const url = page.url(); + console.log(`Current URL: ${url}`); + + if (url.includes('wp-login')) { + console.log('Need to login to access admin'); + + // Try to login with admin credentials if available + try { + await page.fill('#user_login', 'admin'); + await page.fill('#user_pass', 'admin'); // Common staging password + await page.click('#wp-submit'); + await page.waitForLoadState('networkidle'); + + // Check if login was successful + if (page.url().includes('wp-admin') && !page.url().includes('wp-login')) { + console.log('✓ Successfully logged into admin'); + + // Navigate to plugins page + await page.goto('https://upskill-staging.measurequick.com/wp-admin/plugins.php'); + await page.waitForLoadState('networkidle'); + + // Check for HVAC plugin + const hvacPlugin = page.locator('tr[data-slug="hvac-community-events"], tr:has-text("HVAC Community Events")'); + const pluginExists = await hvacPlugin.count() > 0; + + if (pluginExists) { + console.log('✓ HVAC Community Events plugin found in plugins list'); + + // Check if it's active + const isActive = await page.locator('tr[data-slug="hvac-community-events"] .plugin-title strong, tr:has-text("HVAC Community Events") .plugin-title strong').count() > 0; + console.log(`Plugin active status: ${isActive}`); + + // Get plugin details + const pluginRow = page.locator('tr[data-slug="hvac-community-events"], tr:has-text("HVAC Community Events")').first(); + const pluginText = await pluginRow.textContent(); + console.log(`Plugin details: ${pluginText?.substring(0, 200)}...`); + } else { + console.log('✗ HVAC Community Events plugin NOT found in plugins list'); + + // List all plugins to see what's installed + const allPlugins = await page.locator('#the-list tr .plugin-title strong').allTextContents(); + console.log('Installed plugins:', allPlugins); + } + + // Check if we can access HVAC menu items + const hvacMenu = page.locator('#adminmenu a:has-text("HVAC")'); + const menuExists = await hvacMenu.count() > 0; + console.log(`HVAC admin menu exists: ${menuExists}`); + + } else { + console.log('✗ Login failed or redirected'); + } + } catch (error) { + console.log('Login attempt failed:', error); + } + } + + // Check frontend for plugin indicators + await page.goto('https://upskill-staging.measurequick.com/'); + await page.waitForLoadState('networkidle'); + + // Look for HVAC-specific CSS classes, scripts, or content + const hvacIndicators = { + cssFiles: await page.locator('link[href*="hvac"]').count(), + jsFiles: await page.locator('script[src*="hvac"]').count(), + hvacClasses: await page.locator('[class*="hvac"]').count(), + communityPages: await page.locator('a[href*="community"]').count(), + trainerPages: await page.locator('a[href*="trainer"]').count() + }; + + console.log('Frontend HVAC indicators:', hvacIndicators); + + // Check if community registration page exists + try { + await page.goto('https://upskill-staging.measurequick.com/community-registration/'); + await page.waitForLoadState('networkidle'); + const pageTitle = await page.title(); + const pageExists = !pageTitle.includes('Page not found') && !pageTitle.includes('404'); + console.log(`Community registration page exists: ${pageExists}`); + console.log(`Page title: ${pageTitle}`); + } catch (error) { + console.log('Community registration page not accessible'); + } + + // Check if trainer dashboard exists + try { + await page.goto('https://upskill-staging.measurequick.com/trainer-dashboard/'); + await page.waitForLoadState('networkidle'); + const pageTitle = await page.title(); + const pageExists = !pageTitle.includes('Page not found') && !pageTitle.includes('404'); + console.log(`Trainer dashboard page exists: ${pageExists}`); + console.log(`Page title: ${pageTitle}`); + } catch (error) { + console.log('Trainer dashboard page not accessible'); + } + }); +}); \ No newline at end of file