import { describe, expect, test } from 'vitest';

import { parseEnvText } from '../../src/utils/env';

describe('parseEnvText', () => {
  test('parses dotenv content without exposing invalid rows', () => {
    expect(
      parseEnvText(`
        # comment
        AUTH_SECRET="secret=value"
        export authentik_client_id='client'
        1INVALID=nope
        EMPTY=
      `),
    ).toEqual([
      { name: 'AUTH_SECRET', value: 'secret=value' },
      { name: 'AUTHENTIK_CLIENT_ID', value: 'client' },
      { name: 'EMPTY', value: '' },
    ]);
  });

  test('ignores blank lines and strips matching quotes only', () => {
    expect(
      parseEnvText(`

        PLAIN=value
        QUOTED="value"
        SINGLE='value'
        UNMATCHED="value
      `),
    ).toEqual([
      { name: 'PLAIN', value: 'value' },
      { name: 'QUOTED', value: 'value' },
      { name: 'SINGLE', value: 'value' },
      { name: 'UNMATCHED', value: '"value' },
    ]);
  });
});
