import { describe, it, expect, vi } from 'vitest';
vi.mock('../../../frameworks/queue/pQueueAdapter.js', () => ({
    setProgressChangeCallback: vi.fn(),
    setStateChangeCallback: vi.fn(),
    updateJobProgress: vi.fn(),
    getJobsStatus: vi.fn(() => ({ active: [], recent: [] })),
}));
vi.mock('../../../frameworks/logging/logBuffer.js', () => ({
    onLog: vi.fn(),
}));
import { buildBudgetStatusMessage, buildBudgetExceededMessage, } from '../../../main/websocket.js';
describe('buildBudgetStatusMessage', () => {
    it('produces a JSON string with type=budget-status, the view model, and a timestamp', () => {
        const viewModel = {
            limitUsdFormatted: '$200.00',
            consumedUsdFormatted: '$50.00',
            remainingUsdFormatted: '$150.00',
            percentUsedFormatted: '25.00%',
            gaugeWidthPercent: 25,
            exceeded: false,
            periodStart: '2026-05-01T00:00:00.000Z',
        };
        const raw = buildBudgetStatusMessage(viewModel);
        const parsed = JSON.parse(raw);
        expect(parsed.type).toBe('budget-status');
        expect(parsed.data).toEqual(viewModel);
        expect(typeof parsed.timestamp).toBe('string');
    });
});
describe('buildBudgetExceededMessage', () => {
    it('produces a JSON string with type=budget-exceeded carrying the blocked job context', () => {
        const payload = {
            mrNumber: 42,
            platform: 'gitlab',
            projectPath: 'group/project',
            limitUsd: 200,
            consumedUsd: 200.1,
        };
        const raw = buildBudgetExceededMessage(payload);
        const parsed = JSON.parse(raw);
        expect(parsed.type).toBe('budget-exceeded');
        expect(parsed.data).toEqual(payload);
        expect(typeof parsed.timestamp).toBe('string');
    });
});
//# sourceMappingURL=budgetBroadcast.test.js.map