#!/bin/bash
# Quick test script for NIP

set -e

echo "🧪 Testing NIP..."
echo ""

# Test binary exists and runs
echo "1. Testing binary execution..."
if ./nip --help > /dev/null 2>&1; then
    echo "   ✅ Binary executes successfully"
else
    echo "   ❌ Binary execution failed"
    exit 1
fi

# Test version command
echo "2. Testing version command..."
if ./nip --version > /dev/null 2>&1; then
    echo "   ✅ Version command works"
else
    echo "   ❌ Version command failed"
    exit 1
fi

# Test config command (no root needed)
echo "3. Testing config command..."
if ./nip config show > /dev/null 2>&1; then
    echo "   ✅ Config command works"
else
    echo "   ❌ Config command failed"
    exit 1
fi

# Test platform command
echo "4. Testing platform command..."
if ./nip platform > /dev/null 2>&1; then
    echo "   ✅ Platform command works"
else
    echo "   ❌ Platform command failed"
    exit 1
fi

# Test logs command
echo "5. Testing logs command..."
if ./nip logs 5 > /dev/null 2>&1; then
    echo "   ✅ Logs command works"
else
    echo "   ❌ Logs command failed"
    exit 1
fi

# Test setup command (will fail without root, but should not crash)
echo "6. Testing setup command..."
if ./nip setup > /dev/null 2>&1; then
    echo "   ✅ Setup command works"
elif [ $? -eq 1 ]; then
    echo "   ✅ Setup command works (requires root)"
fi

echo "7. Testing config init..."
rm -f ~/.nip/config
if ./nip config init > /dev/null 2>&1; then
    echo "   ✅ Config init works"
    if [ -f ~/.nip/config ]; then
        echo "   ✅ Config file created"
    else
        echo "   ❌ Config file not created"
        exit 1
    fi
fi

# Test help system
echo "8. Testing help system..."
if ./nip --help | grep -q "Universal Package"; then
    echo "   ✅ Help system works"
else
    echo "   ❌ Help system failed"
    exit 1
fi

echo ""
echo "✅ All tests passed!"
