"use strict";
/**
 * Tests for WorkflowParser
 */
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 workflow_parser_1 = require("./workflow-parser");
const path = __importStar(require("path"));
describe('WorkflowParser', () => {
    let parser;
    beforeEach(() => {
        parser = new workflow_parser_1.WorkflowParser();
    });
    describe('parseFile', () => {
        it('should parse a valid workflow file', async () => {
            const workflowPath = path.join(__dirname, '../../examples/validatestack-mvp.workflow.yaml');
            const result = await parser.parseFile(workflowPath);
            expect(result).toBeDefined();
            expect(result.workflow).toBeDefined();
            expect(result.workflow.workflow.id).toBe('validatestack-mvp');
            expect(result.workflow.workflow.name).toBe('ValidateStack MVP');
            expect(result.workflow.workflow.version).toBe('1.0.0');
        });
        it('should throw error for non-existent file', async () => {
            await expect(parser.parseFile('non-existent.yaml')).rejects.toThrow('Workflow file not found');
        });
    });
    describe('parseString', () => {
        it('should parse a valid minimal workflow', async () => {
            const yamlContent = `
workflow:
  id: test-workflow
  version: 1.0.0
  name: Test Workflow
  description: A test workflow

stack:
  web-app:
    type: frontend
    technology: react
    components:
      - id: test-component
        type: form-component
        name: TestComponent
        description: A test component
`;
            const result = await parser.parseString(yamlContent);
            expect(result).toBeDefined();
            expect(result.workflow).toBeDefined();
            expect(result.workflow.workflow.id).toBe('test-workflow');
            expect(result.workflow.workflow.name).toBe('Test Workflow');
            expect(result.workflow.stack).toBeDefined();
            expect(result.workflow.stack['web-app']).toBeDefined();
            expect(result.workflow.stack['web-app'].type).toBe('frontend');
            expect(result.workflow.stack['web-app'].technology).toBe('react');
        });
        it('should throw validation error for missing required fields', async () => {
            const yamlContent = `
workflow:
  id: test-workflow
  version: 1.0.0
`;
            await expect(parser.parseString(yamlContent)).rejects.toThrow('Validation error');
        });
        it('should throw error for empty workflow', async () => {
            await expect(parser.parseString('')).rejects.toThrow('Empty workflow file');
        });
        it('should throw error for workflow without any stack components', async () => {
            const yamlContent = `
workflow:
  id: test-workflow
  version: 1.0.0
  name: Test Workflow
  description: A test workflow
stack: {}
`;
            await expect(parser.parseString(yamlContent)).rejects.toThrow('Workflow must define at least one stack component');
        });
    });
    describe('parseDirectory', () => {
        it('should parse a known-good workflow file', async () => {
            // Test with a specific workflow file that we know works (no circular refs)
            const testDir = path.join(__dirname, '../../examples');
            const testFile = path.join(testDir, 'validatestack-mvp.workflow.yaml');
            // Just test that we can parse a single known-good workflow file
            const result = await parser.parseFile(testFile);
            expect(result).toBeDefined();
            expect(result.workflow).toBeDefined();
            expect(result.workflow.workflow.id).toBe('validatestack-mvp');
            expect(result.workflow.workflow.name).toBe('ValidateStack MVP');
        });
        it('should throw error for non-existent directory', async () => {
            await expect(parser.parseDirectory('non-existent-dir')).rejects.toThrow('Directory not found');
        });
    });
});
//# sourceMappingURL=workflow-parser.test.js.map