refactor: 重构解决方案相关Mapper

- 空值处理与类型控制:为关系型字段添加空值处理与类型控制逻辑
- 目录结构调整:分离SolutionList与Solution相关的Mapper为不同的文件
This commit is contained in:
2025-12-04 17:40:04 +08:00
parent 1245df497b
commit 63c3e2e364
5 changed files with 170 additions and 112 deletions

View File

@ -1,56 +1,5 @@
import { describe, test, expect } from 'vitest';
import { toSolutionListView, toSolutionView } from './solutionMapper';
/**
* 单元测试: toSolutionListView
*/
describe('toSolutionListView', () => {
const baseData: Solution = {
id: 1,
translations: [
{ id: 1, title: 'Solution Title', summary: 'Solution Summary' },
],
type: {
id: 1,
translations: [{ id: 1, name: 'Type Name' }],
sort: 1,
},
};
test('convert raw data to SolutionListView correctly', () => {
const rawData: Solution = { ...baseData };
expect(toSolutionListView(rawData)).toEqual({
id: '1',
title: 'Solution Title',
summary: 'Solution Summary',
solution_type: {
id: '1',
name: 'Type Name',
sort: 1,
},
cover: '',
});
});
test('convert raw data with missing translations', () => {
const rawData: Solution = {
...baseData,
translations: [],
};
expect(toSolutionListView(rawData)).toEqual({
id: '1',
title: '',
summary: '',
solution_type: {
id: '1',
name: 'Type Name',
sort: 1,
},
cover: '',
});
});
});
import { toSolutionView } from './solutionMapper';
/**
* 单元测试: toSolutionView