29 lines
1.2 KiB
JavaScript
29 lines
1.2 KiB
JavaScript
'use strict';
|
|
|
|
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const { hasBuyingIntent, 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);
|
|
});
|