UNPKG

focus-product-extractor2

Version:

Extract product information from chat/order data

155 lines (151 loc) 4.93 kB
"use strict"; var _index = _interopRequireDefault(require("../index.js")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } // 测试 Shopee 进线商品 (只有 spu_id,应该返回 spu 类型) const shopeeSpuTest = { "scene": "chat", "platform": "shopee", "shopId": "276033032", "rawData": { "messages": [{ "sender": "system", "timestamp": 1630000000, "message": { "buyer_enter_msg": { "from": 1, "order_id": "", "sku_id": "", "spu_id": "22261730607" }, "order_id": "", "origin_data": "", "question": "", "sku_id": "", "spu_id": "22261730607", "sub_type": 6, "type": 1 } }] } }; // 测试 Shopee 进线订单 (有 order_id 和 spu_id,应该返回 order 类型) const shopeeOrderTest = { "scene": "chat", "platform": "shopee", "shopId": "276033032", "rawData": { "messages": [{ "sender": "system", "timestamp": 1630000000, "message": { "buyer_enter_msg": { "from": 2, "order_id": "202879018217031", "sku_id": "", "spu_id": "29951359055" }, "order_id": "202879018217031", "origin_data": "", "question": "", "sku_id": "", "spu_id": "29951359055", "sub_type": 6, "type": 1 } }] } }; // 测试 Shopee 商品卡片 (只有 spu_id,应该返回 spu 类型) const shopeeCardTest = { "scene": "chat", "platform": "shopee", "shopId": "276033032", "rawData": { "messages": [{ "sender": "system", "timestamp": 1630000000, "message": { "card_msg": { "data": [{ "wares": { "list": [{ "currency": -1, "desc": "", "image_url": "", "num": 0, "price": 0, "title": "Test Product", "ware_url": "" }], "type": 4 } }] }, "order_id": "", "origin_data": "", "question": "", "sku_id": "", "spu_id": "28308051952", "sub_type": 4, "type": 1 } }] } }; async function testShopeeTypes() { console.log("=== 测试 Shopee 平台类型处理 ===\n"); // 测试 SPU 类型 (只有 spu_id) console.log("1. 测试 Shopee SPU 类型 (只有 spu_id,应该返回 spu 类型):"); try { const spuResult = await _index.default.process(shopeeSpuTest); console.log(" 完整结果:", JSON.stringify(spuResult, null, 4)); 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.type === 'spu' && item.spuId ? '✅ 正确' : '❌ 错误'}`); } else { console.log(" ⚠️ 返回空结果"); } } catch (err) { console.log(` ❌ 错误: ${err.message}`); } console.log("\n2. 测试 Shopee ORDER 类型 (有 order_id 和 spu_id,应该返回 order 类型):"); try { const orderResult = await _index.default.process(shopeeOrderTest); console.log(" 完整结果:", JSON.stringify(orderResult, null, 4)); 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.type === 'order' && item.orderId ? '✅ 正确' : '❌ 错误'}`); } else { console.log(" ⚠️ 返回空结果"); } } catch (err) { console.log(` ❌ 错误: ${err.message}`); } console.log("\n3. 测试 Shopee 卡片 SPU 类型 (卡片消息只有 spu_id):"); try { const cardResult = await _index.default.process(shopeeCardTest); console.log(" 完整结果:", JSON.stringify(cardResult, null, 4)); if (cardResult.items.length > 0) { const item = cardResult.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.type === 'spu' && item.spuId ? '✅ 正确' : '❌ 错误'}`); } else { console.log(" ⚠️ 返回空结果"); } } catch (err) { console.log(` ❌ 错误: ${err.message}`); } console.log("\n=== 测试完成 ==="); } testShopeeTypes();