import { SchedulesService } from './schedules.service';

describe('SchedulesService permission-scoped lookups', () => {
  it('returns scoped classes and minimal classrooms for schedule viewers', async () => {
    const classRepo = {
      find: jest.fn().mockResolvedValue([{ id: 3, name: '三班', code: 'C3' }]),
    };
    const scheduleRepo = {
      createQueryBuilder: jest.fn().mockReturnValue({
        select: jest.fn().mockReturnThis(),
        addSelect: jest.fn().mockReturnThis(),
        innerJoin: jest.fn().mockReturnThis(),
        distinct: jest.fn().mockReturnThis(),
        orderBy: jest.fn().mockReturnThis(),
        addOrderBy: jest.fn().mockReturnThis(),
        getRawMany: jest.fn().mockResolvedValue([{ classroomId: 5, classroomName: '教室5', classroomBuilding: 'A' }]),
      }),
    };
    const classroomRepo = {
      find: jest.fn().mockResolvedValue([{ id: 5, name: '教室5', building: 'A', floor: '1', roomType: 'classroom' }]),
    };
    const service = new SchedulesService(
      scheduleRepo as never,
      classRepo as never,
      classroomRepo as never,
      {} as never,
      {} as never,
    );
    await expect(service.getLookups([3])).resolves.toEqual({
      classes: [{ id: 3, name: '三班', code: 'C3' }],
      classrooms: [{ id: 5, name: '教室5', building: 'A', floor: '1', roomType: 'classroom' }],
    });
  });
});
