'use strict'; const test = require('node:test'); const assert = require('node:assert/strict'); const { hasBuyingIntent, looksLikeLead, missingLeadContacts, detectLanguage, appendLeadFollowup, alreadyAsksForLead } = require('../src/lead-intent'); test('lead-intent: product + quantity is buying intent', () => { assert.equal(hasBuyingIntent('I want 500 pieces of stainless steel rings'), true); assert.equal(hasBuyingIntent('Do you have rings?'), false); }); test('lead-intent: missing company/contact', () => { assert.deepEqual(missingLeadContacts({}), ['company', 'contact']); assert.deepEqual(missingLeadContacts({ company: 'ACME', email: 'a@b.com' }), []); }); test('lead-intent: localized followup appended once', () => { const lang = detectLanguage('我想采购500件戒指'); assert.equal(lang, 'zh'); const out = appendLeadFollowup('好的,这里有几款戒指。', lang); assert.match(out, /公司名称/); assert.equal(appendLeadFollowup(out, lang), out); }); test('lead-intent: detects existing ask in reply', () => { assert.equal(alreadyAsksForLead('Could you share your company name and email?'), true); assert.equal(alreadyAsksForLead('Here are some rings.'), false); }); test('lead-intent: company/contact signal counts as a lead even without unit-quantity', () => { // 单位不规整(500 stainless steel rings)时 hasBuyingIntent 为 false,但已是明确线索 assert.equal(hasBuyingIntent('We are Acme GmbH, contact Anna Klein. We need 500 stainless steel rings.'), false); assert.equal(looksLikeLead('We are Acme GmbH, contact Anna Klein. We need 500 stainless steel rings.'), true); assert.equal(looksLikeLead('Our company is Test Buyer BV, contact name Jan Jansen.'), false); // 没有商品词 assert.equal(looksLikeLead('Do you have rings?'), false); // 没有公司/联系人信号 });