#!/usr/bin/env bash # Helper script to run tests inside the VM # This script is executed inside the VM set -e cd /tmp/moviemap echo "=== Setting up test environment ===" # Setup Python cd backend export PATH="/root/.local/bin:$PATH" python3 -m pip install --user --upgrade pip python3 -m pip install --user -r requirements.txt # Setup Node.js cd ../frontend npm ci echo "=== Waiting for PostgreSQL ===" # Wait for PostgreSQL to be ready for i in {1..30}; do if sudo -u postgres psql -c "SELECT 1;" > /dev/null 2>&1; then echo "PostgreSQL is ready" break fi if [ $i -eq 30 ]; then echo "PostgreSQL failed to start" exit 1 fi sleep 1 done echo "=== Running database migrations ===" cd ../backend export POSTGRES_SOCKET_PATH=/var/run/postgresql export POSTGRES_DB=moviemap_test export POSTGRES_USER=moviemap export PATH="/root/.local/bin:$PATH" alembic upgrade head echo "=== Running backend tests ===" export TEST_POSTGRES_DB=moviemap_test export TEST_POSTGRES_USER=moviemap export TEST_POSTGRES_SOCKET_PATH=/var/run/postgresql export RADARR_URL=http://localhost:7878 export SONARR_URL=http://localhost:8989 export LIDARR_URL=http://localhost:8686 export RADARR_API_KEY=test-key export SONARR_API_KEY=test-key export LIDARR_API_KEY=test-key export PATH="/root/.local/bin:$PATH" pytest tests/ -v --cov=app --cov-report=term-missing echo "=== Building frontend ===" cd ../frontend npm run build echo "=== Running frontend tests ===" npm test -- --run echo "=== All tests completed successfully ==="