import { describe, it, expect, vi } from 'vitest';
import {
  configureMediaRuntime,
  getMediaFillStore,
  getMediaTransport,
  resetMediaRuntimeForTesting,
} from '@ablogcms/media/runtime';
import { getGlobalFillBridge } from '@ablogcms/plugins/core';
import { bootstrapMediaRuntime } from './bootstrap';

vi.mock('@ablogcms/media/runtime', async () => {
  const actual = await vi.importActual<typeof import('@ablogcms/media/runtime')>('@ablogcms/media/runtime');
  return {
    ...actual,
    configureMediaRuntime: vi.fn(actual.configureMediaRuntime),
  };
});

describe('bootstrapMediaRuntime', () => {
  it('createAcmsMediaTransport() で作った transport を configureMediaRuntime に渡し、以降 getMediaTransport で参照できる', () => {
    resetMediaRuntimeForTesting();

    bootstrapMediaRuntime();

    expect(configureMediaRuntime).toHaveBeenCalledTimes(1);
    const transport = getMediaTransport();
    expect(typeof transport.fetchMediaList).toBe('function');
    expect(typeof transport.uploadMedia).toBe('function');
  });

  it('グローバル Fill ブリッジ（getGlobalFillBridge）を configureMediaRuntime に注入し、以降 getMediaFillStore で参照できる', () => {
    resetMediaRuntimeForTesting();

    bootstrapMediaRuntime();

    expect(getMediaFillStore()).toBe(getGlobalFillBridge());
  });
});
