'use strict'; const assert = require('node:assert/strict'); const { getAuthToken, invokeSystemMethod, } = require('../../support/system_method_client'); const EXTRA_HEADERS = { platform: 'web', project: 'all', }; describe('test/app/controller/system.storeWarehouse.test.js', () => { const METHOD_PREFIX = 'storeWarehouse.store'; const REMOVED_SETTING_METHOD_PREFIX = 'setting.storeWarehouse.store'; const REMOVED_SETTING_SNAKE_METHOD_PREFIX = 'setting.store_warehouse'; const REMOVED_LEGACY_METHODS = [ 'list', 'sign', 'rename', 'unbind', 'getPolicyConfig', 'getPolicyConfigFields', 'savePolicyConfig', 'deleteQimenConfig', ]; const REMOVED_COMPAT_SETTING_METHODS = [ 'list', 'sign', 'rename', 'unbind' ]; let token = ''; before(async () => { const auth = await getAuthToken({ forceLogin: true }); token = auth.token; }); it('should expose standalone storeWarehouse.store.list', 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), 'storeWarehouse.store.list 应返回 list'); if (res.body.data.list.length > 0) { assert.ok(!Object.prototype.hasOwnProperty.call(res.body.data.list[0], 'apiConfig'), '首项不应包含 apiConfig 字段'); assert.ok(!Object.prototype.hasOwnProperty.call(res.body.data.list[0], 'api_config'), '首项不应包含 api_config 字段'); assert.ok(!Object.prototype.hasOwnProperty.call(res.body.data.list[0], 'qimenConfig'), '首项不应包含 qimenConfig 字段'); } assert.equal(typeof res.body?.data?.total, 'number'); }); it('should not expose removed legacy storeWarehouse.* methods', async () => { for (const methodName of REMOVED_LEGACY_METHODS) { const removedRes = await invokeSystemMethod(`storeWarehouse.${methodName}`, { page: 1, page_size: 10, }, token, EXTRA_HEADERS); assert.equal(removedRes.status, 500, `legacy method ${methodName} should fail`); assert.equal(removedRes.body.flag, 'failure'); assert.equal(Number(removedRes.body.code), 500); assert.match( String(removedRes.body.message || ''), new RegExp(`服务 storeWarehouse 不存在|方法 ${methodName} 不存在`) ); } }); it('should not expose removed setting.storeWarehouse.store.list alias', async () => { const removedRes = await invokeSystemMethod(`${REMOVED_SETTING_METHOD_PREFIX}.list`, { page: 1, page_size: 10, }, token, EXTRA_HEADERS); assert.equal(removedRes.status, 500); assert.equal(removedRes.body.flag, 'failure'); assert.equal(Number(removedRes.body.code), 500); assert.match(String(removedRes.body.message || ''), /服务 setting\.storeWarehouse\.store 不存在/); }); it('should not expose removed setting.store_warehouse.* compatibility methods', async () => { for (const methodName of REMOVED_COMPAT_SETTING_METHODS) { const removedRes = await invokeSystemMethod(`${REMOVED_SETTING_SNAKE_METHOD_PREFIX}.${methodName}`, { page: 1, page_size: 10, }, token, EXTRA_HEADERS); assert.equal(removedRes.status, 500, `compat setting.store_warehouse.${methodName} should fail`); assert.equal(removedRes.body.flag, 'failure'); assert.equal(Number(removedRes.body.code), 500); assert.match(String(removedRes.body.message || ''), /服务 setting\.store_warehouse 不存在|方法 .* 不存在/); } }); it('should expose standalone storeWarehouse.store.sign parameter validation', 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 expose standalone storeWarehouse.store.unbind parameter validation', 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/); }); it('should expose standalone storeWarehouse.store.rename parameter validation', async () => { const res = await invokeSystemMethod(`${METHOD_PREFIX}.rename`, {}, 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 || ''), /remask|id|counterparty_id|store_id|warehouse_id/); }); it('should expose standalone storeWarehouse.store.adjustPrintQuantity with auth or validation response', async () => { const res = await invokeSystemMethod(`${METHOD_PREFIX}.adjustPrintQuantity`, { change_quantity: 1, }, token, EXTRA_HEADERS); assert.notEqual(res.status, 500, '新接口不应是未注册或方法不存在'); if (res.status === 403) { assert.match(String(res.body?.message || ''), /无权访问|未授权|权限/); return; } assert.equal(res.status, 200); assert.equal(res.body.flag, 'failure'); assert.ok([ 400, 403, 404 ].includes(Number(res.body.code))); assert.match(String(res.body.message || ''), /reason|id|counterparty_id|store_id|warehouse_id|无权访问|不存在/); }); it('should expose standalone storeWarehouse.store.getPolicyConfig parameter validation', async () => { const res = await invokeSystemMethod(`${METHOD_PREFIX}.getPolicyConfig`, {}, 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/); }); it('should expose standalone storeWarehouse.store.getPolicyConfigFields as a metadata list', async () => { const res = await invokeSystemMethod(`${METHOD_PREFIX}.getPolicyConfigFields`, {}, token, EXTRA_HEADERS); assert.equal(res.status, 200); assert.equal(res.body.flag, 'success'); assert.equal(Number(res.body.code), 200); assert.ok(Array.isArray(res.body?.data), '字段信息接口应直接返回列表'); assert.ok(res.body.data.length > 0, '字段信息列表不能为空'); assert.ok(res.body.data.every(item => item && typeof item === 'object' && item.key && item.name && item.type), '每个字段项都应包含 key/name/type'); const printRechargePriceField = res.body.data.find(item => item.key === 'print_recharge_price'); assert.ok(printRechargePriceField, '字段信息应包含 print_recharge_price'); assert.equal(printRechargePriceField.name, '面单充值元/单'); assert.equal(printRechargePriceField.type, 'number'); assert.equal(Number(printRechargePriceField.default || 0), 0); assert.equal(Number(printRechargePriceField.precision), 2); assert.equal(Number(printRechargePriceField.step), 0.01); assert.match(String(printRechargePriceField.description || ''), /支持\s*2\s*位小数/); const needOrderApprovalField = res.body.data.find(item => item.key === 'need_order_approval'); assert.ok(needOrderApprovalField, '字段信息应包含 need_order_approval'); assert.equal(needOrderApprovalField.name, '推送订单需审批'); assert.equal(needOrderApprovalField.type, 'flag'); assert.equal(needOrderApprovalField.default, 1); const storageSeparationField = res.body.data.find(item => item.key === 'storage_separation'); assert.ok(storageSeparationField, '字段信息应包含 storage_separation'); assert.equal(storageSeparationField.name, '是否存储分离'); assert.equal(storageSeparationField.type, 'flag'); assert.equal(storageSeparationField.default, 1); const receiveModeField = res.body.data.find(item => item.key === 'receive_mode'); assert.ok(receiveModeField, '字段信息应包含 receive_mode'); assert.equal(receiveModeField.type, 'enum'); assert.ok(Array.isArray(receiveModeField.options), 'receive_mode 应返回选项列表'); assert.deepEqual( receiveModeField.options.map(option => option.value), [ 'standard', 'strict', 'manual' ] ); assert.deepEqual( receiveModeField.options.map(option => option.label), [ '标准收货', '严格收货', '人工收货' ] ); const defaultExpressField = res.body.data.find(item => item.key === 'default_express_code'); assert.ok(defaultExpressField, '字段信息应包含 default_express_code'); assert.equal(defaultExpressField.name, '默认快递'); assert.equal(defaultExpressField.type, 'list'); assert.equal(defaultExpressField.default, 'STO'); assert.ok(Array.isArray(defaultExpressField.options), 'default_express_code 应返回选项列表'); assert.ok(defaultExpressField.options.length > 0, 'default_express_code 选项不能为空'); assert.ok(defaultExpressField.options.every(option => option && typeof option === 'object' && option.value && option.label), 'default_express_code 选项应包含 value/label'); const defaultPlatformField = res.body.data.find(item => item.key === 'default_platform_code'); assert.ok(defaultPlatformField, '字段信息应包含 default_platform_code'); assert.equal(defaultPlatformField.name, '默认平台'); assert.equal(defaultPlatformField.type, 'list'); assert.equal(defaultPlatformField.default, 'TB'); assert.ok(Array.isArray(defaultPlatformField.options), 'default_platform_code 应返回选项列表'); assert.ok(defaultPlatformField.options.length > 0, 'default_platform_code 选项不能为空'); assert.ok(defaultPlatformField.options.every(option => option && typeof option === 'object' && option.value && option.label), 'default_platform_code 选项应包含 value/label'); }); it('should expose standalone storeWarehouse.store.savePolicyConfig parameter validation', async () => { const res = await invokeSystemMethod(`${METHOD_PREFIX}.savePolicyConfig`, {}, 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/); }); it('should expose standalone storeWarehouse.store.saveApiConfig parameter validation', async () => { const res = await invokeSystemMethod(`${METHOD_PREFIX}.saveApiConfig`, {}, 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 || ''), /interface_type_id|id|counterparty_id|store_id|warehouse_id|qimen_app_key|qimen_customer_id|qimen_warehouse_code/); }); it('should expose standalone storeWarehouse.store.deleteQimenConfig parameter validation', async () => { const res = await invokeSystemMethod(`${METHOD_PREFIX}.deleteQimenConfig`, {}, 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/); }); it('should expose standalone storeWarehouse.store.listApiConfig parameter validation', async () => { const res = await invokeSystemMethod(`${METHOD_PREFIX}.listApiConfig`, {}, 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/); }); });