Files
tilbudgivern/tests/run-full-test-suite.sh
alexpolo1 26d3452d59 Add comprehensive tests for API verification, frontend integration, and PDF generation
- Implemented a new test suite for production API verification using curl, ensuring all critical endpoints respond correctly and return valid JSON.
- Added frontend integration tests to check for critical errors in the UI and verify key UI elements are present and functional.
- Created test data for quotes and project calculations to facilitate testing.
- Developed a script to check offers in the Ordrestyring system, including detailed task descriptions.
- Added tests for generating PDFs from quote data, ensuring the output is valid and contains expected information.
- Implemented a test script for the Røsevangen project, integrating with the Ordrestyring API and verifying database entries.
2025-11-07 08:02:07 +00:00

172 lines
4.7 KiB
Bash
Executable File

#!/bin/bash
echo "🧪 RUNNING FULL TILBUDGIVERN TEST SUITE"
echo "========================================"
echo ""
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
print_status() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Test 1: Backend Jest Tests
echo ""
print_status "1. Running Backend Jest Tests..."
cd backend
npm test > /tmp/jest_results.txt 2>&1
JEST_EXIT_CODE=$?
if [ $JEST_EXIT_CODE -eq 0 ]; then
JEST_PASSED=$(grep "Tests:" /tmp/jest_results.txt | grep -o '[0-9]\+ passed' | head -1)
print_success "Backend Tests: $JEST_PASSED"
else
print_error "Backend Tests Failed"
cat /tmp/jest_results.txt
exit 1
fi
cd ..
# Test 2: Server Status Check
echo ""
print_status "2. Checking PM2 Server Status..."
PM2_STATUS=$(pm2 jlist | jq -r '.[] | select(.name=="tilbudgivern-unified") | .pm2_env.status')
if [ "$PM2_STATUS" = "online" ]; then
print_success "PM2 Server: Online"
else
print_error "PM2 Server: Not running correctly"
pm2 logs tilbudgivern-unified --lines 10 --nostream
exit 1
fi
# Test 3: API Endpoints Test
echo ""
print_status "3. Testing Critical API Endpoints..."
ENDPOINTS=(
"/api/health"
"/api/smart-packages?limit=2"
"/api/smart-packages/categories"
"/api/materials?limit=2"
"/api/planning/employees"
"/api/planning/calendar"
"/api/enhanced/roof-types"
)
ALL_APIS_OK=true
for endpoint in "${ENDPOINTS[@]}"; do
RESPONSE=$(curl -s -w "\n%{http_code}" "https://tilbudsgiveren.alw.dk$endpoint")
STATUS_CODE=$(echo "$RESPONSE" | tail -n1)
RESPONSE_BODY=$(echo "$RESPONSE" | head -n -1)
if [ "$STATUS_CODE" = "200" ]; then
# Verify JSON response
echo "$RESPONSE_BODY" | jq . > /dev/null 2>&1
if [ $? -eq 0 ]; then
print_success "API $endpoint: Status $STATUS_CODE"
else
print_warning "API $endpoint: Status $STATUS_CODE but invalid JSON"
ALL_APIS_OK=false
fi
else
print_error "API $endpoint: Status $STATUS_CODE"
ALL_APIS_OK=false
fi
done
if [ "$ALL_APIS_OK" = false ]; then
print_error "Some API endpoints failed"
exit 1
fi
# Test 4: Frontend Test
echo ""
print_status "4. Testing Frontend Accessibility..."
FRONTEND_RESPONSE=$(curl -s -w "%{http_code}" "https://tilbudsgiveren.alw.dk/")
FRONTEND_STATUS=$(echo "$FRONTEND_RESPONSE" | tail -c 3)
if [ "$FRONTEND_STATUS" = "200" ]; then
print_success "Frontend: Accessible (Status 200)"
else
print_error "Frontend: Not accessible (Status $FRONTEND_STATUS)"
exit 1
fi
# Test 5: Key Features Verification
echo ""
print_status "5. Verifying Key Fixes..."
# Employee endpoint specific test
EMPLOYEE_RESPONSE=$(curl -s "https://tilbudsgiveren.alw.dk/api/planning/employees")
EMPLOYEE_COUNT=$(echo "$EMPLOYEE_RESPONSE" | jq -r '.count')
if [ "$EMPLOYEE_COUNT" -gt "0" ]; then
TOTAL_EMPLOYEES=$(echo "$EMPLOYEE_RESPONSE" | jq -r '.totalEmployees')
print_success "Calendar Fix: $EMPLOYEE_COUNT active employees of $TOTAL_EMPLOYEES total ✅"
else
print_error "Calendar Fix: No active employees found ❌"
exit 1
fi
# Smart packages test
PACKAGES_RESPONSE=$(curl -s "https://tilbudsgiveren.alw.dk/api/smart-packages?limit=1")
PACKAGES_SUCCESS=$(echo "$PACKAGES_RESPONSE" | jq -r '.success')
if [ "$PACKAGES_SUCCESS" = "true" ]; then
print_success "SmartPackages Fix: Service initialized correctly ✅"
else
print_error "SmartPackages Fix: Service not working ❌"
exit 1
fi
# Test 6: Performance Check
echo ""
print_status "6. Quick Performance Check..."
START_TIME=$(date +%s%N)
curl -s "https://tilbudsgiveren.alw.dk/api/health" > /dev/null
END_TIME=$(date +%s%N)
DURATION=$(( (END_TIME - START_TIME) / 1000000 ))
if [ $DURATION -lt 5000 ]; then
print_success "API Response Time: ${DURATION}ms ✅"
else
print_warning "API Response Time: ${DURATION}ms (slower than expected)"
fi
# Final Summary
echo ""
echo "========================================"
print_success "🎉 ALL TESTS PASSED! TILBUDGIVERN IS READY!"
echo "========================================"
echo ""
print_status "✅ Backend Tests: Jest tests passed"
print_status "✅ Server Status: PM2 online"
print_status "✅ API Endpoints: All responding correctly"
print_status "✅ Frontend: Accessible and serving"
print_status "✅ Calendar Fix: Employee data working"
print_status "✅ SmartPackages Fix: Service initialized"
print_status "✅ Performance: Response times acceptable"
echo ""
print_status "🌐 Production URL: https://tilbudsgiveren.alw.dk/"
print_status "📋 Ready for Jannick's testing!"
echo ""