test: 优化测试代码
All checks were successful
deploy to server / build-and-deploy (push) Successful in 3m5s
All checks were successful
deploy to server / build-and-deploy (push) Successful in 3m5s
- 显式导入相关依赖以避免相关问题
This commit is contained in:
77
server/utils/search-converters.test.ts
Normal file
77
server/utils/search-converters.test.ts
Normal file
@ -0,0 +1,77 @@
|
||||
import { describe, expect, test } from 'vitest';
|
||||
import { converters } from './search-converters';
|
||||
|
||||
/**
|
||||
* 单元测试: converters
|
||||
*/
|
||||
describe('converters', () => {
|
||||
test('convert product item', () => {
|
||||
const item = {
|
||||
id: 1,
|
||||
name: 'Hydraulic Pump',
|
||||
summary: 'High efficiency',
|
||||
description: 'Detailed description',
|
||||
type: 'pump',
|
||||
};
|
||||
const result = converters.products(item);
|
||||
expect(result).toEqual({
|
||||
id: 1,
|
||||
type: 'product',
|
||||
title: 'Hydraulic Pump',
|
||||
summary: 'High efficiency',
|
||||
});
|
||||
});
|
||||
|
||||
test('convert solution item', () => {
|
||||
const item = {
|
||||
id: 1,
|
||||
title: 'Solution A',
|
||||
summary: 'Effective solution',
|
||||
content: 'Detailed content',
|
||||
type: 'Type A',
|
||||
};
|
||||
const result = converters.solutions(item);
|
||||
expect(result).toEqual({
|
||||
id: 1,
|
||||
type: 'solution',
|
||||
title: 'Solution A',
|
||||
summary: 'Effective solution',
|
||||
});
|
||||
});
|
||||
|
||||
test('convert question item', () => {
|
||||
const item = {
|
||||
id: 1,
|
||||
title: 'How to use product?',
|
||||
content:
|
||||
'This is a detailed explanation of how to use the product effectively.',
|
||||
products: ['Product A'],
|
||||
product_types: ['Type A'],
|
||||
};
|
||||
const result = converters.questions(item);
|
||||
expect(result).toEqual({
|
||||
id: 1,
|
||||
title: 'How to use product?',
|
||||
summary:
|
||||
'This is a detailed explanation of how to use the product effectively....',
|
||||
type: 'question',
|
||||
});
|
||||
});
|
||||
|
||||
test('convert product document item', () => {
|
||||
const item = {
|
||||
id: 1,
|
||||
title: 'User Manual',
|
||||
products: ['Product A'],
|
||||
product_types: ['Type A'],
|
||||
fileUUID: 'TEST-UUID',
|
||||
};
|
||||
const result = converters.product_documents(item);
|
||||
expect(result).toEqual({
|
||||
id: 'TEST-UUID',
|
||||
title: 'User Manual',
|
||||
summary: '',
|
||||
type: 'document',
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user