summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/next-task.test.sh43
1 files changed, 43 insertions, 0 deletions
diff --git a/test/next-task.test.sh b/test/next-task.test.sh
new file mode 100644
index 0000000..3304efa
--- /dev/null
+++ b/test/next-task.test.sh
@@ -0,0 +1,43 @@
+#!/bin/bash
+# test/next-task.test.sh
+
+set -euo pipefail
+
+# Create a temporary database
+TEST_DB=$(mktemp)
+sqlite3 "$TEST_DB" <<EOF
+CREATE TABLE tasks (
+ id TEXT PRIMARY KEY,
+ state TEXT NOT NULL,
+ parent_task_id TEXT,
+ created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
+ updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
+ priority TEXT DEFAULT 'normal'
+);
+EOF
+
+# Insert a COMPLETED task that will not have a PENDING child or sibling,
+# to ensure the fallback logic is triggered.
+sqlite3 "$TEST_DB" "INSERT INTO tasks (id, state, created_at) VALUES ('completed-no-children', 'COMPLETED', '2023-01-01 12:00:00');"
+
+# Inject a QUEUED task (should be picked by fallback)
+sqlite3 "$TEST_DB" "INSERT INTO tasks (id, state, priority, created_at) VALUES ('queued-task-id', 'QUEUED', 'high', '2023-01-01 10:00:00');"
+
+# Inject a PENDING task (lower priority, should not be picked first by fallback)
+sqlite3 "$TEST_DB" "INSERT INTO tasks (id, state, priority, created_at) VALUES ('pending-task-id', 'PENDING', 'normal', '2023-01-01 11:00:00');"
+
+# Run the next-task script with the temporary database path
+export DB_PATH="$TEST_DB" # Override DB_PATH for the test
+SCRIPT_DIR="$(dirname "$(dirname "$0")")/scripts"
+NEXT_TASK_ID=$("$SCRIPT_DIR/next-task")
+
+# Assert that the QUEUED task is returned
+if [[ "$NEXT_TASK_ID" == "queued-task-id" ]]; then
+ echo "Test passed: QUEUED task was selected by fallback."
+else
+ echo "Test failed: Expected 'queued-task-id', got '$NEXT_TASK_ID'"
+ exit 1
+fi
+
+# Clean up
+rm "$TEST_DB"