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

import { buildSkillTextDownload } from './skill-file-download';

describe('skill file download', () => {
  it('downloads the current text buffer including unsaved edits', async () => {
    const blob = buildSkillTextDownload(
      {
        content: 'saved',
        isText: true,
        path: 'scripts/run.py',
        type: 'SCRIPT',
      },
      'unsaved edit',
    );

    expect(await blob?.text()).toBe('unsaved edit');
  });

  it.each([
    ['ASSET', 'assets/archive.bin'],
    ['EXAMPLE', 'examples/archive.bin'],
    ['OTHER', 'resources/archive.bin'],
    ['REFERENCE', 'references/manual.pdf'],
    ['SCRIPT', 'scripts/tool.bin'],
  ])(
    'keeps binary %s resources on the authenticated download path',
    (type, path) => {
      expect(
        buildSkillTextDownload({ isText: false, path, type }, ''),
      ).toBeUndefined();
    },
  );
});
