Files
jinshen-website/server/utils/search-converters.test.ts
R2m1liA f1398a5545 feat: 为搜索条目添加细分类型
- 类型细分:有原先的四大分类添加细分类型,例如产品(原纸分切机)
- 接口调整:原先的type分类改为sectionType并将type作为细分类型使用
2025-12-05 16:49:09 +08:00

87 lines
2.1 KiB
TypeScript

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',
cover: 'rand-om__-uuid-1234',
};
const result = converters.products(item);
expect(result).toEqual({
id: 1,
sectionType: 'product',
title: 'Hydraulic Pump',
summary: 'High efficiency',
type: 'pump',
thumbnail: '/api/assets/rand-om__-uuid-1234',
});
});
test('convert solution item', () => {
const item = {
id: 1,
title: 'Solution A',
summary: 'Effective solution',
content: 'Detailed content',
type: 'Type A',
cover: 'rand-om__-uuid-5678',
};
const result = converters.solutions(item);
expect(result).toEqual({
id: 1,
sectionType: 'solution',
title: 'Solution A',
summary: 'Effective solution',
type: 'Type A',
thumbnail: '/api/assets/rand-om__-uuid-5678',
});
});
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'],
type: 'Question Type',
};
const result = converters.questions(item);
expect(result).toEqual({
id: 1,
title: 'How to use product?',
summary: undefined,
type: 'Question Type',
sectionType: 'question',
});
});
test('convert product document item', () => {
const item = {
id: 1,
title: 'User Manual',
products: ['Product A'],
product_types: ['Type A'],
fileUUID: 'TEST-UUID',
type: 'manual',
};
const result = converters.product_documents(item);
expect(result).toEqual({
id: 'TEST-UUID',
title: 'User Manual',
summary: undefined,
sectionType: 'document',
type: 'manual',
});
});
});