import { ForbiddenException } from '@nestjs/common';
import { assertStepPermission, permittedStepKeys } from './imports.access';

describe('permittedStepKeys', () => {
  it('超级管理员拥有全部导入阶段', () => {
    expect(
      permittedStepKeys({ id: 1, permissions: [], isSuperAdmin: true }),
    ).toEqual(['students', 'rooms', 'checkins', 'transfers']);
  });

  it('按细分权限计算可提交阶段', () => {
    expect(
      permittedStepKeys({
        id: 1,
        permissions: ['student:import', 'room:edit', 'occupancy:checkin'],
        isSuperAdmin: false,
      }),
    ).toEqual(['students', 'rooms', 'checkins']);
  });

  it('无导入权限时仅返回空数组', () => {
    expect(
      permittedStepKeys({ id: 1, permissions: ['ai:chat:use'], isSuperAdmin: false }),
    ).toEqual([]);
  });
});

describe('assertStepPermission', () => {
  it('无对应细分权限时拒绝提交', () => {
    expect(() =>
      assertStepPermission(
        { id: 1, permissions: ['ai:chat:use'], isSuperAdmin: false },
        'transfers',
      ),
    ).toThrow(ForbiddenException);
  });
});
