Merge pull request '修复考勤服务测试 mock' (#17)

This commit is contained in:
2026-07-16 03:01:59 +00:00
2 changed files with 9 additions and 1 deletions

View File

@@ -21,6 +21,7 @@ const createService = () => {
create: jest.fn((value: Record<string, unknown>) => ({ id: 90, ...value })),
save: jest.fn(async (value: unknown) => value),
};
const attendanceDeviceRepo = { find: jest.fn().mockResolvedValue([]) };
const dataSource = {
transaction: jest.fn(
async (cb: (manager: { getRepository: jest.Mock }) => Promise<unknown>) => {
@@ -43,9 +44,10 @@ const createService = () => {
{} as never,
{} as never,
sessionRepo as never,
attendanceDeviceRepo as never,
dataSource as unknown as DataSource,
);
return { service, attendanceRepo, dingRawRepo, scheduleRepo, classStudentRepo, sessionRepo, dataSource };
return { service, attendanceRepo, dingRawRepo, scheduleRepo, classStudentRepo, sessionRepo, attendanceDeviceRepo, dataSource };
};
const endedSchedule = {

View File

@@ -6,6 +6,7 @@ import { Repository } from 'typeorm';
import { AttendanceService } from './attendance.service';
import { AttendanceRecord } from '../entities/attendance-record.entity';
import { AttendanceSession } from '../entities/attendance-session.entity';
import { AttendanceDevice } from '../entities/attendance-device.entity';
import { DingAttendanceRaw } from '../entities/ding-attendance-raw.entity';
import { Class } from '../entities/class.entity';
import { Student } from '../entities/student.entity';
@@ -43,6 +44,7 @@ describe('AttendanceService — batchCreate', () => {
const mockScheduleRepo = { find: jest.fn().mockResolvedValue([]) };
const mockClassStudentRepo = { find: jest.fn().mockResolvedValue([]) };
const mockStudentDingMappingRepo = { find: jest.fn().mockResolvedValue([]) };
const mockAttendanceDeviceRepo = { find: jest.fn().mockResolvedValue([]) };
const module: TestingModule = await Test.createTestingModule({
providers: [
@@ -56,6 +58,7 @@ describe('AttendanceService — batchCreate', () => {
{ provide: getRepositoryToken(ClassStudent), useValue: mockClassStudentRepo },
{ provide: getRepositoryToken(ClassTeacher), useValue: { findOne: jest.fn() } },
{ provide: getRepositoryToken(AttendanceSession), useValue: {} },
{ provide: getRepositoryToken(AttendanceDevice), useValue: mockAttendanceDeviceRepo },
{ provide: getDataSourceToken(), useValue: { transaction: jest.fn() } },
],
}).compile();
@@ -136,6 +139,7 @@ describe('AttendanceService — teacher DingTalk class scope', () => {
classTeacherRepo as never,
{} as never,
{} as never,
{} as never,
);
beforeEach(() => {
@@ -211,6 +215,7 @@ describe('AttendanceService — DingTalk raw query', () => {
{} as never,
{} as never,
{} as never,
{} as never,
);
await expect(
@@ -283,6 +288,7 @@ describe('AttendanceService — session serialization', () => {
{} as never,
{} as never,
{} as never,
{ find: jest.fn().mockResolvedValue([]) } as never,
dataSourceMock as never,
);
}