feat: Add schema check and logging tests for project tasks and notes
This commit is contained in:
10
check-schema.mjs
Normal file
10
check-schema.mjs
Normal file
@@ -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());
|
||||
@@ -503,7 +503,6 @@ export default function ProjectTasksSection({ projectId }) {
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
{/* Description row (expandable) */}
|
||||
{task.description && expandedDescriptions[task.id] && (
|
||||
<tr className="bg-blue-50">
|
||||
@@ -516,7 +515,8 @@ export default function ProjectTasksSection({ projectId }) {
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
)} {/* Notes row (expandable) */}
|
||||
)}{" "}
|
||||
{/* Notes row (expandable) */}
|
||||
{expandedNotes[task.id] && (
|
||||
<tr className="bg-gray-50">
|
||||
<td colSpan="6" className="px-4 py-4">
|
||||
@@ -534,8 +534,8 @@ export default function ProjectTasksSection({ projectId }) {
|
||||
key={note.note_id}
|
||||
className={`p-3 rounded border flex justify-between items-start ${
|
||||
note.is_system
|
||||
? 'bg-blue-50 border-blue-200'
|
||||
: 'bg-white border-gray-200'
|
||||
? "bg-blue-50 border-blue-200"
|
||||
: "bg-white border-gray-200"
|
||||
}`}
|
||||
>
|
||||
<div className="flex-1">
|
||||
|
||||
@@ -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) {
|
||||
|
||||
49
test-logging.mjs
Normal file
49
test-logging.mjs
Normal file
@@ -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.");
|
||||
Reference in New Issue
Block a user