UNPKG

focus-product-extractor2

Version:

Extract product information from chat/order data

138 lines (136 loc) 4.11 kB
"use strict"; var _index = _interopRequireDefault(require("../index.js")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } // 测试淘宝平台的不同类型 ID 处理 const tbSkuTest = { "scene": "chat", "platform": "tb", "shopId": "tb_shop_123", "rawData": { "messages": [{ "sender": "buyer", "timestamp": 7, "message": { "type": 1, "sub_type": 6, "sku_id": "7701704245031", "spu_id": "", "order_id": "", "question": "", "origin_data": "", "buyer_enter_msg": { "from": "1", "sku_id": "7701704245031", "spu_id": "", "order_id": "" } } }] } }; const tbOrderTest = { "scene": "chat", "platform": "tb", "shopId": "tb_shop_123", "rawData": { "messages": [{ "sender": "buyer", "timestamp": 7, "message": { "type": 1, "sub_type": 6, "sku_id": "", "spu_id": "", "order_id": "tb_order_789", "question": "", "origin_data": "", "buyer_enter_msg": { "from": "1", "sku_id": "", "spu_id": "", "order_id": "tb_order_789" } } }] } }; const tbSpuTest = { "scene": "chat", "platform": "tb", "shopId": "tb_shop_123", "rawData": { "messages": [{ "sender": "buyer", "timestamp": 7, "message": { "type": 1, "sub_type": 6, "sku_id": "", "spu_id": "tb_spu_456", "order_id": "", "question": "", "origin_data": "", "buyer_enter_msg": { "from": "1", "sku_id": "", "spu_id": "tb_spu_456", "order_id": "" } } }] } }; async function testFieldAssignment() { console.log("=== 测试字段分配功能 ===\n"); // 测试 SKU 类型 console.log("1. 测试 SKU 类型 (应该存储到 goodsId):"); try { const skuResult = await _index.default.process(tbSkuTest); if (skuResult.items.length > 0) { const item = skuResult.items[0]; console.log(` ✅ type: ${item.type}`); console.log(` ✅ goodsId: ${item.goodsId || '未设置'}`); console.log(` ✅ orderId: ${item.orderId || '未设置'}`); console.log(` ✅ spuId: ${item.spuId || '未设置'}`); console.log(` 结果: ${item.goodsId ? '✅ 正确存储到 goodsId' : '❌ 未正确存储'}`); } else { console.log(" ⚠️ 返回空结果"); } } catch (err) { console.log(` ❌ 错误: ${err.message}`); } console.log("\n2. 测试 ORDER 类型 (应该存储到 orderId):"); try { const orderResult = await _index.default.process(tbOrderTest); if (orderResult.items.length > 0) { const item = orderResult.items[0]; console.log(` ✅ type: ${item.type}`); console.log(` ✅ goodsId: ${item.goodsId || '未设置'}`); console.log(` ✅ orderId: ${item.orderId || '未设置'}`); console.log(` ✅ spuId: ${item.spuId || '未设置'}`); console.log(` 结果: ${item.orderId ? '✅ 正确存储到 orderId' : '❌ 未正确存储'}`); } else { console.log(" ⚠️ 返回空结果"); } } catch (err) { console.log(` ❌ 错误: ${err.message}`); } console.log("\n3. 测试 SPU 类型 (应该存储到 spuId):"); try { const spuResult = await _index.default.process(tbSpuTest); if (spuResult.items.length > 0) { const item = spuResult.items[0]; console.log(` ✅ type: ${item.type}`); console.log(` ✅ goodsId: ${item.goodsId || '未设置'}`); console.log(` ✅ orderId: ${item.orderId || '未设置'}`); console.log(` ✅ spuId: ${item.spuId || '未设置'}`); console.log(` 结果: ${item.spuId ? '✅ 正确存储到 spuId' : '❌ 未正确存储'}`); } else { console.log(" ⚠️ 返回空结果"); } } catch (err) { console.log(` ❌ 错误: ${err.message}`); } console.log("\n=== 测试完成 ==="); } testFieldAssignment();