forked from wangziqi/gongxue-base
test: update attendance service mocks
This commit is contained in:
@@ -21,6 +21,7 @@ const createService = () => {
|
|||||||
create: jest.fn((value: Record<string, unknown>) => ({ id: 90, ...value })),
|
create: jest.fn((value: Record<string, unknown>) => ({ id: 90, ...value })),
|
||||||
save: jest.fn(async (value: unknown) => value),
|
save: jest.fn(async (value: unknown) => value),
|
||||||
};
|
};
|
||||||
|
const attendanceDeviceRepo = { find: jest.fn().mockResolvedValue([]) };
|
||||||
const dataSource = {
|
const dataSource = {
|
||||||
transaction: jest.fn(
|
transaction: jest.fn(
|
||||||
async (cb: (manager: { getRepository: jest.Mock }) => Promise<unknown>) => {
|
async (cb: (manager: { getRepository: jest.Mock }) => Promise<unknown>) => {
|
||||||
@@ -43,9 +44,10 @@ const createService = () => {
|
|||||||
{} as never,
|
{} as never,
|
||||||
{} as never,
|
{} as never,
|
||||||
sessionRepo as never,
|
sessionRepo as never,
|
||||||
|
attendanceDeviceRepo as never,
|
||||||
dataSource as unknown as DataSource,
|
dataSource as unknown as DataSource,
|
||||||
);
|
);
|
||||||
return { service, attendanceRepo, dingRawRepo, scheduleRepo, classStudentRepo, sessionRepo, dataSource };
|
return { service, attendanceRepo, dingRawRepo, scheduleRepo, classStudentRepo, sessionRepo, attendanceDeviceRepo, dataSource };
|
||||||
};
|
};
|
||||||
|
|
||||||
const endedSchedule = {
|
const endedSchedule = {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { Repository } from 'typeorm';
|
|||||||
import { AttendanceService } from './attendance.service';
|
import { AttendanceService } from './attendance.service';
|
||||||
import { AttendanceRecord } from '../entities/attendance-record.entity';
|
import { AttendanceRecord } from '../entities/attendance-record.entity';
|
||||||
import { AttendanceSession } from '../entities/attendance-session.entity';
|
import { AttendanceSession } from '../entities/attendance-session.entity';
|
||||||
|
import { AttendanceDevice } from '../entities/attendance-device.entity';
|
||||||
import { DingAttendanceRaw } from '../entities/ding-attendance-raw.entity';
|
import { DingAttendanceRaw } from '../entities/ding-attendance-raw.entity';
|
||||||
import { Class } from '../entities/class.entity';
|
import { Class } from '../entities/class.entity';
|
||||||
import { Student } from '../entities/student.entity';
|
import { Student } from '../entities/student.entity';
|
||||||
@@ -43,6 +44,7 @@ describe('AttendanceService — batchCreate', () => {
|
|||||||
const mockScheduleRepo = { find: jest.fn().mockResolvedValue([]) };
|
const mockScheduleRepo = { find: jest.fn().mockResolvedValue([]) };
|
||||||
const mockClassStudentRepo = { find: jest.fn().mockResolvedValue([]) };
|
const mockClassStudentRepo = { find: jest.fn().mockResolvedValue([]) };
|
||||||
const mockStudentDingMappingRepo = { find: jest.fn().mockResolvedValue([]) };
|
const mockStudentDingMappingRepo = { find: jest.fn().mockResolvedValue([]) };
|
||||||
|
const mockAttendanceDeviceRepo = { find: jest.fn().mockResolvedValue([]) };
|
||||||
|
|
||||||
const module: TestingModule = await Test.createTestingModule({
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
providers: [
|
providers: [
|
||||||
@@ -56,6 +58,7 @@ describe('AttendanceService — batchCreate', () => {
|
|||||||
{ provide: getRepositoryToken(ClassStudent), useValue: mockClassStudentRepo },
|
{ provide: getRepositoryToken(ClassStudent), useValue: mockClassStudentRepo },
|
||||||
{ provide: getRepositoryToken(ClassTeacher), useValue: { findOne: jest.fn() } },
|
{ provide: getRepositoryToken(ClassTeacher), useValue: { findOne: jest.fn() } },
|
||||||
{ provide: getRepositoryToken(AttendanceSession), useValue: {} },
|
{ provide: getRepositoryToken(AttendanceSession), useValue: {} },
|
||||||
|
{ provide: getRepositoryToken(AttendanceDevice), useValue: mockAttendanceDeviceRepo },
|
||||||
{ provide: getDataSourceToken(), useValue: { transaction: jest.fn() } },
|
{ provide: getDataSourceToken(), useValue: { transaction: jest.fn() } },
|
||||||
],
|
],
|
||||||
}).compile();
|
}).compile();
|
||||||
@@ -136,6 +139,7 @@ describe('AttendanceService — teacher DingTalk class scope', () => {
|
|||||||
classTeacherRepo as never,
|
classTeacherRepo as never,
|
||||||
{} as never,
|
{} as never,
|
||||||
{} as never,
|
{} as never,
|
||||||
|
{} as never,
|
||||||
);
|
);
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
@@ -211,6 +215,7 @@ describe('AttendanceService — DingTalk raw query', () => {
|
|||||||
{} as never,
|
{} as never,
|
||||||
{} as never,
|
{} as never,
|
||||||
{} as never,
|
{} as never,
|
||||||
|
{} as never,
|
||||||
);
|
);
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
@@ -283,6 +288,7 @@ describe('AttendanceService — session serialization', () => {
|
|||||||
{} as never,
|
{} as never,
|
||||||
{} as never,
|
{} as never,
|
||||||
{} as never,
|
{} as never,
|
||||||
|
{ find: jest.fn().mockResolvedValue([]) } as never,
|
||||||
dataSourceMock as never,
|
dataSourceMock as never,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user