"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const database_1 = require("../walls/06-memory/database/database");
const memory_event_store_1 = require("../walls/06-memory/stores/memory-event-store");
const TEST_PROJECT = 'test-velocity';
function setupTestData() {
    const db = (0, database_1.getDb)();
    db.prepare('DELETE FROM memory_events WHERE project = ?').run(TEST_PROJECT);
    for (let i = 0; i < 14; i++) {
        (0, memory_event_store_1.recordMemoryEvent)({ project: TEST_PROJECT, type: 'branch', summary: `Commit ${i}`, importance: 5 });
        (0, memory_event_store_1.recordMemoryEvent)({ project: TEST_PROJECT, type: 'edit', summary: `Edit ${i}`, importance: 3 });
        if (i % 3 === 0)
            (0, memory_event_store_1.recordMemoryEvent)({ project: TEST_PROJECT, type: 'decision', summary: `Decision ${i}`, importance: 8 });
        if (i % 4 === 0) {
            (0, memory_event_store_1.recordMemoryEvent)({ project: TEST_PROJECT, type: 'error', summary: `Error ${i}`, importance: 7 });
            (0, memory_event_store_1.recordMemoryEvent)({ project: TEST_PROJECT, type: 'fix', summary: `Fix ${i}`, importance: 8 });
        }
        if (i % 2 === 0)
            (0, memory_event_store_1.recordMemoryEvent)({ project: TEST_PROJECT, type: 'verification', summary: `Verify ${i}`, importance: 6 });
    }
}
describe('Developer Velocity', () => {
    beforeAll(() => { setupTestData(); });
    test('computeDeveloperVelocity returns valid result', () => {
        const { computeDeveloperVelocity } = require('../walls/06-memory/stores/developer-velocity');
        const vel = computeDeveloperVelocity(TEST_PROJECT, 30);
        expect(vel.project).toBe(TEST_PROJECT);
        expect(typeof vel.metrics.totalCommits).toBe('number');
        expect(typeof vel.score.overall).toBe('number');
        expect(Array.isArray(vel.trends)).toBe(true);
    });
    test('score has valid grade', () => {
        const { computeDeveloperVelocity } = require('../walls/06-memory/stores/developer-velocity');
        const vel = computeDeveloperVelocity(TEST_PROJECT, 30);
        expect(['S', 'A', 'B', 'C', 'D', 'F']).toContain(vel.score.grade);
    });
    test('score dimensions are 0-100', () => {
        const { computeDeveloperVelocity } = require('../walls/06-memory/stores/developer-velocity');
        const vel = computeDeveloperVelocity(TEST_PROJECT, 30);
        expect(vel.score.dimensions.productivity).toBeGreaterThanOrEqual(0);
        expect(vel.score.dimensions.productivity).toBeLessThanOrEqual(100);
        expect(vel.score.dimensions.quality).toBeGreaterThanOrEqual(0);
        expect(vel.score.dimensions.quality).toBeLessThanOrEqual(100);
    });
    test('metrics populated', () => {
        const { computeDeveloperVelocity } = require('../walls/06-memory/stores/developer-velocity');
        const vel = computeDeveloperVelocity(TEST_PROJECT, 30);
        expect(vel.metrics.totalCommits).toBe(14);
        expect(vel.metrics.totalEdits).toBe(14);
        expect(vel.metrics.totalDecisions).toBeGreaterThan(0);
    });
    test('chart is string', () => {
        const { computeDeveloperVelocity } = require('../walls/06-memory/stores/developer-velocity');
        const vel = computeDeveloperVelocity(TEST_PROJECT, 30);
        expect(typeof vel.chart).toBe('string');
        expect(vel.chart).toContain('Developer Velocity');
    });
    test('formatDeveloperVelocity produces markdown', () => {
        const { computeDeveloperVelocity, formatDeveloperVelocity } = require('../walls/06-memory/stores/developer-velocity');
        const vel = computeDeveloperVelocity(TEST_PROJECT, 30);
        const formatted = formatDeveloperVelocity(vel);
        expect(formatted).toContain('Developer Velocity');
        expect(formatted).toContain('Score');
    });
});
//# sourceMappingURL=developer-velocity.test.js.map