All checks were successful
deploy to server / build-and-deploy (push) Successful in 2m56s
114 lines
2.3 KiB
TypeScript
114 lines
2.3 KiB
TypeScript
import { describe, expect, test } from 'vitest';
|
|
|
|
/**
|
|
* 单元测试: toProductQuestionView
|
|
*/
|
|
describe('toProductQuestionView', () => {
|
|
test('convert raw data to ProductQuestionView correctly', () => {
|
|
const rawData: Question = {
|
|
id: 1,
|
|
translations: [
|
|
{ id: 1, title: 'Question Title', content: 'Question Answer' },
|
|
],
|
|
};
|
|
|
|
expect(toProductQuestionView(rawData)).toEqual({
|
|
id: 1,
|
|
title: 'Question Title',
|
|
content: 'Question Answer',
|
|
});
|
|
});
|
|
|
|
test('convert raw data with missing translations', () => {
|
|
const rawData: Question = {
|
|
id: 1,
|
|
translations: [],
|
|
};
|
|
|
|
expect(toProductQuestionView(rawData)).toEqual({
|
|
id: 1,
|
|
title: '',
|
|
content: '',
|
|
});
|
|
});
|
|
});
|
|
|
|
/**
|
|
* 单元测试: toQuestionListView
|
|
*/
|
|
describe('toQuestionListView', () => {
|
|
test('convert raw data to QuestionListView correctly', () => {
|
|
const rawData: Question = {
|
|
id: 1,
|
|
translations: [
|
|
{ id: 1, title: 'Question Title', content: 'Question Answer' },
|
|
],
|
|
products: [
|
|
{
|
|
id: 1,
|
|
products_id: {
|
|
id: 1,
|
|
translations: [{ id: 1, name: 'Product Name' }],
|
|
product_type: {
|
|
id: 1,
|
|
translations: [{ id: 1, name: 'Type Name' }],
|
|
},
|
|
},
|
|
},
|
|
],
|
|
};
|
|
|
|
expect(toQuestionListView(rawData)).toEqual({
|
|
id: 1,
|
|
title: 'Question Title',
|
|
content: 'Question Answer',
|
|
products: [
|
|
{
|
|
id: 1,
|
|
name: 'Product Name',
|
|
type: {
|
|
id: 1,
|
|
name: 'Type Name',
|
|
},
|
|
},
|
|
],
|
|
});
|
|
});
|
|
|
|
test('convert raw data with missing translations', () => {
|
|
const rawData: Question = {
|
|
id: 1,
|
|
translations: [],
|
|
products: [
|
|
{
|
|
id: 1,
|
|
products_id: {
|
|
id: 1,
|
|
translations: [],
|
|
product_type: {
|
|
id: 1,
|
|
translations: [],
|
|
},
|
|
},
|
|
},
|
|
],
|
|
};
|
|
|
|
expect(toQuestionListView(rawData)).toEqual({
|
|
id: 1,
|
|
title: '',
|
|
content: '',
|
|
products: [
|
|
{
|
|
id: 1,
|
|
name: '',
|
|
type: {
|
|
id: 1,
|
|
name: '',
|
|
},
|
|
},
|
|
],
|
|
});
|
|
});
|
|
});
|