import { describe, it, expect } from 'vitest';
import { createSpaceGateway, createPublicAppGateway } from './app-file-gateway';

// read-only は writeFile/deleteFile の「不在」で表現する。認証版は両方を持ち、公開版は
// 持たない。AppRunner はこの有無を見て read-only を判定する（プロパティ存在 = 書き込み可）。
describe('app-file-gateway', () => {
  it('space gateway exposes write/delete (read-write)', () => {
    const g = createSpaceGateway('s1');
    expect(typeof g.writeFile).toBe('function');
    expect(typeof g.deleteFile).toBe('function');
  });

  it('public app gateway has NO write/delete (read-only)', () => {
    const g = createPublicAppGateway('tok');
    expect(g.writeFile).toBeUndefined();
    expect(g.deleteFile).toBeUndefined();
  });

  it('rawUrl points at the matching backend endpoint for each gateway', () => {
    expect(createSpaceGateway('s1').rawUrl('apps/x/a.png')).toBe(
      '/api/local/spaces/s1/files/raw?path=apps%2Fx%2Fa.png',
    );
    expect(createPublicAppGateway('tok').rawUrl('apps/x/a.png')).toBe(
      '/api/app-share/tok/files/raw?path=apps%2Fx%2Fa.png',
    );
  });
});
