feat: 相关问题查询添加问题类型查询
- 查询语句更改:添加type字段 - mapper增添:添加type字段的mapper - 视图模型更改:QuestionListView添加type字段
This commit is contained in:
@ -1,5 +1,51 @@
|
||||
import { describe, expect, test } from 'vitest';
|
||||
import { toProductQuestionView, toQuestionListView } from './questionMapper';
|
||||
import {
|
||||
toProductQuestionView,
|
||||
toQuestionListView,
|
||||
toQuestionTypeView,
|
||||
} from './questionMapper';
|
||||
|
||||
/**
|
||||
* 单元测试: toQuestionTypeView
|
||||
*/
|
||||
describe('toQuestionTypeView', () => {
|
||||
const baseData: QuestionType = {
|
||||
id: 1,
|
||||
translations: [{ id: 1, name: 'Type Name' }],
|
||||
};
|
||||
|
||||
test('convert raw data to QuestionTypeView correctly', () => {
|
||||
const rawData: QuestionType = {
|
||||
...baseData,
|
||||
};
|
||||
|
||||
expect(toQuestionTypeView(rawData)).toEqual({
|
||||
id: '1',
|
||||
type: 'Type Name',
|
||||
});
|
||||
});
|
||||
|
||||
test('convert raw data with missing translations', () => {
|
||||
const rawData: QuestionType = {
|
||||
...baseData,
|
||||
translations: [],
|
||||
};
|
||||
|
||||
expect(toQuestionTypeView(rawData)).toEqual({
|
||||
id: '1',
|
||||
type: '',
|
||||
});
|
||||
});
|
||||
|
||||
test('convert null input to default QuestionTypeView', () => {
|
||||
const rawData: QuestionType | null = null;
|
||||
|
||||
expect(toQuestionTypeView(rawData)).toEqual({
|
||||
id: '',
|
||||
type: '',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* 单元测试: toProductQuestionView
|
||||
@ -43,6 +89,10 @@ describe('toProductQuestionView', () => {
|
||||
describe('toQuestionListView', () => {
|
||||
const baseData: Question = {
|
||||
id: 1,
|
||||
type: {
|
||||
id: 1,
|
||||
translations: [{ id: 1, name: 'Type Name' }],
|
||||
},
|
||||
translations: [
|
||||
{ id: 1, title: 'Question Title', content: 'Question Answer' },
|
||||
],
|
||||
@ -68,6 +118,10 @@ describe('toQuestionListView', () => {
|
||||
|
||||
expect(toQuestionListView(rawData)).toEqual({
|
||||
id: '1',
|
||||
type: {
|
||||
id: '1',
|
||||
type: 'Type Name',
|
||||
},
|
||||
title: 'Question Title',
|
||||
content: 'Question Answer',
|
||||
products: [
|
||||
@ -104,6 +158,10 @@ describe('toQuestionListView', () => {
|
||||
|
||||
expect(toQuestionListView(rawData)).toEqual({
|
||||
id: '1',
|
||||
type: {
|
||||
id: '1',
|
||||
type: 'Type Name',
|
||||
},
|
||||
title: '',
|
||||
content: '',
|
||||
products: [
|
||||
|
||||
Reference in New Issue
Block a user