import { RbacService } from './rbac.service';

describe('RbacService teacher listing', () => {
  it('queries only teacher roles, excluding administrators', async () => {
    const queryBuilder = {
      leftJoinAndSelect: jest.fn(),
      where: jest.fn(),
      andWhere: jest.fn(),
      getCount: jest.fn().mockResolvedValue(0),
      orderBy: jest.fn(),
      skip: jest.fn(),
      take: jest.fn(),
      getMany: jest.fn().mockResolvedValue([]),
    };
    for (const method of ['leftJoinAndSelect', 'where', 'andWhere', 'orderBy', 'skip', 'take'] as const) {
      queryBuilder[method].mockReturnValue(queryBuilder);
    }
    const userRepo = { createQueryBuilder: jest.fn().mockReturnValue(queryBuilder) };
    const service = new RbacService(
      {} as never,
      {} as never,
      userRepo as never,
      {} as never,
      {} as never,
      {} as never,
      {} as never,
      {} as never,
    );

    await service.getTeachers();

    expect(queryBuilder.where).toHaveBeenCalledWith(
      '(role.code IN (:...roleCodes) OR role.name IN (:...roleNames))',
      {
        roleCodes: ['teacher'],
        roleNames: ['任课老师', '老师'],
      },
    );
  });
});
