All checks were successful
deploy to server / build-and-deploy (push) Successful in 3m1s
- 为SolutionType添加Sort字段用于排序 - 解决方案列表按照sort升序排序
99 lines
2.1 KiB
TypeScript
99 lines
2.1 KiB
TypeScript
import { describe, test, expect } from 'vitest';
|
|
|
|
/**
|
|
* 单元测试: toSolutionListView
|
|
*/
|
|
describe('toSolutionListView', () => {
|
|
test('convert raw data to SolutionListView correctly', () => {
|
|
const rawData: Solution = {
|
|
id: 1,
|
|
translations: [
|
|
{ id: 1, title: 'Solution Title', summary: 'Solution Summary' },
|
|
],
|
|
type: {
|
|
id: 1,
|
|
translations: [{ id: 1, name: 'Type Name' }],
|
|
sort: 1,
|
|
},
|
|
};
|
|
|
|
expect(toSolutionListView(rawData)).toEqual({
|
|
id: 1,
|
|
title: 'Solution Title',
|
|
summary: 'Solution Summary',
|
|
solution_type: {
|
|
id: 1,
|
|
name: 'Type Name',
|
|
sort: 1,
|
|
},
|
|
});
|
|
});
|
|
|
|
test('convert raw data with missing translations', () => {
|
|
const rawData: Solution = {
|
|
id: 1,
|
|
translations: [],
|
|
type: {
|
|
id: 1,
|
|
translations: [],
|
|
sort: null,
|
|
},
|
|
};
|
|
|
|
expect(toSolutionListView(rawData)).toEqual({
|
|
id: 1,
|
|
title: '',
|
|
summary: '',
|
|
solution_type: {
|
|
id: 1,
|
|
name: '',
|
|
sort: 999,
|
|
},
|
|
});
|
|
});
|
|
});
|
|
|
|
/**
|
|
* 单元测试: toSolutionView
|
|
*/
|
|
describe('toSolutionView', () => {
|
|
test('convert raw data to SolutionView correctly', () => {
|
|
const rawData: Solution = {
|
|
id: 1,
|
|
translations: [
|
|
{
|
|
id: 1,
|
|
title: 'Solution Title',
|
|
summary: 'Solution Summary',
|
|
content: 'Solution Content',
|
|
},
|
|
],
|
|
create_at: '2023-01-01T00:00:00Z',
|
|
};
|
|
|
|
expect(toSolutionView(rawData)).toEqual({
|
|
id: 1,
|
|
title: 'Solution Title',
|
|
summary: 'Solution Summary',
|
|
content: 'Solution Content',
|
|
createAt: '2023-01-01T00:00:00Z',
|
|
});
|
|
});
|
|
|
|
test('convert raw data with missing translations', () => {
|
|
const rawData: Solution = {
|
|
id: 1,
|
|
translations: [],
|
|
create_at: '2023-01-01T00:00:00Z',
|
|
};
|
|
|
|
expect(toSolutionView(rawData)).toEqual({
|
|
id: 1,
|
|
title: '',
|
|
summary: '',
|
|
content: '',
|
|
createAt: '2023-01-01T00:00:00Z',
|
|
});
|
|
});
|
|
});
|