From f0e3bf6eaa932c83fe7da150b895518699a36a87 Mon Sep 17 00:00:00 2001 From: Chop <28534054+RChopin@users.noreply.github.com> Date: Thu, 19 Jun 2025 22:13:08 +0200 Subject: [PATCH] feat: Add schema check and logging tests for project tasks and notes --- check-schema.mjs | 10 ++++++ src/components/ProjectTasksSection.js | 10 +++--- src/lib/queries/notes.js | 8 ++--- src/lib/queries/tasks.js | 6 ++-- test-logging.mjs | 49 +++++++++++++++++++++++++++ 5 files changed, 70 insertions(+), 13 deletions(-) create mode 100644 check-schema.mjs create mode 100644 test-logging.mjs diff --git a/check-schema.mjs b/check-schema.mjs new file mode 100644 index 0000000..038448f --- /dev/null +++ b/check-schema.mjs @@ -0,0 +1,10 @@ +import db from "./src/lib/db.js"; + +console.log("Database schema for notes table:"); +console.log(db.prepare("PRAGMA table_info(notes)").all()); + +console.log("\nDatabase schema for project_tasks table:"); +console.log(db.prepare("PRAGMA table_info(project_tasks)").all()); + +console.log("\nSample notes to check is_system column:"); +console.log(db.prepare("SELECT * FROM notes LIMIT 5").all()); diff --git a/src/components/ProjectTasksSection.js b/src/components/ProjectTasksSection.js index 3d8a7c8..788097d 100644 --- a/src/components/ProjectTasksSection.js +++ b/src/components/ProjectTasksSection.js @@ -503,7 +503,6 @@ export default function ProjectTasksSection({ projectId }) { - {/* Description row (expandable) */} {task.description && expandedDescriptions[task.id] && ( @@ -516,7 +515,8 @@ export default function ProjectTasksSection({ projectId }) { - )} {/* Notes row (expandable) */} + )}{" "} + {/* Notes row (expandable) */} {expandedNotes[task.id] && ( @@ -533,9 +533,9 @@ export default function ProjectTasksSection({ projectId }) {
diff --git a/src/lib/queries/notes.js b/src/lib/queries/notes.js index a134d46..ca896fa 100644 --- a/src/lib/queries/notes.js +++ b/src/lib/queries/notes.js @@ -20,11 +20,9 @@ export function getNotesByTaskId(task_id) { } export function addNoteToTask(task_id, note, is_system = false) { - db.prepare(`INSERT INTO notes (task_id, note, is_system) VALUES (?, ?, ?)`).run( - task_id, - note, - is_system ? 1 : 0 - ); + db.prepare( + `INSERT INTO notes (task_id, note, is_system) VALUES (?, ?, ?)` + ).run(task_id, note, is_system ? 1 : 0); } export function deleteNote(note_id) { diff --git a/src/lib/queries/tasks.js b/src/lib/queries/tasks.js index 33fb821..c98874c 100644 --- a/src/lib/queries/tasks.js +++ b/src/lib/queries/tasks.js @@ -62,7 +62,7 @@ export function getProjectTasks(projectId) { export function createProjectTask(data) { let result; let taskName; - + if (data.task_template_id) { // Creating from template - explicitly set custom_max_wait_days to NULL so COALESCE uses template value const stmt = db.prepare(` @@ -75,7 +75,7 @@ export function createProjectTask(data) { data.status || "pending", data.priority || "normal" ); - + // Get the template name for the log const templateStmt = db.prepare("SELECT name FROM tasks WHERE task_id = ?"); const template = templateStmt.get(data.task_template_id); @@ -94,7 +94,7 @@ export function createProjectTask(data) { data.status || "pending", data.priority || "normal" ); - + taskName = data.custom_task_name; } diff --git a/test-logging.mjs b/test-logging.mjs new file mode 100644 index 0000000..1f72dc9 --- /dev/null +++ b/test-logging.mjs @@ -0,0 +1,49 @@ +import db from "./src/lib/db.js"; +import { + createProjectTask, + updateProjectTaskStatus, +} from "./src/lib/queries/tasks.js"; +import { getNotesByTaskId } from "./src/lib/queries/notes.js"; + +console.log("Testing automatic logging system...\n"); + +// Test 1: Create a new task and check if system note is created +console.log("Test 1: Creating a new task..."); +try { + const result = createProjectTask({ + project_id: 1, // Assuming project ID 1 exists + custom_task_name: "Test Task for Logging", + custom_description: "Testing automatic note creation", + custom_max_wait_days: 7, + priority: "high", + status: "pending", + }); + + const taskId = result.lastInsertRowid; + console.log(`✓ Task created with ID: ${taskId}`); + + // Check if system note was created + const notes = getNotesByTaskId(taskId); + console.log(`✓ Notes found: ${notes.length}`); + console.log("Notes:", notes); + + // Test 2: Update task status and check if system note is created + console.log("\nTest 2: Updating task status..."); + updateProjectTaskStatus(taskId, "in_progress"); + console.log("✓ Task status updated to in_progress"); + + // Check if new system note was created + const updatedNotes = getNotesByTaskId(taskId); + console.log(`✓ Notes after status update: ${updatedNotes.length}`); + console.log("Updated notes:", updatedNotes); + + // Clean up - delete test task + console.log("\nCleaning up test data..."); + db.prepare("DELETE FROM notes WHERE task_id = ?").run(taskId); + db.prepare("DELETE FROM project_tasks WHERE id = ?").run(taskId); + console.log("✓ Test data cleaned up"); +} catch (error) { + console.error("❌ Error during testing:", error); +} + +console.log("\nTest completed.");