import { describe, it, expect } from 'vitest';
import Database from 'better-sqlite3';
import { runMigrations } from '@main/db/migrations/index.js';

describe('migrations m002 due_date', () => {
  // v3 (m003 soft_delete) lands in v0.2.3 #4 — latest version + user_version
  // assertions migrate to migrations.test.ts. Here we keep only the m002-specific
  // assertion (due_date column existence) which is version-stable.
  it('due_date column exists with NULL default', () => {
    const db = new Database(':memory:');
    runMigrations(db);
    db.prepare(
      `INSERT INTO notes (id, raw_text, ai_status, created_at, updated_at)
       VALUES (?, ?, 'pending', ?, ?)`
    ).run('n1', 'x', '2026-04-26T00:00:00Z', '2026-04-26T00:00:00Z');
    const row = db.prepare('SELECT due_date, due_date_edited_by_user FROM notes WHERE id=?').get('n1') as any;
    expect(row.due_date).toBeNull();
    expect(row.due_date_edited_by_user).toBe(0);
  });
});
