test: 为mapper补充测试
All checks were successful
deploy to server / build-and-deploy (push) Successful in 2m56s
All checks were successful
deploy to server / build-and-deploy (push) Successful in 2m56s
This commit is contained in:
88
app/models/mappers/solutionMapper.test.ts
Normal file
88
app/models/mappers/solutionMapper.test.ts
Normal file
@ -0,0 +1,88 @@
|
||||
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' }],
|
||||
},
|
||||
};
|
||||
|
||||
expect(toSolutionListView(rawData)).toEqual({
|
||||
id: 1,
|
||||
title: 'Solution Title',
|
||||
summary: 'Solution Summary',
|
||||
solution_type: 'Type Name',
|
||||
});
|
||||
});
|
||||
|
||||
test('convert raw data with missing translations', () => {
|
||||
const rawData: Solution = {
|
||||
id: 1,
|
||||
translations: [],
|
||||
type: {
|
||||
id: 1,
|
||||
translations: [],
|
||||
},
|
||||
};
|
||||
|
||||
expect(toSolutionListView(rawData)).toEqual({
|
||||
id: 1,
|
||||
title: '',
|
||||
summary: '',
|
||||
solution_type: '',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* 单元测试: 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',
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user