54 lines
2.0 KiB
TypeScript
54 lines
2.0 KiB
TypeScript
|
|
import { ProductService } from './services/ProductService';
|
||
|
|
import db from './config/database';
|
||
|
|
import { DomainBootstrap } from './core/runtime/DomainBootstrap';
|
||
|
|
import { DomainRegistry } from './core/runtime/DomainRegistry';
|
||
|
|
|
||
|
|
async function testWasher() {
|
||
|
|
console.log('🚀 Testing AI Product Washer (BIZ_PROD_12)...');
|
||
|
|
|
||
|
|
try {
|
||
|
|
// 1. 初始化全量领域 (包含 Feature Flags, Product 表等)
|
||
|
|
await DomainBootstrap.init();
|
||
|
|
await DomainRegistry.bootstrap();
|
||
|
|
|
||
|
|
const tenantId = 'test-tenant';
|
||
|
|
// 1. 创建测试商品
|
||
|
|
const productId = await ProductService.create(tenantId, {
|
||
|
|
platform: 'Alibaba',
|
||
|
|
productId: 'TEST_WASHER_001',
|
||
|
|
title: 'Original Title with Brand Name Nike and bad characters !!!',
|
||
|
|
description: 'This is a description that needs localization for the Middle East market.',
|
||
|
|
mainImage: 'https://example.com/original_nike_shoe.jpg',
|
||
|
|
status: 'active'
|
||
|
|
});
|
||
|
|
console.log(`✅ Created test product: ${productId}`);
|
||
|
|
|
||
|
|
// 2. 执行清洗与本地化
|
||
|
|
console.log('--- Running Wash and Localize ---');
|
||
|
|
const result = await ProductService.washAndLocalize(tenantId, productId, 'Middle East', 'en');
|
||
|
|
|
||
|
|
console.log('✅ Washer result:', JSON.stringify(result, null, 2));
|
||
|
|
|
||
|
|
// 3. 验证更新后的数据
|
||
|
|
const updatedProduct = await ProductService.getById(tenantId, productId);
|
||
|
|
console.log('--- Updated Product Data ---');
|
||
|
|
console.log('New Title:', updatedProduct?.title);
|
||
|
|
console.log('New Image:', updatedProduct?.mainImage);
|
||
|
|
console.log('SEO Tags:', updatedProduct?.attributes?.seo_tags);
|
||
|
|
|
||
|
|
if (updatedProduct?.title?.includes('[Local]')) {
|
||
|
|
console.log('✅ Semantic cleaning and localization verified (Mock)');
|
||
|
|
}
|
||
|
|
if (updatedProduct?.mainImage?.includes('style=Gold & Luxury')) {
|
||
|
|
console.log('✅ Multi-modal enhancement (style) verified');
|
||
|
|
}
|
||
|
|
|
||
|
|
} catch (error) {
|
||
|
|
console.error('❌ Test failed:', error);
|
||
|
|
} finally {
|
||
|
|
await db.destroy();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
testWasher();
|