90 lines
2.9 KiB
TypeScript
90 lines
2.9 KiB
TypeScript
import { ArchiveService } from './archive.service';
|
|
|
|
describe('ArchiveService.getProfile', () => {
|
|
it('returns the admission archive under the public result field', async () => {
|
|
const student = { id: 7, name: '测试学生' };
|
|
const result = {
|
|
id: 3,
|
|
studentId: 7,
|
|
cultureFinalScore: 450,
|
|
admittedCollege: '测试学院',
|
|
};
|
|
|
|
const studentRepo = { findOne: jest.fn().mockResolvedValue(student) };
|
|
const profileRepo = { findOne: jest.fn().mockResolvedValue(null) };
|
|
const enrollmentRepo = { find: jest.fn().mockResolvedValue([]) };
|
|
const examScoreRepo = { find: jest.fn().mockResolvedValue([]) };
|
|
const learningRecordRepo = { find: jest.fn().mockResolvedValue([]) };
|
|
const resultRepo = { findOne: jest.fn().mockResolvedValue(result) };
|
|
const attachmentRepo = { find: jest.fn().mockResolvedValue([]) };
|
|
const attendanceRepo = { find: jest.fn().mockResolvedValue([]) };
|
|
|
|
const service = new ArchiveService(
|
|
studentRepo as never,
|
|
profileRepo as never,
|
|
enrollmentRepo as never,
|
|
examScoreRepo as never,
|
|
learningRecordRepo as never,
|
|
resultRepo as never,
|
|
attachmentRepo as never,
|
|
attendanceRepo as never,
|
|
{} as never,
|
|
);
|
|
|
|
const response = await service.getProfile(7);
|
|
|
|
expect(response).toMatchObject({ student, result, attendances: [] });
|
|
expect(response).not.toHaveProperty('resultArchive');
|
|
});
|
|
|
|
it('将学生可空字符串字段归一化为空串,避免前端校验报格式异常', async () => {
|
|
const student = {
|
|
id: 7,
|
|
name: '测试学生',
|
|
phone: null,
|
|
idNumber: null,
|
|
studentNo: null,
|
|
gender: null,
|
|
ethnicity: null,
|
|
emergencyContact: null,
|
|
emergencyPhone: null,
|
|
supervisor: null,
|
|
};
|
|
const emptyRepos = {
|
|
profile: { findOne: jest.fn().mockResolvedValue(null) },
|
|
enrollment: { find: jest.fn().mockResolvedValue([]) },
|
|
exam: { find: jest.fn().mockResolvedValue([]) },
|
|
learning: { find: jest.fn().mockResolvedValue([]) },
|
|
result: { findOne: jest.fn().mockResolvedValue(null) },
|
|
attachment: { find: jest.fn().mockResolvedValue([]) },
|
|
attendance: { find: jest.fn().mockResolvedValue([]) },
|
|
};
|
|
const service = new ArchiveService(
|
|
{ findOne: jest.fn().mockResolvedValue(student) } as never,
|
|
emptyRepos.profile as never,
|
|
emptyRepos.enrollment as never,
|
|
emptyRepos.exam as never,
|
|
emptyRepos.learning as never,
|
|
emptyRepos.result as never,
|
|
emptyRepos.attachment as never,
|
|
emptyRepos.attendance as never,
|
|
{} as never,
|
|
);
|
|
|
|
const response = await service.getProfile(7);
|
|
|
|
expect(response.student).toMatchObject({
|
|
id: 7,
|
|
name: '测试学生',
|
|
phone: '',
|
|
idNumber: '',
|
|
studentNo: '',
|
|
gender: '',
|
|
ethnicity: '',
|
|
emergencyContact: '',
|
|
emergencyPhone: '',
|
|
supervisor: '',
|
|
});
|
|
});
|
|
});
|