import { describe, expect, it } from 'vitest';
import { applyLocalAstMutation } from './goa-ast-local';

describe('local GOA mutations', () => {
  it('adds an import once', () => {
    const first = applyLocalAstMutation({
      source: 'export const value = 1;\n',
      operation: 'ADD_IMPORT',
      codePayload: "import { thing } from './thing';",
      filePath: 'src/main.ts',
    });
    expect(first.applied).toBe(true);
    expect(first.content).toContain("import { thing } from './thing';");

    const second = applyLocalAstMutation({
      source: first.content,
      operation: 'ADD_IMPORT',
      codePayload: "import { thing } from './thing';",
      filePath: 'src/main.ts',
    });
    expect(second.applied).toBe(false);
  });

  it('refuses an unsupported operation', () => {
    const result = applyLocalAstMutation({
      source: 'const value = 1;',
      operation: 'UNKNOWN' as never,
      codePayload: 'unsafe',
      filePath: 'src/main.ts',
    });
    expect(result.applied).toBe(false);
  });
});
