import { describe, expect, it } from 'vitest';
import { platformOperations } from './platform-operations.generated';
import { groupForOperation, platformGroups } from './groups';

describe('平台 OpenAPI 页面覆盖', () => {
  it('每个后端平台接口恰好归入一个页面组', () => {
    const knownGroups = new Set(platformGroups.map((group) => group.key));
    const grouped = platformOperations.map((operation) => ({ id: operation.id, group: groupForOperation(operation) }));
    expect(grouped).toHaveLength(platformOperations.length);
    expect(new Set(grouped.map((item) => item.id)).size).toBe(platformOperations.length);
    expect(grouped.every((item) => knownGroups.has(item.group))).toBe(true);
  });

  it('契约只包含平台权限域接口', () => {
    expect(platformOperations.length).toBeGreaterThan(0);
    expect(platformOperations.every((operation) => operation.path.startsWith('/api/platform-admin/') || operation.path.startsWith('/api/backoffice/platform/'))).toBe(true);
  });
});
