#!/bin/bash
# Script to update gateway tests and run them

set -e

echo "========================================="
echo "Updating Gateway Tests"
echo "========================================="
echo ""

# Check if we're in the right directory
if [ ! -f "test-all-phases.sh" ]; then
    echo "Error: test-all-phases.sh not found. Are you in apps/gateway?"
    exit 1
fi

# Stash any local changes
echo "Stashing local changes..."
git stash push -m "Stashing before test update $(date)" || true

# Pull latest changes
echo "Pulling latest changes..."
git pull --rebase || git pull

# Make scripts executable
chmod +x test-*.sh 2>/dev/null || true

echo ""
echo "========================================="
echo "Running Tests"
echo "========================================="
echo ""

# Run the tests
bash test-all-phases.sh 2>&1 | tail -40

