574 lines
24 KiB
JavaScript
574 lines
24 KiB
JavaScript
'use strict';
|
|
|
|
const assert = require('node:assert/strict');
|
|
const { app } = require('egg-mock/bootstrap');
|
|
const {
|
|
getAuthToken,
|
|
invokeSystemMethod,
|
|
} = require('../../support/system_method_client');
|
|
|
|
const EXTRA_HEADERS = {
|
|
platform: 'web',
|
|
project: 'all',
|
|
};
|
|
|
|
/**
|
|
* 从列表中选出固定的测试签约关系。
|
|
* @param {Array<object>} relations 签约关系列表。
|
|
* @return {object|null} 固定测试关系,找不到时返回空。
|
|
*/
|
|
function pickFixedTestRelation(relations) {
|
|
if (!Array.isArray(relations)) {
|
|
return null;
|
|
}
|
|
|
|
return relations.find(item => Number(item.store_id) === 1000000 && Number(item.warehouse_id) === 100000)
|
|
|| null;
|
|
}
|
|
|
|
/**
|
|
* 确保指定 AppKey 存在对应的奇门应用记录。
|
|
*
|
|
* @param {string} appKey 奇门应用 AppKey。
|
|
* @param {string} customerId 客户标识。
|
|
* @return {Promise<boolean>} 是否为本次测试新建的记录。
|
|
*/
|
|
async function ensureQimenAppRecord(appKey, customerId) {
|
|
const existing = await app.model.QimenApp.findOne({
|
|
where: {
|
|
app_key: appKey,
|
|
},
|
|
});
|
|
|
|
if (existing) {
|
|
return false;
|
|
}
|
|
|
|
await app.model.QimenApp.create({
|
|
name: `autotest_qimen_app_${Date.now()}`,
|
|
app_key: appKey,
|
|
customer_id: customerId,
|
|
});
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* 删除测试创建的奇门应用记录。
|
|
*
|
|
* @param {string} appKey 奇门应用 AppKey。
|
|
* @return {Promise<void>} 无返回值。
|
|
*/
|
|
async function removeQimenAppRecord(appKey) {
|
|
if (!appKey) {
|
|
return;
|
|
}
|
|
|
|
await app.model.QimenApp.destroy({
|
|
where: {
|
|
app_key: appKey,
|
|
},
|
|
});
|
|
}
|
|
|
|
describe('test/app/controller/system.setting.storeWarehouse.test.js', () => {
|
|
const METHOD_PREFIX = 'storeWarehouse.store';
|
|
let token = '';
|
|
let sampleRelation = null;
|
|
|
|
before(async () => {
|
|
const auth = await getAuthToken({ forceLogin: true });
|
|
token = auth.token;
|
|
});
|
|
|
|
it('should list store-warehouse contracts in current subject scope', async () => {
|
|
const res = await invokeSystemMethod(`${METHOD_PREFIX}.list`, {
|
|
page: 1,
|
|
page_size: 10,
|
|
}, token, EXTRA_HEADERS);
|
|
|
|
assert.equal(res.status, 200);
|
|
assert.equal(res.body.flag, 'success');
|
|
assert.equal(res.body.code, 200);
|
|
assert.ok(Array.isArray(res.body?.data?.list), 'list 应返回数组');
|
|
assert.ok(res.body?.data?.current_subject, '应返回当前主体信息');
|
|
sampleRelation = pickFixedTestRelation(res.body?.data?.list);
|
|
assert.ok(sampleRelation, '未找到固定测试仓/测试货主对应关系');
|
|
});
|
|
|
|
it('should allow renaming current-side remask and reflect it in list display', async () => {
|
|
assert.ok(sampleRelation, '需要至少一条现有签约关系用于改名回归');
|
|
|
|
const listRes = await invokeSystemMethod(`${METHOD_PREFIX}.list`, {
|
|
page: 1,
|
|
page_size: 30,
|
|
}, token, EXTRA_HEADERS);
|
|
|
|
assert.equal(listRes.status, 200);
|
|
assert.equal(listRes.body.flag, 'success');
|
|
assert.equal(listRes.body.code, 200);
|
|
|
|
const currentRole = String(listRes.body?.data?.current_subject?.role || '');
|
|
const candidates = Array.isArray(listRes.body?.data?.list) ? listRes.body.data.list : [];
|
|
const candidate = pickFixedTestRelation(candidates);
|
|
assert.ok(candidate, '未找到固定测试仓/测试货主对应关系,无法改名回归');
|
|
|
|
const isWarehouse = currentRole === 'warehouse';
|
|
const originRemask = String(candidate.remask || '');
|
|
const nextRemask = `autotest_alias_${Date.now()}`;
|
|
|
|
try {
|
|
const renameRes = await invokeSystemMethod(`${METHOD_PREFIX}.rename`, {
|
|
id: Number(candidate.id),
|
|
remask: nextRemask,
|
|
}, token, EXTRA_HEADERS);
|
|
|
|
assert.equal(renameRes.status, 200);
|
|
assert.equal(renameRes.body.flag, 'success');
|
|
assert.equal(renameRes.body.code, 200);
|
|
assert.equal(String(renameRes.body?.data?.contract?.remask), nextRemask);
|
|
assert.equal(
|
|
String(isWarehouse ? renameRes.body?.data?.contract?.store_name : renameRes.body?.data?.contract?.warehouse_name),
|
|
nextRemask
|
|
);
|
|
|
|
const verifyRes = await invokeSystemMethod(`${METHOD_PREFIX}.list`, {
|
|
id: Number(candidate.id),
|
|
}, token, EXTRA_HEADERS);
|
|
|
|
assert.equal(verifyRes.status, 200);
|
|
assert.equal(verifyRes.body.flag, 'success');
|
|
assert.equal(verifyRes.body.code, 200);
|
|
|
|
const verified = Array.isArray(verifyRes.body?.data?.list) ? verifyRes.body.data.list[0] : null;
|
|
assert.ok(verified, '改名后应能查到对应签约关系');
|
|
assert.equal(
|
|
String(isWarehouse ? verified.store_name : verified.warehouse_name),
|
|
nextRemask
|
|
);
|
|
} finally {
|
|
await invokeSystemMethod(`${METHOD_PREFIX}.rename`, {
|
|
id: Number(candidate.id),
|
|
remask: originRemask,
|
|
}, token, EXTRA_HEADERS);
|
|
}
|
|
});
|
|
|
|
it('should generate a temp code and support preview before confirmation', async () => {
|
|
assert.ok(sampleRelation, '需要至少一条现有签约关系用于临时码回归');
|
|
|
|
const initRes = await invokeSystemMethod(`${METHOD_PREFIX}.sign`, {
|
|
store_id: 1000000,
|
|
warehouse_id: 100000,
|
|
apply_reason: 'autotest temp sign flow',
|
|
remask: `autotest_remask_${Date.now()}`,
|
|
}, token, EXTRA_HEADERS);
|
|
|
|
assert.equal(initRes.status, 200);
|
|
assert.equal(initRes.body.flag, 'success');
|
|
assert.equal(initRes.body.code, 200);
|
|
assert.equal(initRes.body?.data?.mode, 'initiate');
|
|
assert.ok(String(initRes.body?.data?.temp_code || '').length >= 8, '发起签约后应返回临时码');
|
|
|
|
const previewRes = await invokeSystemMethod(`${METHOD_PREFIX}.sign`, {
|
|
temp_code: initRes.body.data.temp_code,
|
|
action: 'preview',
|
|
}, token, EXTRA_HEADERS);
|
|
|
|
assert.equal(previewRes.status, 200);
|
|
assert.equal(previewRes.body.flag, 'success');
|
|
assert.equal(previewRes.body.code, 200);
|
|
assert.equal(previewRes.body?.data?.mode, 'preview');
|
|
assert.equal(String(previewRes.body?.data?.temp_code || ''), String(initRes.body?.data?.temp_code || ''));
|
|
assert.equal(Boolean(previewRes.body?.data?.can_confirm), false, '同一发起方不应直接确认自己的临时码');
|
|
});
|
|
|
|
it('should only change use_status when unbinding', async () => {
|
|
assert.ok(sampleRelation, '需要至少一条现有签约关系用于解除回归');
|
|
|
|
const originalAuthStatus = Number(sampleRelation.auth_status || 0);
|
|
const originalUseStatus = Number(sampleRelation.use_status || 0);
|
|
const targetUseStatus = originalUseStatus === 1 ? 0 : 1;
|
|
|
|
try {
|
|
const unbindRes = await invokeSystemMethod(`${METHOD_PREFIX}.unbind`, {
|
|
id: Number(sampleRelation.id),
|
|
use_status: targetUseStatus,
|
|
}, token, EXTRA_HEADERS);
|
|
|
|
assert.equal(unbindRes.status, 200);
|
|
assert.equal(unbindRes.body.flag, 'success');
|
|
assert.equal(unbindRes.body.code, 200);
|
|
assert.equal(Number(unbindRes.body?.data?.contract?.use_status), targetUseStatus);
|
|
assert.equal(Number(unbindRes.body?.data?.contract?.auth_status), originalAuthStatus, '解除接口不应改动 auth_status');
|
|
} finally {
|
|
await invokeSystemMethod(`${METHOD_PREFIX}.unbind`, {
|
|
id: Number(sampleRelation.id),
|
|
use_status: originalUseStatus,
|
|
}, token, EXTRA_HEADERS);
|
|
}
|
|
});
|
|
|
|
it('should allow warehouse side to save and get policy config on a contract', async function() {
|
|
const listRes = await invokeSystemMethod(`${METHOD_PREFIX}.list`, {
|
|
page: 1,
|
|
page_size: 30,
|
|
}, token, EXTRA_HEADERS);
|
|
|
|
assert.equal(listRes.status, 200);
|
|
assert.equal(listRes.body.flag, 'success');
|
|
assert.equal(listRes.body.code, 200);
|
|
|
|
const currentRole = String(listRes.body?.data?.current_subject?.role || '');
|
|
if (currentRole !== 'warehouse') {
|
|
this.skip();
|
|
}
|
|
|
|
const candidates = Array.isArray(listRes.body?.data?.list) ? listRes.body.data.list : [];
|
|
const candidate = pickFixedTestRelation(candidates);
|
|
assert.ok(candidate, '未找到固定测试仓/测试货主对应关系,无法做策略配置回归');
|
|
|
|
const originalPolicyConfig = candidate.policy_config && typeof candidate.policy_config === 'object'
|
|
? (() => {
|
|
const nextOriginalPolicyConfig = { ...candidate.policy_config };
|
|
delete nextOriginalPolicyConfig.sku_visibility;
|
|
return nextOriginalPolicyConfig;
|
|
})()
|
|
: null;
|
|
const nextPolicyConfig = {
|
|
receive_mode: 'strict',
|
|
auto_allocate_bin: 1,
|
|
auto_allocate_express: 1,
|
|
auto_allocate_storage: 1,
|
|
storage_separation: 1,
|
|
allow_mix_batch: 0,
|
|
max_daily_inbound: 5000,
|
|
need_order_approval: 1,
|
|
enable_external_express_code: 1,
|
|
remark: `autotest_${Date.now()}`,
|
|
};
|
|
|
|
try {
|
|
const saveRes = await invokeSystemMethod(`${METHOD_PREFIX}.savePolicyConfig`, {
|
|
id: Number(candidate.id),
|
|
policy_config: nextPolicyConfig,
|
|
}, token, EXTRA_HEADERS);
|
|
|
|
assert.equal(saveRes.status, 200);
|
|
assert.equal(saveRes.body.flag, 'success');
|
|
assert.equal(saveRes.body.code, 200);
|
|
assert.equal(Number(saveRes.body?.data?.contract_id || 0), Number(candidate.id));
|
|
assert.equal(String(saveRes.body?.data?.policy_config?.receive_mode || ''), 'strict');
|
|
assert.equal(Number(saveRes.body?.data?.policy_config?.auto_allocate_bin || 0), 1);
|
|
assert.equal(Number(saveRes.body?.data?.policy_config?.auto_allocate_express || 0), 1, '保存后 auto_allocate_express 应为 1');
|
|
assert.equal(Number(saveRes.body?.data?.policy_config?.auto_allocate_storage || 0), 1, '保存后 auto_allocate_storage 应为 1');
|
|
assert.equal(Number(saveRes.body?.data?.policy_config?.storage_separation || 0), 1, '保存后 storage_separation 应为 1');
|
|
assert.equal(Number(saveRes.body?.data?.policy_config?.need_order_approval || 0), 1, '保存后 need_order_approval 应为 1');
|
|
assert.equal(Number(saveRes.body?.data?.policy_config?.enable_external_express_code || 0), 1, '保存后 enable_external_express_code 应为 1');
|
|
|
|
const getRes = await invokeSystemMethod(`${METHOD_PREFIX}.getPolicyConfig`, {
|
|
id: Number(candidate.id),
|
|
}, token, EXTRA_HEADERS);
|
|
|
|
assert.equal(getRes.status, 200);
|
|
assert.equal(getRes.body.flag, 'success');
|
|
assert.equal(getRes.body.code, 200);
|
|
assert.equal(Number(getRes.body?.data?.contract_id || 0), Number(candidate.id));
|
|
assert.equal(
|
|
Number(getRes.body?.data?.contract?.print_quantity_locked || 0),
|
|
Number(candidate.print_quantity_locked || 0)
|
|
);
|
|
assert.equal(Number(getRes.body?.data?.policy_config?.max_daily_inbound || 0), 5000);
|
|
assert.equal(Number(getRes.body?.data?.policy_config?.auto_allocate_express || 0), 1, '读取后 auto_allocate_express 应为 1');
|
|
assert.equal(Number(getRes.body?.data?.policy_config?.auto_allocate_storage || 0), 1, '读取后 auto_allocate_storage 应为 1');
|
|
assert.equal(Number(getRes.body?.data?.policy_config?.storage_separation || 0), 1, '读取后 storage_separation 应为 1');
|
|
assert.equal(Number(getRes.body?.data?.policy_config?.need_order_approval || 0), 1, '读取后 need_order_approval 应为 1');
|
|
assert.equal(Number(getRes.body?.data?.policy_config?.enable_external_express_code || 0), 1, '读取后 enable_external_express_code 应为 1');
|
|
|
|
const policyConfigWithoutExternalExpress = { ...nextPolicyConfig };
|
|
delete policyConfigWithoutExternalExpress.enable_external_express_code;
|
|
|
|
const saveDefaultRes = await invokeSystemMethod(`${METHOD_PREFIX}.savePolicyConfig`, {
|
|
id: Number(candidate.id),
|
|
policy_config: policyConfigWithoutExternalExpress,
|
|
}, token, EXTRA_HEADERS);
|
|
|
|
assert.equal(saveDefaultRes.status, 200);
|
|
assert.equal(saveDefaultRes.body.flag, 'success');
|
|
assert.equal(saveDefaultRes.body.code, 200);
|
|
assert.equal(Number(saveDefaultRes.body?.data?.policy_config?.enable_external_express_code || 0), 0, '未传 enable_external_express_code 时应默认关闭');
|
|
|
|
const getDefaultRes = await invokeSystemMethod(`${METHOD_PREFIX}.getPolicyConfig`, {
|
|
id: Number(candidate.id),
|
|
}, token, EXTRA_HEADERS);
|
|
|
|
assert.equal(getDefaultRes.status, 200);
|
|
assert.equal(getDefaultRes.body.flag, 'success');
|
|
assert.equal(getDefaultRes.body.code, 200);
|
|
assert.equal(Number(getDefaultRes.body?.data?.policy_config?.enable_external_express_code || 0), 0, '读取时缺省 enable_external_express_code 应视为关闭');
|
|
} finally {
|
|
if (originalPolicyConfig) {
|
|
await invokeSystemMethod(`${METHOD_PREFIX}.savePolicyConfig`, {
|
|
id: Number(candidate.id),
|
|
policy_config: originalPolicyConfig,
|
|
}, token, EXTRA_HEADERS);
|
|
}
|
|
}
|
|
});
|
|
|
|
it('should reject unsupported policy config fields on a contract', async function() {
|
|
const listRes = await invokeSystemMethod(`${METHOD_PREFIX}.list`, {
|
|
page: 1,
|
|
page_size: 30,
|
|
}, token, EXTRA_HEADERS);
|
|
|
|
assert.equal(listRes.status, 200);
|
|
assert.equal(listRes.body.flag, 'success');
|
|
assert.equal(listRes.body.code, 200);
|
|
|
|
const currentRole = String(listRes.body?.data?.current_subject?.role || '');
|
|
if (currentRole !== 'warehouse') {
|
|
this.skip();
|
|
}
|
|
|
|
const candidates = Array.isArray(listRes.body?.data?.list) ? listRes.body.data.list : [];
|
|
const candidate = pickFixedTestRelation(candidates);
|
|
assert.ok(candidate, '未找到固定测试仓/测试货主对应关系,无法做策略字段限制回归');
|
|
|
|
const res = await invokeSystemMethod(`${METHOD_PREFIX}.savePolicyConfig`, {
|
|
id: Number(candidate.id),
|
|
policy_config: {
|
|
receive_mode: 'strict',
|
|
unexpected_field: 'blocked',
|
|
},
|
|
}, token, EXTRA_HEADERS);
|
|
|
|
assert.equal(res.status, 200);
|
|
assert.equal(res.body.flag, 'failure');
|
|
assert.equal(Number(res.body.code), 400);
|
|
assert.match(String(res.body.message || ''), /unexpected_field|不支持字段/);
|
|
});
|
|
|
|
it('should allow warehouse side to save, update and delete api config on a contract', async function() {
|
|
const listRes = await invokeSystemMethod(`${METHOD_PREFIX}.list`, {
|
|
page: 1,
|
|
page_size: 30,
|
|
}, token, EXTRA_HEADERS);
|
|
|
|
assert.equal(listRes.status, 200);
|
|
assert.equal(listRes.body.flag, 'success');
|
|
assert.equal(listRes.body.code, 200);
|
|
|
|
const currentRole = String(listRes.body?.data?.current_subject?.role || '');
|
|
if (currentRole !== 'warehouse') {
|
|
this.skip();
|
|
}
|
|
|
|
const candidates = Array.isArray(listRes.body?.data?.list) ? listRes.body.data.list : [];
|
|
const candidate = pickFixedTestRelation(candidates);
|
|
assert.ok(candidate, '未找到固定测试仓/测试货主对应关系,无法做接口配置回归');
|
|
|
|
const originalApiConfig = candidate.api_config || candidate.apiConfig || null;
|
|
const seed = Date.now();
|
|
const createdCustomerId = `autotest_customer_db_${seed}`;
|
|
const updatedCustomerId = `${createdCustomerId}_updated`;
|
|
const ignoredCustomerId = `autotest_customer_external_${seed}`;
|
|
const restoreAppKey = originalApiConfig?.qimen_app_key || '';
|
|
let createdQimenApp = false;
|
|
let createdRestoreQimenApp = false;
|
|
const createPayload = {
|
|
id: Number(candidate.id),
|
|
interface_type_id: Number((originalApiConfig && originalApiConfig.interface_type_id) || 0) || undefined,
|
|
app_name: `autotest_api_${seed}`,
|
|
qimen_app_key: `autotest_app_${seed}`,
|
|
qimen_warehouse_code: `autotest_wh_${seed}`,
|
|
contact_person: 'autotest',
|
|
contact_phone: '13800138000',
|
|
email: `autotest_${seed}@example.com`,
|
|
is_enabled: 1,
|
|
};
|
|
|
|
try {
|
|
createdQimenApp = await ensureQimenAppRecord(createPayload.qimen_app_key, createdCustomerId);
|
|
if (restoreAppKey && String(originalApiConfig?.qimen_customer_id || '').trim()) {
|
|
createdRestoreQimenApp = await ensureQimenAppRecord(restoreAppKey, String(originalApiConfig.qimen_customer_id || '').trim());
|
|
}
|
|
|
|
const saveRes = await invokeSystemMethod(`${METHOD_PREFIX}.saveApiConfig`, createPayload, token, EXTRA_HEADERS);
|
|
assert.equal(saveRes.status, 200);
|
|
assert.equal(saveRes.body.flag, 'success');
|
|
assert.equal(saveRes.body.code, 200);
|
|
assert.match(String(saveRes.body?.data?.action || ''), /create|update/);
|
|
|
|
const savedApiConfig = saveRes.body?.data?.api_config || saveRes.body?.data?.apiConfig || saveRes.body?.data?.qimen_config || null;
|
|
assert.ok(savedApiConfig, '保存后应返回 api_config');
|
|
assert.equal(String(savedApiConfig?.qimen_app_key || ''), createPayload.qimen_app_key);
|
|
assert.equal(String(savedApiConfig?.qimen_customer_id || ''), createdCustomerId);
|
|
assert.equal(String(savedApiConfig?.qimen_warehouse_code || ''), createPayload.qimen_warehouse_code);
|
|
|
|
await app.model.QimenApp.update({
|
|
customer_id: updatedCustomerId,
|
|
}, {
|
|
where: {
|
|
app_key: createPayload.qimen_app_key,
|
|
},
|
|
});
|
|
|
|
const updatePayload = {
|
|
...createPayload,
|
|
interface_type_id: Number((savedApiConfig && savedApiConfig.interface_type_id) || createPayload.interface_type_id || 0) || undefined,
|
|
app_name: `${createPayload.app_name}_updated`,
|
|
qimen_customer_id: ignoredCustomerId,
|
|
qimen_warehouse_code: `${createPayload.qimen_warehouse_code}_updated`,
|
|
is_enabled: 0,
|
|
};
|
|
const updateRes = await invokeSystemMethod(`${METHOD_PREFIX}.saveApiConfig`, updatePayload, token, EXTRA_HEADERS);
|
|
assert.equal(updateRes.status, 200);
|
|
assert.equal(updateRes.body.flag, 'success');
|
|
assert.equal(updateRes.body.code, 200);
|
|
assert.equal(String(updateRes.body?.data?.action || ''), 'update');
|
|
|
|
const updatedApiConfig = updateRes.body?.data?.api_config || updateRes.body?.data?.apiConfig || updateRes.body?.data?.qimen_config || null;
|
|
assert.ok(updatedApiConfig, '更新后应返回 api_config');
|
|
assert.equal(String(updatedApiConfig?.qimen_customer_id || ''), updatedCustomerId);
|
|
assert.notEqual(String(updatedApiConfig?.qimen_customer_id || ''), ignoredCustomerId);
|
|
assert.equal(String(updatedApiConfig?.qimen_warehouse_code || ''), updatePayload.qimen_warehouse_code);
|
|
assert.equal(Number(updatedApiConfig?.is_enabled), 0);
|
|
|
|
const verifyRes = await invokeSystemMethod(`${METHOD_PREFIX}.list`, {
|
|
id: Number(candidate.id),
|
|
}, token, EXTRA_HEADERS);
|
|
assert.equal(verifyRes.status, 200);
|
|
assert.equal(verifyRes.body.flag, 'success');
|
|
assert.equal(verifyRes.body.code, 200);
|
|
const verified = Array.isArray(verifyRes.body?.data?.list) ? verifyRes.body.data.list[0] : null;
|
|
assert.ok(verified, '保存接口配置后应能查询到签约关系');
|
|
assert.equal(String((verified?.api_config || verified?.apiConfig || {}).qimen_customer_id || ''), updatedCustomerId);
|
|
|
|
const configListRes = await invokeSystemMethod(`${METHOD_PREFIX}.listApiConfig`, {
|
|
id: Number(candidate.id),
|
|
}, token, EXTRA_HEADERS);
|
|
assert.equal(configListRes.status, 200);
|
|
assert.equal(configListRes.body.flag, 'success');
|
|
assert.equal(configListRes.body.code, 200);
|
|
assert.equal(Number(configListRes.body?.data?.contract_id || 0), Number(candidate.id));
|
|
assert.ok(Array.isArray(configListRes.body?.data?.list), '应返回接口配置列表');
|
|
assert.ok((configListRes.body?.data?.list || []).length >= 1, '保存后应至少返回一条接口配置');
|
|
assert.equal(String(configListRes.body?.data?.list?.[0]?.qimen_customer_id || ''), updatedCustomerId);
|
|
|
|
const deleteRes = await invokeSystemMethod(`${METHOD_PREFIX}.deleteQimenConfig`, {
|
|
id: Number(candidate.id),
|
|
interface_type_id: Number((updatedApiConfig && updatedApiConfig.interface_type_id) || createPayload.interface_type_id || 0) || undefined,
|
|
}, token, EXTRA_HEADERS);
|
|
assert.equal(deleteRes.status, 200);
|
|
assert.equal(deleteRes.body.flag, 'success');
|
|
assert.equal(deleteRes.body.code, 200);
|
|
assert.equal(Boolean(deleteRes.body?.data?.deleted), true);
|
|
|
|
const verifyDeleteRes = await invokeSystemMethod(`${METHOD_PREFIX}.list`, {
|
|
id: Number(candidate.id),
|
|
}, token, EXTRA_HEADERS);
|
|
assert.equal(verifyDeleteRes.status, 200);
|
|
assert.equal(verifyDeleteRes.body.flag, 'success');
|
|
assert.equal(verifyDeleteRes.body.code, 200);
|
|
const deletedView = Array.isArray(verifyDeleteRes.body?.data?.list) ? verifyDeleteRes.body.data.list[0] : null;
|
|
assert.ok(deletedView, '删除接口配置后仍应能查询到签约关系');
|
|
assert.equal(deletedView?.api_config || deletedView?.apiConfig || null, null);
|
|
|
|
const emptyListRes = await invokeSystemMethod(`${METHOD_PREFIX}.listApiConfig`, {
|
|
id: Number(candidate.id),
|
|
}, token, EXTRA_HEADERS);
|
|
assert.equal(emptyListRes.status, 200);
|
|
assert.equal(emptyListRes.body.flag, 'success');
|
|
assert.equal(emptyListRes.body.code, 200);
|
|
assert.ok(Array.isArray(emptyListRes.body?.data?.list), '删除后仍应返回列表结构');
|
|
assert.equal(Number(emptyListRes.body?.data?.total || 0), 0);
|
|
} finally {
|
|
try {
|
|
if (originalApiConfig) {
|
|
await invokeSystemMethod(`${METHOD_PREFIX}.saveApiConfig`, {
|
|
id: Number(candidate.id),
|
|
interface_type_id: Number(originalApiConfig.interface_type_id || 0) || undefined,
|
|
app_name: originalApiConfig.app_name,
|
|
qimen_app_key: originalApiConfig.qimen_app_key,
|
|
qimen_customer_id: originalApiConfig.qimen_customer_id,
|
|
qimen_warehouse_code: originalApiConfig.qimen_warehouse_code,
|
|
contact_person: originalApiConfig.contact_person,
|
|
contact_phone: originalApiConfig.contact_phone,
|
|
email: originalApiConfig.email,
|
|
is_enabled: Number(originalApiConfig.is_enabled || 0),
|
|
}, token, EXTRA_HEADERS);
|
|
}
|
|
} finally {
|
|
if (createdRestoreQimenApp) {
|
|
await removeQimenAppRecord(restoreAppKey);
|
|
}
|
|
|
|
if (createdQimenApp) {
|
|
await removeQimenAppRecord(createPayload.qimen_app_key);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
it('should fail to save api config when qimen_app_key has no matching qimen app record', async function() {
|
|
const listRes = await invokeSystemMethod(`${METHOD_PREFIX}.list`, {
|
|
page: 1,
|
|
page_size: 30,
|
|
}, token, EXTRA_HEADERS);
|
|
|
|
assert.equal(listRes.status, 200);
|
|
assert.equal(listRes.body.flag, 'success');
|
|
assert.equal(listRes.body.code, 200);
|
|
|
|
const currentRole = String(listRes.body?.data?.current_subject?.role || '');
|
|
if (currentRole !== 'warehouse') {
|
|
this.skip();
|
|
}
|
|
|
|
const candidates = Array.isArray(listRes.body?.data?.list) ? listRes.body.data.list : [];
|
|
const candidate = pickFixedTestRelation(candidates);
|
|
assert.ok(candidate, '未找到固定测试仓/测试货主对应关系,无法做接口配置失败回归');
|
|
|
|
const originalApiConfig = candidate.api_config || candidate.apiConfig || null;
|
|
const seed = Date.now();
|
|
const payload = {
|
|
id: Number(candidate.id),
|
|
interface_type_id: Number((originalApiConfig && originalApiConfig.interface_type_id) || 0) || undefined,
|
|
app_name: `autotest_missing_qimen_app_${seed}`,
|
|
qimen_app_key: `autotest_missing_qimen_app_key_${seed}`,
|
|
qimen_warehouse_code: `autotest_missing_wh_${seed}`,
|
|
contact_person: 'autotest',
|
|
contact_phone: '13800138000',
|
|
email: `autotest_missing_${seed}@example.com`,
|
|
is_enabled: 1,
|
|
};
|
|
|
|
const res = await invokeSystemMethod(`${METHOD_PREFIX}.saveApiConfig`, payload, token, EXTRA_HEADERS);
|
|
|
|
assert.equal(res.status, 200);
|
|
assert.equal(res.body.flag, 'failure');
|
|
assert.equal(Number(res.body.code), 400);
|
|
assert.match(String(res.body.message || ''), /qimen_app_key|奇门应用配置/);
|
|
});
|
|
|
|
it('should reject sign when counterparty is missing', async () => {
|
|
const res = await invokeSystemMethod(`${METHOD_PREFIX}.sign`, {
|
|
print_quantity: 0,
|
|
}, token, EXTRA_HEADERS);
|
|
|
|
assert.equal(res.status, 200);
|
|
assert.equal(res.body.flag, 'failure');
|
|
assert.equal(Number(res.body.code), 400);
|
|
assert.match(String(res.body.message || ''), /counterparty_id|store_id|warehouse_id/);
|
|
});
|
|
|
|
it('should reject unbind when no target relation is provided', async () => {
|
|
const res = await invokeSystemMethod(`${METHOD_PREFIX}.unbind`, {}, token, EXTRA_HEADERS);
|
|
|
|
assert.equal(res.status, 200);
|
|
assert.equal(res.body.flag, 'failure');
|
|
assert.equal(Number(res.body.code), 400);
|
|
assert.match(String(res.body.message || ''), /id|counterparty_id|store_id|warehouse_id/);
|
|
});
|
|
});
|