diff --git a/packages/reservation-platform/docker/test-env.yml b/packages/reservation-platform/docker/test-env.yml index ffad4a4..22e169f 100644 --- a/packages/reservation-platform/docker/test-env.yml +++ b/packages/reservation-platform/docker/test-env.yml @@ -1,25 +1,7 @@ version: '3.8' services: - # Backend for testing - backend: - build: - context: ../../backend - dockerfile: Dockerfile - container_name: myp-backend-test - ports: - - "5000:5000" - environment: - - SECRET_KEY=testsecretkey123456789 - - DATABASE_URL=sqlite:///myp.db - - FLASK_ENV=development - - TESTING=true - volumes: - - backend-test-data:/app/instance - networks: - - test-network - - # Frontend for testing - bound to loopback address + # Frontend for testing - using external backend frontend-test: build: context: .. @@ -29,17 +11,7 @@ services: - NODE_ENV=development - AUTH_TRUST_HOST=true - AUTH_SECRET=test-secret-key-for-testing-only-do-not-use-in-production - - NEXT_PUBLIC_BACKEND_URL=http://backend:5000 + - NEXT_PUBLIC_BACKEND_URL=http://192.168.0.105:5000 ports: - "127.0.0.1:3000:3000" - depends_on: - - backend - networks: - - test-network - -networks: - test-network: - driver: bridge - -volumes: - backend-test-data: \ No newline at end of file + network_mode: "host" \ No newline at end of file diff --git a/packages/reservation-platform/docker/test-integration.sh b/packages/reservation-platform/docker/test-integration.sh index 00d9de6..9a1c8f9 100755 --- a/packages/reservation-platform/docker/test-integration.sh +++ b/packages/reservation-platform/docker/test-integration.sh @@ -48,29 +48,28 @@ if [ $? -ne 0 ]; then exit 1 fi -# Wait for backend to be ready -echo -e "${YELLOW}Waiting for backend to be ready...${NC}" | tee -a "$TEST_LOG" -max_attempts=30 +# Check if external backend is available +echo -e "${YELLOW}Checking if external backend is available...${NC}" | tee -a "$TEST_LOG" +max_attempts=10 attempt=1 backend_ready=false while [ $attempt -le $max_attempts ] && [ "$backend_ready" = "false" ]; do echo "Checking backend readiness (attempt $attempt/$max_attempts)..." | tee -a "$TEST_LOG" - if curl -s http://localhost:5000/api/health &> /dev/null; then + if curl -s http://192.168.0.105:5000/api/health &> /dev/null; then backend_ready=true - echo -e "${GREEN}Backend is ready!${NC}" | tee -a "$TEST_LOG" + echo -e "${GREEN}External backend is available!${NC}" | tee -a "$TEST_LOG" else - echo "Backend not ready yet, waiting..." | tee -a "$TEST_LOG" + echo "External backend not available yet, waiting..." | tee -a "$TEST_LOG" sleep 2 attempt=$((attempt+1)) fi done if [ "$backend_ready" = "false" ]; then - echo -e "${RED}Backend failed to start properly after $max_attempts attempts${NC}" | tee -a "$TEST_LOG" - echo "Logs from backend container:" | tee -a "$TEST_LOG" - run_docker_compose -f "$SCRIPT_DIR/test-env.yml" logs backend >> "$TEST_LOG" 2>&1 + echo -e "${RED}External backend at 192.168.0.105:5000 is not available after $max_attempts attempts${NC}" | tee -a "$TEST_LOG" + echo -e "${RED}Please make sure the backend is running on the separate Raspberry Pi${NC}" | tee -a "$TEST_LOG" # Cleanup run_docker_compose -f "$SCRIPT_DIR/test-env.yml" down >> "$TEST_LOG" 2>&1 @@ -120,7 +119,7 @@ if [ -z "$frontend_container_id" ]; then fi # Run a simple test inside the frontend container to check API connectivity -api_test_result=$(docker exec $frontend_container_id curl -s http://backend:5000/api/health) +api_test_result=$(docker exec $frontend_container_id curl -s http://192.168.0.105:5000/api/health) if [[ "$api_test_result" == *"healthy"* ]]; then echo -e "${GREEN}Test 1 PASSED: Frontend can connect to backend API${NC}" | tee -a "$TEST_LOG" else @@ -145,7 +144,7 @@ echo -e "${GREEN}Integration tests completed${NC}" | tee -a "$TEST_LOG" # Ask if the environment should be kept running or shutdown echo -e "${YELLOW}Test environment is running at:${NC}" | tee -a "$TEST_LOG" echo "Frontend: http://127.0.0.1:3000" | tee -a "$TEST_LOG" -echo "Backend: http://localhost:5000" | tee -a "$TEST_LOG" +echo "Backend: http://192.168.0.105:5000 (external Raspberry Pi)" | tee -a "$TEST_LOG" echo "" | tee -a "$TEST_LOG" read -p "Do you want to keep the test environment running? (y/n): " keep_running