32 lines
1.6 KiB
JavaScript
32 lines
1.6 KiB
JavaScript
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('ERP-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);
|
||
});
|