"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;
    };
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const utils_1 = require("../../src/assertions/utils");
const cliState_1 = __importDefault(require("../../src/cliState"));
jest.mock('fs');
jest.mock('path');
jest.mock('../../src/cliState');
describe('processFileReference', () => {
    beforeEach(() => {
        jest.resetAllMocks();
        cliState_1.default.basePath = '/base/path';
    });
    it('should process JSON files correctly', () => {
        const jsonContent = JSON.stringify({ key: 'value' });
        jest.mocked(fs.readFileSync).mockReturnValue(jsonContent);
        jest.mocked(path.resolve).mockReturnValue('/base/path/test.json');
        jest.mocked(path.extname).mockReturnValue('.json');
        const result = (0, utils_1.processFileReference)('file://test.json');
        expect(result).toEqual({ key: 'value' });
        expect(fs.readFileSync).toHaveBeenCalledWith('/base/path/test.json', 'utf8');
    });
    it('should process YAML files correctly', () => {
        const yamlContent = 'key: value';
        jest.mocked(fs.readFileSync).mockReturnValue(yamlContent);
        jest.mocked(path.resolve).mockReturnValue('/base/path/test.yaml');
        jest.mocked(path.extname).mockReturnValue('.yaml');
        const result = (0, utils_1.processFileReference)('file://test.yaml');
        expect(result).toEqual({ key: 'value' });
        expect(fs.readFileSync).toHaveBeenCalledWith('/base/path/test.yaml', 'utf8');
    });
    it('should process TXT files correctly', () => {
        const txtContent = 'plain text content\n';
        jest.mocked(fs.readFileSync).mockReturnValue(txtContent);
        jest.mocked(path.resolve).mockReturnValue('/base/path/test.txt');
        jest.mocked(path.extname).mockReturnValue('.txt');
        const result = (0, utils_1.processFileReference)('file://test.txt');
        expect(result).toBe('plain text content');
        expect(fs.readFileSync).toHaveBeenCalledWith('/base/path/test.txt', 'utf8');
    });
    it('should throw an error for unsupported file types', () => {
        jest.mocked(path.resolve).mockReturnValue('/base/path/test.unsupported');
        jest.mocked(path.extname).mockReturnValue('.unsupported');
        expect(() => (0, utils_1.processFileReference)('file://test.unsupported')).toThrow('Unsupported file type');
    });
});
describe('getFinalTest', () => {
    beforeEach(() => {
        jest.clearAllMocks();
    });
    it('should correctly merge test and assertion data', () => {
        const mockApiProvider = {
            id: () => 'mockProvider',
            callApi: jest.fn(),
        };
        const testCase = {
            vars: { var1: 'value1' },
            options: {
                provider: {
                    id: () => 'testProvider',
                    callApi: jest.fn(),
                },
            },
        };
        const assertion = {
            type: 'equals',
            value: 'expected value',
            provider: mockApiProvider,
            rubricPrompt: 'custom rubric prompt',
        };
        const result = (0, utils_1.getFinalTest)(testCase, assertion);
        expect(Object.isFrozen(result)).toBe(true);
        expect(result.options?.provider).toBe(mockApiProvider);
        expect(result.options?.rubricPrompt).toBe('custom rubric prompt');
        expect(result.vars).toEqual({ var1: 'value1' });
        expect(testCase.options?.provider?.id()).toBe('testProvider');
        expect(typeof result.options?.provider?.callApi).toBe('function');
    });
    it('should use test provider when assertion provider is not provided', () => {
        const testCase = {
            options: {
                provider: {
                    id: () => 'testProvider',
                    callApi: jest.fn(),
                },
            },
        };
        const assertion = {
            type: 'equals',
            value: 'expected value',
        };
        const result = (0, utils_1.getFinalTest)(testCase, assertion);
        expect(result.options?.provider?.id()).toBe('testProvider');
        expect(typeof result.options?.provider?.callApi).toBe('function');
    });
});
//# sourceMappingURL=utils.test.js.map