统一平台、气站和配送点后台的服务关系业务名称展示。 新增气站、配送点、服务人员三级联动及暂未分配语义。 后端补充组织归属、人员角色和启用状态的严格校验。 补充前后端测试、项目文档、操作日志及本机日志忽略规则。
172 lines
4.7 KiB
JavaScript
172 lines
4.7 KiB
JavaScript
/**
|
||
* 功能:验证工作人员气站与配送点联动策略及页面隔离配置。
|
||
* 版本:v1.0.0
|
||
*/
|
||
import assert from 'node:assert/strict';
|
||
import { readFile } from 'node:fs/promises';
|
||
import { transformWithOxc } from 'vite';
|
||
|
||
const policyURL = new URL(
|
||
'../src/views/resource/resource-relation-linkage-policy.ts',
|
||
import.meta.url,
|
||
);
|
||
const source = await readFile(policyURL, 'utf8');
|
||
const transformed = await transformWithOxc(source, policyURL.pathname);
|
||
const moduleURL = `data:text/javascript;base64,${Buffer.from(transformed.code).toString('base64')}`;
|
||
const {
|
||
createRelationRequestVersionGuard,
|
||
linkedRelationFilters,
|
||
linkedRelationValidationMessage,
|
||
optionParentIdentity,
|
||
shouldClearLinkedOption,
|
||
staffOrganizationFilters,
|
||
staffOrganizationValidationMessage,
|
||
} = await import(moduleURL);
|
||
|
||
const gasA = 'gas-a';
|
||
const gasB = 'gas-b';
|
||
const deliveryA = { identity: 'delivery-a', gas_basic_identity: gasA };
|
||
const platformDelivery = {
|
||
identity: 'delivery-platform',
|
||
gas_basic_identity: '',
|
||
};
|
||
|
||
assert.equal(
|
||
optionParentIdentity(deliveryA, 'gas_basic_identity'),
|
||
gasA,
|
||
'普通配送点必须能回填所属气站',
|
||
);
|
||
|
||
assert.deepEqual(staffOrganizationFilters(gasA, 'delivery-a'), {
|
||
gas_basic_identities: gasA,
|
||
delivery_basic_identities: 'delivery-a',
|
||
});
|
||
assert.deepEqual(staffOrganizationFilters('', ''), {
|
||
gas_basic_unassigned: '1',
|
||
delivery_basic_unassigned: '1',
|
||
});
|
||
const staffA = {
|
||
identity: 'staff-a',
|
||
gas_basic_identity: gasA,
|
||
delivery_basic_identity: 'delivery-a',
|
||
};
|
||
assert.equal(
|
||
staffOrganizationValidationMessage(gasA, 'delivery-a', 'staff-a', staffA),
|
||
'',
|
||
);
|
||
assert.match(
|
||
staffOrganizationValidationMessage(gasB, 'delivery-a', 'staff-a', staffA),
|
||
/不属于当前气站/,
|
||
);
|
||
assert.match(
|
||
staffOrganizationValidationMessage(gasA, '', 'staff-a', staffA),
|
||
/不属于当前配送点/,
|
||
);
|
||
assert.match(
|
||
staffOrganizationValidationMessage(gasA, 'delivery-a', 'staff-a', undefined),
|
||
/无法确认/,
|
||
);
|
||
assert.equal(
|
||
optionParentIdentity(platformDelivery, 'gas_basic_identity'),
|
||
'',
|
||
'平台主管配送点必须保持气站为空',
|
||
);
|
||
|
||
assert.equal(
|
||
shouldClearLinkedOption(gasA, deliveryA, 'gas_basic_identity'),
|
||
false,
|
||
'同一气站的配送点必须保留',
|
||
);
|
||
assert.equal(
|
||
shouldClearLinkedOption(gasB, deliveryA, 'gas_basic_identity'),
|
||
true,
|
||
'切换到其他气站必须清空原配送点',
|
||
);
|
||
assert.equal(
|
||
shouldClearLinkedOption('', deliveryA, 'gas_basic_identity'),
|
||
true,
|
||
'清空气站时必须清空普通配送点',
|
||
);
|
||
assert.equal(
|
||
shouldClearLinkedOption('', platformDelivery, 'gas_basic_identity'),
|
||
false,
|
||
'清空气站时允许保留平台主管配送点',
|
||
);
|
||
assert.equal(
|
||
shouldClearLinkedOption(gasA, platformDelivery, 'gas_basic_identity'),
|
||
true,
|
||
'选择气站时平台主管配送点不应作为其直属配送点保留',
|
||
);
|
||
assert.equal(
|
||
shouldClearLinkedOption(gasA, undefined, 'gas_basic_identity'),
|
||
false,
|
||
'无法加载配送点记录时不得误清当前值',
|
||
);
|
||
|
||
assert.match(
|
||
linkedRelationValidationMessage(
|
||
gasB,
|
||
'delivery-a',
|
||
deliveryA,
|
||
'gas_basic_identity',
|
||
),
|
||
/不属于所属气站/,
|
||
);
|
||
assert.match(
|
||
linkedRelationValidationMessage(
|
||
gasA,
|
||
'delivery-platform',
|
||
platformDelivery,
|
||
'gas_basic_identity',
|
||
),
|
||
/平台主管配送点/,
|
||
);
|
||
assert.match(
|
||
linkedRelationValidationMessage(
|
||
'',
|
||
'delivery-a',
|
||
deliveryA,
|
||
'gas_basic_identity',
|
||
),
|
||
/确认所属气站/,
|
||
);
|
||
assert.equal(
|
||
linkedRelationValidationMessage(
|
||
gasA,
|
||
'delivery-a',
|
||
deliveryA,
|
||
'gas_basic_identity',
|
||
),
|
||
'',
|
||
);
|
||
assert.deepEqual(linkedRelationFilters(gasA, 'gas_basic_identities'), {
|
||
gas_basic_identities: gasA,
|
||
});
|
||
assert.equal(
|
||
linkedRelationFilters('', 'gas_basic_identities'),
|
||
undefined,
|
||
'未选气站时允许查询全部配送点,包括平台主管配送点',
|
||
);
|
||
|
||
const requestGuard = createRelationRequestVersionGuard();
|
||
const firstRequest = requestGuard.begin('/delivery_basic');
|
||
const secondRequest = requestGuard.begin('/delivery_basic');
|
||
assert.equal(requestGuard.isLatest('/delivery_basic', firstRequest), false);
|
||
assert.equal(requestGuard.isLatest('/delivery_basic', secondRequest), true);
|
||
|
||
const resourcesSource = await readFile(
|
||
new URL('../src/api/resources.ts', import.meta.url),
|
||
'utf8',
|
||
);
|
||
assert.equal(
|
||
(resourcesSource.match(/relationLinkage:/g) ?? []).length,
|
||
2,
|
||
'联动配置必须显式启用于工作人员和用户服务关系的配送点字段',
|
||
);
|
||
assert.match(resourcesSource, /filterKey: 'gas_basic_identities'/);
|
||
assert.match(resourcesSource, /organizationScoped: true/);
|
||
assert.match(resourcesSource, /label: '所属气站'/);
|
||
assert.match(resourcesSource, /label: '所属配送点'/);
|
||
|
||
console.log('工作人员气站与配送点联动检查通过');
|