"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
const offline_queue_1 = require("../offline-queue");
const path = __importStar(require("path"));
describe('OfflineQueue', () => {
    let queue;
    const testDir = path.join(process.cwd(), '.fivo/cell');
    beforeEach(() => {
        queue = new offline_queue_1.OfflineQueue(testDir);
        queue.clearQueue();
    });
    test('enqueues and dequeues signals', () => {
        queue.enqueue('edit_diff', { code: 'test' });
        expect(queue.getQueueSize()).toBe(1);
        const signal = queue.dequeue();
        expect(signal).not.toBeNull();
        expect(signal.type).toBe('edit_diff');
        expect(queue.getQueueSize()).toBe(0);
    });
    test('peek returns first without removing', () => {
        queue.enqueue('accept', {});
        queue.enqueue('reject', {});
        const peeked = queue.peek();
        expect(peeked).not.toBeNull();
        expect(peeked.type).toBe('accept');
        expect(queue.getQueueSize()).toBe(2);
    });
    test('syncOnReconnect processes queue', async () => {
        queue.enqueue('edit_diff', {});
        queue.enqueue('accept', {});
        const result = await queue.syncOnReconnect(async () => true);
        expect(result.synced).toBe(2);
        expect(result.failed).toBe(0);
    });
    test('checkEngineHealth returns ONLINE after heartbeat', () => {
        queue.heartbeat();
        const status = queue.checkEngineHealth();
        expect(status.state).toBe('ONLINE');
    });
    test('checkEngineHealth returns ONLINE by default', () => {
        const status = queue.checkEngineHealth();
        expect(status.state).toBe('ONLINE');
    });
    test('getDegradedMessage returns appropriate message', () => {
        const onlineMsg = queue.getDegradedMessage({ state: 'ONLINE', lastHeartbeat: '', consecutiveFailures: 0 });
        expect(onlineMsg).toContain('online');
        const offlineMsg = queue.getDegradedMessage({ state: 'OFFLINE', lastHeartbeat: '', consecutiveFailures: 3 });
        expect(offlineMsg).toContain('OFFLINE');
    });
});
//# sourceMappingURL=offline-queue.test.js.map