Files
LWLT-AIBOT/tools/erp-account-identity.test.mjs
2026-09-07 20:21:09 +08:00

32 lines
1.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import { createRequire } from 'node:module';
import test from 'node:test';
const require = createRequire(import.meta.url);
const identity = require('../chrome-extension/ltjt-order-assistant/erp-account-identity.js');
test('ERP account identity comparison accepts only normalized exact equality', () => {
assert.equal(identity.exactErpAccountIdentityMatch('测试AI员工账号', ' 测试ai员工账号 '), true);
assert.equal(identity.exactErpAccountIdentityMatch('-01', 'erp-01'), true);
assert.equal(identity.exactErpAccountIdentityMatch('测试 AI', '测试 ai'), true);
});
test('ERP account identity comparison rejects substrings and blank identities', () => {
assert.equal(identity.exactErpAccountIdentityMatch('测试', '测试ai员工账号'), false);
assert.equal(identity.exactErpAccountIdentityMatch('admin', 'erp-admin-01'), false);
assert.equal(identity.exactErpAccountIdentityMatch('', ''), false);
assert.equal(identity.exactErpAccountIdentityMatch('employee', ''), false);
});
test('ERP session probe reads the unique login label and never matches against whole-page text', () => {
const background = readFileSync(
new URL('../chrome-extension/ltjt-order-assistant/background.js', import.meta.url),
'utf8'
);
assert.match(background, /document\.querySelectorAll\('#Lable_UserName'\)/u);
assert.match(background, /accountNodes\.length === 1/u);
assert.match(background, /exactErpAccountIdentityMatch/u);
assert.doesNotMatch(background, /bodyText\.includes\(expectedAccount\)/u);
});