169 lines
4.9 KiB
JavaScript
169 lines
4.9 KiB
JavaScript
'use strict';
|
|
|
|
/**
|
|
* `storage.stockout.*` 与奇门发货主单(`wms_order_delivery_*` / `JYCK` 等)的语义、默认筛选
|
|
* 不在本任务范围;相关集成验收放到独立任务与对应表/接口后再补。
|
|
*/
|
|
|
|
const assert = require('node:assert/strict');
|
|
const {
|
|
getAuthToken,
|
|
invokeSystemMethod,
|
|
} = require('../../support/system_method_client');
|
|
|
|
const EXTRA_HEADERS = {
|
|
platform: 'web',
|
|
project: 'all',
|
|
};
|
|
|
|
const TEST_WAREHOUSE_ID = 100000;
|
|
|
|
function normalizeListPayload(data) {
|
|
if (data && Array.isArray(data.list)) return data;
|
|
if (data && data.data && Array.isArray(data.data.list)) return data.data;
|
|
return null;
|
|
}
|
|
|
|
async function switchToWarehouseRoleWithDeliveryData(token) {
|
|
let currentToken = token;
|
|
|
|
const infoRes = await invokeSystemMethod('user.info', {}, currentToken, EXTRA_HEADERS);
|
|
assert.equal(infoRes.status, 200);
|
|
assert.equal(infoRes.body.flag, 'success');
|
|
assert.equal(infoRes.body.code, 200);
|
|
|
|
const employees = Array.isArray(infoRes.body?.data?.employees) ? infoRes.body.data.employees : [];
|
|
const preferredWarehouseRoles = employees.filter(item =>
|
|
item
|
|
&& item.role_type === 'warehouse'
|
|
&& Number(item.id)
|
|
&& Number(item.store_id) === TEST_WAREHOUSE_ID
|
|
);
|
|
|
|
const candidateRoleIds = [ ...new Set(preferredWarehouseRoles.map(item => Number(item.id)).filter(Boolean)) ];
|
|
|
|
assert.ok(candidateRoleIds.length > 0, '当前账号没有固定测试仓角色');
|
|
|
|
for (const roleId of candidateRoleIds) {
|
|
const changeRes = await invokeSystemMethod('user.changeRole', {
|
|
roleId,
|
|
}, currentToken, EXTRA_HEADERS);
|
|
|
|
if (changeRes.status !== 200 || changeRes.body?.flag !== 'success' || changeRes.body?.code !== 200) {
|
|
continue;
|
|
}
|
|
|
|
currentToken = changeRes.body?.data?.token || currentToken;
|
|
|
|
const statsRes = await invokeSystemMethod('order.stats', {
|
|
where: {},
|
|
}, currentToken, EXTRA_HEADERS);
|
|
|
|
if (statsRes.status !== 200 || statsRes.body?.flag !== 'success' || statsRes.body?.code !== 200) {
|
|
continue;
|
|
}
|
|
|
|
const total = Number(statsRes.body?.data?.total || 0);
|
|
if (total > 0) {
|
|
return {
|
|
token: currentToken,
|
|
roleId,
|
|
total,
|
|
};
|
|
}
|
|
}
|
|
|
|
throw new Error('未找到有订单数据的仓库角色');
|
|
}
|
|
|
|
async function getEntryContextForRemovedMethods(token) {
|
|
const listRes = await invokeSystemMethod('storage.entry.list', {
|
|
pagination: {
|
|
page: 1,
|
|
pageSize: 1,
|
|
},
|
|
where: {},
|
|
}, token, EXTRA_HEADERS);
|
|
|
|
assert.equal(listRes.status, 200);
|
|
assert.equal(listRes.body.flag, 'success');
|
|
assert.equal(listRes.body.code, 200);
|
|
|
|
const payload = normalizeListPayload(listRes.body.data);
|
|
const entry = payload && Array.isArray(payload.list)
|
|
? [ ...payload.list ].sort((left, right) => Number(left?.id || 0) - Number(right?.id || 0))[0]
|
|
: null;
|
|
|
|
if (!entry || !entry.id) {
|
|
return {
|
|
orderId: 1,
|
|
detailId: 1,
|
|
itemCode: `SKU-${Date.now().toString().slice(-6)}`,
|
|
};
|
|
}
|
|
|
|
const getRes = await invokeSystemMethod('storage.entry.get', {
|
|
id: Number(entry.id),
|
|
}, token, EXTRA_HEADERS);
|
|
|
|
assert.equal(getRes.status, 200);
|
|
assert.equal(getRes.body.flag, 'success');
|
|
assert.equal(getRes.body.code, 200);
|
|
|
|
const entryOrder = getRes.body?.data?.entryOrder || {};
|
|
const firstItem = Array.isArray(entryOrder?.items)
|
|
? [ ...entryOrder.items ].sort((left, right) => Number(left?.id || 0) - Number(right?.id || 0))[0]
|
|
: null;
|
|
|
|
return {
|
|
orderId: Number(entry.id),
|
|
detailId: Number(firstItem?.id || 1),
|
|
itemCode: String(firstItem?.item_code || firstItem?.stock?.item_code || `SKU-${Date.now().toString().slice(-6)}`),
|
|
};
|
|
}
|
|
|
|
describe('test/app/controller/system.storage.delivery.module.test.js', function() {
|
|
this.timeout(120000);
|
|
|
|
it('should not expose removed storage.entry detail methods', async () => {
|
|
const { token } = await getAuthToken();
|
|
const switched = await switchToWarehouseRoleWithDeliveryData(token);
|
|
const entryContext = await getEntryContextForRemovedMethods(switched.token);
|
|
|
|
const removedMethods = [
|
|
{
|
|
method: 'storage.entry.addDetail',
|
|
body: {
|
|
order_id: entryContext.orderId,
|
|
count: 1,
|
|
item_code: entryContext.itemCode,
|
|
inventory_type: 'ZP',
|
|
},
|
|
},
|
|
{
|
|
method: 'storage.entry.deleteDetail',
|
|
body: {
|
|
id: entryContext.detailId,
|
|
},
|
|
},
|
|
{
|
|
method: 'storage.entry.detailChange',
|
|
body: {
|
|
id: entryContext.detailId,
|
|
count: 2,
|
|
item_code: entryContext.itemCode,
|
|
},
|
|
},
|
|
];
|
|
|
|
for (const { method, body } of removedMethods) {
|
|
const res = await invokeSystemMethod(method, body, switched.token, EXTRA_HEADERS);
|
|
const isLegacySuccess = res.status === 200
|
|
&& res.body?.flag === 'success'
|
|
&& Number(res.body?.code) === 200;
|
|
|
|
assert.ok(!isLegacySuccess, `${method} 仍然返回 success 200: ${JSON.stringify(res.body)}`);
|
|
}
|
|
});
|
|
});
|