chore: apply eslint --fix autofixes (remove unnecessary as never casts in tests)
This commit is contained in:
@@ -213,7 +213,7 @@ describe('AttendanceController — write data scope', () => {
|
||||
],
|
||||
};
|
||||
|
||||
await controller.batchCreate(dto, req as never);
|
||||
await controller.batchCreate(dto, req);
|
||||
|
||||
expect(attendanceService.assertClassAccess).toHaveBeenCalledWith(21, 8, false);
|
||||
expect(attendanceService.assertClassAccess).toHaveBeenCalledWith(21, 9, false);
|
||||
@@ -232,7 +232,7 @@ describe('AttendanceController — write data scope', () => {
|
||||
],
|
||||
};
|
||||
|
||||
await expect(controller.batchCreate(dto, req as never)).rejects.toBeInstanceOf(
|
||||
await expect(controller.batchCreate(dto, req)).rejects.toBeInstanceOf(
|
||||
ForbiddenException,
|
||||
);
|
||||
expect(attendanceService.batchCreate).not.toHaveBeenCalled();
|
||||
@@ -264,8 +264,8 @@ describe('AttendanceController — write data scope', () => {
|
||||
records: [],
|
||||
});
|
||||
|
||||
await controller.pullLessonAttendance('4', { date: '2026-07-11' }, req as never);
|
||||
await controller.completeLessonAttendance('90', req as never);
|
||||
await controller.pullLessonAttendance('4', { date: '2026-07-11' }, req);
|
||||
await controller.completeLessonAttendance('90', req);
|
||||
|
||||
expect(attendanceService.assertClassAccess).toHaveBeenNthCalledWith(1, 21, 8, false);
|
||||
expect(attendanceService.assertClassAccess).toHaveBeenNthCalledWith(2, 21, 8, false);
|
||||
@@ -274,7 +274,7 @@ describe('AttendanceController — write data scope', () => {
|
||||
it('checks class access before generating attendance from schedules', async () => {
|
||||
attendanceService.generateFromSchedules.mockResolvedValue({ count: 0, records: [] });
|
||||
|
||||
await controller.generateFromSchedules({ classId: 8 }, req as never);
|
||||
await controller.generateFromSchedules({ classId: 8 }, req);
|
||||
|
||||
expect(attendanceService.assertClassAccess).toHaveBeenCalledWith(21, 8, false);
|
||||
});
|
||||
@@ -284,8 +284,8 @@ describe('AttendanceController — write data scope', () => {
|
||||
attendanceService.update.mockResolvedValue({ id: 4, classId: 8, status: 'late' });
|
||||
attendanceService.remove.mockResolvedValue({ deleted: true });
|
||||
|
||||
await controller.update('4', { status: 'late' }, req as never);
|
||||
await controller.remove('4', req as never);
|
||||
await controller.update('4', { status: 'late' }, req);
|
||||
await controller.remove('4', req);
|
||||
|
||||
expect(attendanceService.assertClassAccess).toHaveBeenCalledTimes(2);
|
||||
expect(attendanceService.assertClassAccess).toHaveBeenNthCalledWith(1, 21, 8, false);
|
||||
@@ -323,7 +323,7 @@ describe('AttendanceController — SSE progress scoping', () => {
|
||||
const received: Array<{ phase: string; userId?: number }> = [];
|
||||
const sub = controller.importProgressStream({
|
||||
user: { id: 42, username: 'alice', permissions: ['attendance:view'], isSuperAdmin: false, roles: [] },
|
||||
} as never).subscribe({
|
||||
}).subscribe({
|
||||
next: (e) => received.push(JSON.parse(e.data as string)),
|
||||
});
|
||||
|
||||
@@ -338,7 +338,7 @@ describe('AttendanceController — SSE progress scoping', () => {
|
||||
const received: Array<{ phase: string; userId?: number }> = [];
|
||||
const sub = controller.importProgressStream({
|
||||
user: { id: 42, username: 'alice', permissions: ['attendance:view'], isSuperAdmin: false, roles: [] },
|
||||
} as never).subscribe({
|
||||
}).subscribe({
|
||||
next: (e) => received.push(JSON.parse(e.data as string)),
|
||||
});
|
||||
|
||||
@@ -355,7 +355,7 @@ describe('AttendanceController — SSE progress scoping', () => {
|
||||
const received: Array<{ phase: string; userId?: number }> = [];
|
||||
const sub = controller.importProgressStream({
|
||||
user: { id: 42, username: 'alice', permissions: ['attendance:view'], isSuperAdmin: false, roles: [] },
|
||||
} as never).subscribe({
|
||||
}).subscribe({
|
||||
next: (e) => received.push(JSON.parse(e.data as string)),
|
||||
});
|
||||
progressSubject.next({ phase: 'fetching' }); // no userId
|
||||
|
||||
@@ -68,7 +68,7 @@ export class ClassesService {
|
||||
}
|
||||
|
||||
async findAll(query: QueryClassDto, accessibleClassIds?: number[]) {
|
||||
let where: Record<string, unknown> = {};
|
||||
const where: Record<string, unknown> = {};
|
||||
if (query.status) where.status = query.status;
|
||||
if (query.classType) where.classType = query.classType;
|
||||
if (query.keyword) where.name = Like(`%${query.keyword}%`);
|
||||
|
||||
@@ -326,7 +326,7 @@ describe('ClassroomRentalsService — rental schedule sync', () => {
|
||||
...existingRental,
|
||||
startDate: '2026-04-01',
|
||||
endDate: '2026-04-30',
|
||||
} as ClassroomRental;
|
||||
};
|
||||
const existingSchedule = {
|
||||
id: 50,
|
||||
rentalId: 1,
|
||||
@@ -372,7 +372,7 @@ describe('ClassroomRentalsService — rental schedule sync', () => {
|
||||
status: 'active',
|
||||
lesseeOrganization: { id: 2, name: 'Organization A' } as Organization,
|
||||
} as ClassroomRental;
|
||||
const cancelledRental = { ...rental, status: 'cancelled' } as ClassroomRental;
|
||||
const cancelledRental = { ...rental, status: 'cancelled' };
|
||||
|
||||
rentalRepo.findOne.mockResolvedValueOnce(rental).mockResolvedValueOnce(cancelledRental);
|
||||
|
||||
@@ -449,7 +449,7 @@ describe('ClassroomRentalsService — organization roles', () => {
|
||||
lesseeOrganizationId: 2,
|
||||
startDate: '2026-08-01',
|
||||
endDate: '2026-08-31',
|
||||
} as any);
|
||||
});
|
||||
|
||||
expect(rentalRepo.save).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
|
||||
@@ -32,7 +32,7 @@ describe('DashboardService — teacher class scope', () => {
|
||||
{} as never,
|
||||
{} as never,
|
||||
{} as never,
|
||||
{} as never,
|
||||
{},
|
||||
);
|
||||
|
||||
await service.getClassAttendanceRanking([8, 9]);
|
||||
|
||||
@@ -167,7 +167,7 @@ describe('DatabaseMigrationsService — bootstrap failure handling', () => {
|
||||
{ provide: getDataSourceToken(), useValue: dataSource },
|
||||
],
|
||||
}).compile();
|
||||
const service = module.get(DatabaseMigrationsService) as DatabaseMigrationsService & MigrationsPrivate;
|
||||
const service = module.get(DatabaseMigrationsService);
|
||||
|
||||
jest.spyOn(service, 'ensureAiConfigTable').mockRejectedValue(new Error('migration failed'));
|
||||
const backfill = jest.spyOn(service, 'backfillOrganizations').mockResolvedValue();
|
||||
@@ -228,7 +228,7 @@ describe('DatabaseMigrationsService — protectAttendanceHistory', () => {
|
||||
{ provide: getDataSourceToken(), useValue: dataSource },
|
||||
],
|
||||
}).compile();
|
||||
service = module.get(DatabaseMigrationsService) as DatabaseMigrationsService & MigrationsPrivate;
|
||||
service = module.get(DatabaseMigrationsService);
|
||||
}
|
||||
|
||||
it('skips when attendance_sessions table is absent', async () => {
|
||||
@@ -424,5 +424,5 @@ async function bootstrapCourseAttendance(runner: ReturnType<typeof mockRunner>)
|
||||
{ provide: getDataSourceToken(), useValue: dataSource },
|
||||
],
|
||||
}).compile();
|
||||
service = module.get(DatabaseMigrationsService) as DatabaseMigrationsService & MigrationsPrivate;
|
||||
service = module.get(DatabaseMigrationsService);
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ describe('DingTalkService — queryShifts', () => {
|
||||
accessToken: 'test-token',
|
||||
tokenExpiresAt: Date.now() + 3_600_000,
|
||||
});
|
||||
jest.spyOn(service as never, 'rateLimit').mockResolvedValue(undefined);
|
||||
jest.spyOn(service, 'rateLimit').mockResolvedValue(undefined);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -107,7 +107,7 @@ describe('DingTalkService — attendance machine only group', () => {
|
||||
accessToken: 'test-token',
|
||||
tokenExpiresAt: Date.now() + 3_600_000,
|
||||
});
|
||||
jest.spyOn(service as never, 'rateLimit').mockResolvedValue(undefined);
|
||||
jest.spyOn(service, 'rateLimit').mockResolvedValue(undefined);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
||||
@@ -22,7 +22,7 @@ describe('OrganizationsService — host organization rules', () => {
|
||||
});
|
||||
|
||||
it('does not allow the host organization to be archived', async () => {
|
||||
repo.findOne.mockResolvedValue({ id: 1, name: '本机构', isHost: true } as Organization);
|
||||
repo.findOne.mockResolvedValue({ id: 1, name: '本机构', isHost: true });
|
||||
|
||||
await expect(service.remove(1)).rejects.toBeInstanceOf(BadRequestException);
|
||||
expect(repo.update).not.toHaveBeenCalled();
|
||||
|
||||
@@ -61,7 +61,7 @@ describe('SchedulesController — class data scope', () => {
|
||||
it('checks the requested class before creating a schedule', async () => {
|
||||
service.create.mockResolvedValue({ id: 1, ...scheduleDto });
|
||||
|
||||
await controller.create(scheduleDto, teacherRequest as never);
|
||||
await controller.create(scheduleDto, teacherRequest);
|
||||
|
||||
expect(service.assertClassAccess).toHaveBeenCalledWith(21, 8, false);
|
||||
expect(service.create).toHaveBeenCalledWith(scheduleDto);
|
||||
@@ -71,7 +71,7 @@ describe('SchedulesController — class data scope', () => {
|
||||
service.findOne.mockResolvedValue({ id: 4, ...scheduleDto });
|
||||
service.update.mockResolvedValue({ id: 4, ...scheduleDto, classId: 9 });
|
||||
|
||||
await controller.update('4', { classId: 9 }, teacherRequest as never);
|
||||
await controller.update('4', { classId: 9 }, teacherRequest);
|
||||
|
||||
expect(service.assertClassAccess).toHaveBeenNthCalledWith(1, 21, 8, false);
|
||||
expect(service.assertClassAccess).toHaveBeenNthCalledWith(2, 21, 9, false);
|
||||
@@ -80,7 +80,7 @@ describe('SchedulesController — class data scope', () => {
|
||||
it('checks the owning class before returning full schedule details', async () => {
|
||||
service.findOne.mockResolvedValue({ id: 4, ...scheduleDto });
|
||||
|
||||
await controller.findOne('4', teacherRequest as never);
|
||||
await controller.findOne('4', teacherRequest);
|
||||
|
||||
expect(service.assertClassAccess).toHaveBeenCalledWith(21, 8, false);
|
||||
});
|
||||
@@ -89,7 +89,7 @@ describe('SchedulesController — class data scope', () => {
|
||||
service.findOne.mockResolvedValue({ id: 4, ...scheduleDto });
|
||||
service.remove.mockResolvedValue({ success: true });
|
||||
|
||||
await controller.remove('4', teacherRequest as never);
|
||||
await controller.remove('4', teacherRequest);
|
||||
|
||||
expect(service.assertClassAccess).toHaveBeenCalledWith(21, 8, false);
|
||||
expect(service.remove).toHaveBeenCalledWith(4);
|
||||
@@ -100,7 +100,7 @@ describe('SchedulesController — class data scope', () => {
|
||||
{ id: 2, classId: 99, subject: '英语', teacherId: 7, notes: '隐私', classroomId: 3 },
|
||||
]);
|
||||
|
||||
const result = await controller.getClassroomOccupancy('3', undefined, teacherRequest as never);
|
||||
const result = await controller.getClassroomOccupancy('3', undefined, teacherRequest);
|
||||
|
||||
expect(result).toEqual([
|
||||
expect.objectContaining({
|
||||
@@ -119,7 +119,7 @@ describe('SchedulesController — class data scope', () => {
|
||||
it('rejects records without a class instead of exposing full details to a scoped teacher', async () => {
|
||||
service.findOne.mockResolvedValue({ id: 4, ...scheduleDto, classId: null });
|
||||
|
||||
await expect(controller.findOne('4', teacherRequest as never)).rejects.toBeInstanceOf(
|
||||
await expect(controller.findOne('4', teacherRequest)).rejects.toBeInstanceOf(
|
||||
ForbiddenException,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -199,7 +199,7 @@ describe('ScheduleSyncService — partial batch failure', () => {
|
||||
expect(scheduleUsers).toHaveBeenCalledTimes(2);
|
||||
expect(result.failedBatchCount).toBeGreaterThan(0);
|
||||
expect(result.errors).toBeDefined();
|
||||
expect(result.errors!.length).toBeGreaterThan(0);
|
||||
expect(result.errors.length).toBeGreaterThan(0);
|
||||
// syncedItems should only count the successful batch
|
||||
expect(result.syncedItems).toBeGreaterThan(0);
|
||||
});
|
||||
@@ -287,8 +287,8 @@ describe('ScheduleSyncService — attendance group failure', () => {
|
||||
expect(result.failedItems).toBeGreaterThan(0);
|
||||
// error message must contain the group failure detail
|
||||
expect(result.errors).toBeDefined();
|
||||
expect(result.errors!.some((e) => e.includes('考勤组'))).toBe(true);
|
||||
expect(result.errors!.some((e) => e.includes('强化班'))).toBe(true);
|
||||
expect(result.errors.some((e) => e.includes('考勤组'))).toBe(true);
|
||||
expect(result.errors.some((e) => e.includes('强化班'))).toBe(true);
|
||||
// the successful class should still sync
|
||||
expect(result.syncedItems).toBeGreaterThan(0);
|
||||
expect(result.groupCount).toBe(1);
|
||||
@@ -455,8 +455,8 @@ describe('ScheduleSyncService — all shifts fail', () => {
|
||||
expect(result.failedItems).toBeGreaterThan(0);
|
||||
// Errors must contain shift failure messages
|
||||
expect(result.errors).toBeDefined();
|
||||
expect(result.errors!.length).toBeGreaterThan(0);
|
||||
expect(result.errors!.some((e) => e.includes('班次'))).toBe(true);
|
||||
expect(result.errors.length).toBeGreaterThan(0);
|
||||
expect(result.errors.some((e) => e.includes('班次'))).toBe(true);
|
||||
// No scheduleUsers calls (no group created)
|
||||
expect(dingTalkService.scheduleUsers).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user