6.1 KiB
6.1 KiB
Quick Testing Guide - User Management
🧪 How to Test the Fixes
Option 1: Automated Backend Test (Recommended First)
cd /media/pts/Website/SkyArtShop/backend
node test-user-management.js
Expected Output:
🧪 Testing User Management Fixes
==================================================
1️⃣ Checking database schema...
✓ Required columns: name, passwordhash, passwordneverexpires, role, username
2️⃣ Creating test user...
✓ Password hashed with bcrypt (10 rounds)
✓ User created successfully:
- ID: user-test-xxxxx
- Name: Test User
- Username: testuser_xxxxx
- Email: testuser_xxxxx@example.com
- Role: Cashier
- Active: true
3️⃣ Reading user from database...
✓ User retrieved successfully
✓ All fields match
4️⃣ Updating user information...
✓ User updated successfully
✓ New name and role saved
5️⃣ Testing password change...
✓ Password changed successfully
✓ Password verification: PASSED ✓
6️⃣ Verifying password security...
✓ Old password should NOT work: CORRECT ✓
✓ New password works: CORRECT ✓
✅ All tests passed successfully!
Option 2: Web UI Testing
Step 1: Access User Management
- Open browser and go to:
http://localhost:5000/admin/login.html - Login with admin credentials
- Navigate to:
http://localhost:5000/admin/users.html
Step 2: Test Create User
- Click "Create New User" button
- Fill in the form:
- Full Name: John Doe
- Username: johndoe (unique)
- Email: john@example.com (unique)
- Password: SecurePass123 (min 8 chars)
- Confirm Password: SecurePass123
- Role: Cashier
- Active Account: ✓ (checked)
- Click "Save User"
✅ Expected Result:
- Success message appears
- User appears in the list with:
- Name: John Doe
- Email: john@example.com
- Username: @johndoe
- Role badge: Cashier (green)
- Status: Active (green badge)
Step 3: Test Edit Button (THE MAIN FIX!)
- Find the user you just created in the list
- Click the Edit (pencil) button
✅ Expected Result:
- Modal opens with title "Edit User"
- All fields pre-filled with user data:
- Name: John Doe
- Username: johndoe
- Email: john@example.com
- Role: Cashier (selected)
- Active Account: ✓ (checked)
- Change some data:
- Name: Jane Doe
- Role: Admin
- Click "Save User"
✅ Expected Result:
- Success message appears
- User list updates showing:
- Name: Jane Doe
- Role badge: Admin (purple)
Step 4: Test Change Password
- Click the Change Password (key) button on the user
- Enter new password: NewSecure456
- Confirm password: NewSecure456
- Click "Change Password"
✅ Expected Result:
- Success message appears
- Password is updated in database
- Can verify by checking database or logging in with new password
Step 5: Test Delete User
- Click the Delete (trash) button
- Confirm deletion
- User is removed from list
✅ Expected Result:
- Success message appears
- User no longer appears in list
Option 3: API Testing UI
- Open:
http://localhost:5000/admin/test-user-api.html - Make sure you're logged in as admin
- Run each test in order:
Test 1: List All Users
- Click "Run Test" under section 1
- Should show all users in JSON format
Test 2: Get Single User
- Enter a user ID (copy from Test 1 results)
- Click "Run Test"
- Should show single user details
Test 3: Create New User
- Fields are pre-filled with random data
- Click "Run Test"
- Should create user and auto-fill IDs in other test sections
Test 4: Update User
- User ID should be auto-filled from Test 3
- Enter new name
- Select new role
- Click "Run Test"
- Should update user
Test 5: Change Password
- User ID should be auto-filled
- Password is pre-filled: NewSecure456
- Click "Run Test"
- Should change password
Test 6: Delete User
- User ID should be auto-filled
- Click "Run Test"
- Confirm deletion
- Should delete the test user
🔍 What to Check
Database Verification
cd /media/pts/Website/SkyArtShop/backend
node -e "
const db = require('./config/database');
db.query('SELECT id, name, username, email, role, isactive FROM adminusers ORDER BY createdat DESC LIMIT 3')
.then(r => console.table(r.rows))
.finally(() => process.exit());
"
Check Password Hash Format
cd /media/pts/Website/SkyArtShop/backend
node -e "
const db = require('./config/database');
db.query('SELECT username, LEFT(passwordhash, 10) as hash_start, LENGTH(passwordhash) as hash_length FROM adminusers LIMIT 3')
.then(r => console.table(r.rows))
.finally(() => process.exit());
"
Expected Output:
hash_startshould be$2b$10$...(bcrypt format)hash_lengthshould be 60
✅ Success Criteria
All of these should work:
- ✅ Edit button opens modal with user data pre-filled
- ✅ Create user saves name, username, email, and role
- ✅ User list shows all user information correctly
- ✅ Update user changes are saved to database
- ✅ Password changes work and are hashed with bcrypt
- ✅ All data reads correctly from database
- ✅ No JavaScript errors in browser console
- ✅ No errors in server logs
🐛 Troubleshooting
If Edit Button Doesn't Work
- Open browser console (F12)
- Click edit button
- Check for JavaScript errors
- Verify user ID is being passed correctly
- Check network tab for API request/response
If User Creation Fails
- Check server logs:
pm2 logs skyartshop - Verify all required fields are filled
- Check for duplicate username/email
- Verify password is at least 8 characters
If Password Not Working
- Check database: password hash should be 60 characters
- Hash should start with
$2b$10$ - Verify bcrypt is installed:
npm list bcrypt - Check server logs for bcrypt errors
📞 Support
If you encounter any issues:
- Check
/backend/logs/for detailed error logs - Run automated test:
node test-user-management.js - Check browser console for frontend errors
- Review server logs:
pm2 logs skyartshop
All fixes have been thoroughly tested and verified! 🎉