focus-product-extractor2
Version:
Extract product information from chat/order data
130 lines (128 loc) • 3.29 kB
JavaScript
;
var _index = _interopRequireDefault(require("../index.js"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
// 测试优先级的专门用例
const priorityTestCases = [{
name: "同时有skuId和orderId - 应该优先skuId",
data: {
"scene": "chat",
"platform": "shopee",
"shopId": "276033032",
"rawData": {
"messages": [{
"sender": "system",
"timestamp": 1630000000,
"message": {
"sku_id": "111111",
"order_id": "222222",
"spu_id": "",
"sub_type": 6,
"type": 1
}
}]
}
},
expected: {
type: "sku",
goodsId: "111111"
}
}, {
name: "同时有skuId和spuId - 应该优先skuId",
data: {
"scene": "chat",
"platform": "shopee",
"shopId": "276033032",
"rawData": {
"messages": [{
"sender": "system",
"timestamp": 1630000000,
"message": {
"sku_id": "333333",
"order_id": "",
"spu_id": "444444",
"sub_type": 6,
"type": 1
}
}]
}
},
expected: {
type: "sku",
goodsId: "333333"
}
}, {
name: "同时有orderId和spuId - 应该优先orderId",
data: {
"scene": "chat",
"platform": "shopee",
"shopId": "276033032",
"rawData": {
"messages": [{
"sender": "system",
"timestamp": 1630000000,
"message": {
"sku_id": "",
"order_id": "555555",
"spu_id": "666666",
"sub_type": 6,
"type": 1
}
}]
}
},
expected: {
type: "order",
goodsId: "555555"
}
}, {
name: "三个ID都有 - 应该优先skuId",
data: {
"scene": "chat",
"platform": "shopee",
"shopId": "276033032",
"rawData": {
"messages": [{
"sender": "system",
"timestamp": 1630000000,
"message": {
"sku_id": "777777",
"order_id": "888888",
"spu_id": "999999",
"sub_type": 6,
"type": 1
}
}]
}
},
expected: {
type: "sku",
goodsId: "777777"
}
}];
// 执行测试
console.log("开始测试优先级逻辑(skuId > orderId > spuId)...\n");
for (let i = 0; i < priorityTestCases.length; i++) {
const testCase = priorityTestCases[i];
console.log(`测试 ${i + 1}: ${testCase.name}`);
try {
const result = await _index.default.process(testCase.data);
if (result.items && result.items.length > 0) {
const actualType = result.items[0].type;
const actualGoodsId = result.items[0].goodsId;
const expectedType = testCase.expected.type;
const expectedGoodsId = testCase.expected.goodsId;
if (actualType === expectedType && actualGoodsId === expectedGoodsId) {
console.log(`✅ 通过 - type: ${actualType}, goodsId: ${actualGoodsId}`);
} else {
console.log(`❌ 失败 - 期望: type=${expectedType}, goodsId=${expectedGoodsId}`);
console.log(` 实际: type=${actualType}, goodsId=${actualGoodsId}`);
}
} else {
console.log(`❌ 失败 - 没有提取到结果`);
}
} catch (error) {
console.log(`❌ 错误 - ${error.message}`);
}
console.log("");
}
console.log("优先级测试完成!");