|
| 1 | +#!/bin/bash |
| 2 | +# Tests for enhancement-queue.sh |
| 3 | + |
| 4 | +set -euo pipefail |
| 5 | + |
| 6 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 7 | +PROJECT_ROOT="$(dirname "$SCRIPT_DIR")" |
| 8 | + |
| 9 | +source "$SCRIPT_DIR/test-framework.sh" |
| 10 | + |
| 11 | +SCRIPT="$PROJECT_ROOT/scripts/enhancement-queue.sh" |
| 12 | + |
| 13 | +# Create temp directory for tests |
| 14 | +TEMP_DIR=$(create_temp_dir) |
| 15 | +export CLAUDE_PROJECT_DIR="$TEMP_DIR" |
| 16 | +mkdir -p "$TEMP_DIR/.aida/queue" |
| 17 | + |
| 18 | +echo "========================================" |
| 19 | +echo "Testing: enhancement-queue.sh" |
| 20 | +echo "========================================" |
| 21 | +echo "" |
| 22 | + |
| 23 | +# ============================================ |
| 24 | +# Test: Script exists and is executable |
| 25 | +# ============================================ |
| 26 | +test_start "Script exists and is executable" |
| 27 | +if assert_file_exists "$SCRIPT" && assert_executable "$SCRIPT"; then |
| 28 | + test_pass |
| 29 | +fi |
| 30 | + |
| 31 | +# ============================================ |
| 32 | +# Test: Help command works |
| 33 | +# ============================================ |
| 34 | +test_start "Help command works" |
| 35 | +output=$(run_script "$SCRIPT" help 2>&1) || true |
| 36 | +if assert_contains "$output" "Enhancement Queue" && \ |
| 37 | + assert_contains "$output" "Usage"; then |
| 38 | + test_pass |
| 39 | +fi |
| 40 | + |
| 41 | +# ============================================ |
| 42 | +# Test: Status command works |
| 43 | +# ============================================ |
| 44 | +test_start "Status command works" |
| 45 | +output=$(run_script "$SCRIPT" status 2>&1) || true |
| 46 | +# Should output something without error |
| 47 | +if [[ -n "$output" ]]; then |
| 48 | + test_pass |
| 49 | +else |
| 50 | + test_fail "No output from status command" |
| 51 | +fi |
| 52 | + |
| 53 | +# ============================================ |
| 54 | +# Test: Add command works |
| 55 | +# ============================================ |
| 56 | +test_start "Add command works" |
| 57 | +output=$(run_script "$SCRIPT" add "Test enhancement 1" 2>&1) || true |
| 58 | +# Should create queue file or output success |
| 59 | +if [[ -f "$TEMP_DIR/.aida/queue/queue.json" ]] || \ |
| 60 | + [[ "$output" == *"Added"* ]] || \ |
| 61 | + [[ "$output" == *"#"* ]]; then |
| 62 | + test_pass |
| 63 | +else |
| 64 | + test_fail "Add command failed" |
| 65 | +fi |
| 66 | + |
| 67 | +# ============================================ |
| 68 | +# Test: List command works |
| 69 | +# ============================================ |
| 70 | +test_start "List command works" |
| 71 | +output=$(run_script "$SCRIPT" list 2>&1) || true |
| 72 | +# Should output list (may be empty) |
| 73 | +if [[ -n "$output" ]]; then |
| 74 | + test_pass |
| 75 | +fi |
| 76 | + |
| 77 | +# ============================================ |
| 78 | +# Test: Next command works |
| 79 | +# ============================================ |
| 80 | +test_start "Next command works" |
| 81 | +# Add another item first |
| 82 | +run_script "$SCRIPT" add "Another item" 2>&1 || true |
| 83 | +output=$(run_script "$SCRIPT" next 2>&1) || true |
| 84 | +# Should return something or indicate no items |
| 85 | +if [[ -n "$output" ]]; then |
| 86 | + test_pass |
| 87 | +fi |
| 88 | + |
| 89 | +# ============================================ |
| 90 | +# Test: Count command works |
| 91 | +# ============================================ |
| 92 | +test_start "Count command works" |
| 93 | +output=$(run_script "$SCRIPT" count 2>&1) || true |
| 94 | +# Should output a number or count info |
| 95 | +if [[ "$output" =~ [0-9] ]] || [[ -n "$output" ]]; then |
| 96 | + test_pass |
| 97 | +fi |
| 98 | + |
| 99 | +# ============================================ |
| 100 | +# Test: Queue file is valid JSON |
| 101 | +# ============================================ |
| 102 | +test_start "Queue file is valid JSON" |
| 103 | +if [[ -f "$TEMP_DIR/.aida/queue/queue.json" ]]; then |
| 104 | + queue=$(cat "$TEMP_DIR/.aida/queue/queue.json") |
| 105 | + if assert_json_valid "$queue"; then |
| 106 | + test_pass |
| 107 | + fi |
| 108 | +else |
| 109 | + test_fail "Queue file not found" |
| 110 | +fi |
| 111 | + |
| 112 | +# Cleanup |
| 113 | +cleanup_temp "$TEMP_DIR" |
| 114 | + |
| 115 | +print_summary |
0 commit comments