feat: 增加工作人员组织联动
This commit is contained in:
@@ -0,0 +1,138 @@
|
||||
/**
|
||||
* 功能:验证工作人员气站与配送点联动策略及页面隔离配置。
|
||||
* 版本: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,
|
||||
} = 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.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,
|
||||
1,
|
||||
'联动配置只能显式启用于工作人员配送点字段',
|
||||
);
|
||||
assert.match(resourcesSource, /filterKey: 'gas_basic_identities'/);
|
||||
assert.match(resourcesSource, /label: '所属气站'/);
|
||||
assert.match(resourcesSource, /label: '所属配送点'/);
|
||||
|
||||
console.log('工作人员气站与配送点联动检查通过');
|
||||
Reference in New Issue
Block a user