import { describe, expect, it } from 'vitest'; import { applyRetiredSystemConfigPolicy, RETIRED_SYSTEM_CONFIG_KEYS, } from '../src/services/retiredSystemConfigKeys'; import type { QuerySpec } from '../src/services/queryExecutor'; describe('retired system_configs', () => { it('includes leftover and internal-only keys', () => { expect(RETIRED_SYSTEM_CONFIG_KEYS.has('ai_purchase_tolerance')).toBe(true); expect(RETIRED_SYSTEM_CONFIG_KEYS.has('orphan_fulfillment_trigger_enabled')).toBe(true); expect(RETIRED_SYSTEM_CONFIG_KEYS.has('purchaser_supplier_status_view')).toBe(true); expect(RETIRED_SYSTEM_CONFIG_KEYS.has('purchaser_one_click_supplier_inspection')).toBe(true); expect(RETIRED_SYSTEM_CONFIG_KEYS.has('bid_settings')).toBe(true); expect(RETIRED_SYSTEM_CONFIG_KEYS.has('order_abnormal_threshold')).toBe(true); expect(RETIRED_SYSTEM_CONFIG_KEYS.has('weigh_ota_policy')).toBe(true); }); it('select/update/delete hide retired keys', () => { const spec: QuerySpec = { table: 'system_configs', action: 'select' }; const out = applyRetiredSystemConfigPolicy(spec); expect(out.filters).toEqual( expect.arrayContaining([ { op: 'neq', column: 'config_key', value: 'ai_purchase_tolerance' }, { op: 'neq', column: 'config_key', value: 'orphan_fulfillment_trigger_enabled' }, { op: 'neq', column: 'config_key', value: 'purchaser_supplier_status_view' }, { op: 'neq', column: 'config_key', value: 'purchaser_one_click_supplier_inspection' }, { op: 'neq', column: 'config_key', value: 'bid_settings' }, { op: 'neq', column: 'config_key', value: 'order_abnormal_threshold' }, { op: 'neq', column: 'config_key', value: 'weigh_ota_policy' }, ]) ); }); it('rejects insert of retired keys', () => { const spec: QuerySpec = { table: 'system_configs', action: 'insert', insertData: { config_key: 'ai_purchase_tolerance', config_value: { value: 0.05 } }, }; expect(() => applyRetiredSystemConfigPolicy(spec)).toThrow(/已停用/); }); it('leaves other tables unchanged', () => { const spec: QuerySpec = { table: 'orders', action: 'select' }; expect(applyRetiredSystemConfigPolicy(spec)).toBe(spec); }); }); describe('purchaser mini-program features', () => { it('does not read supplier-status / one-click system configs', async () => { const { readFileSync } = await import('node:fs'); const src = readFileSync(new URL('../src/routes/mobile/mobileShared.ts', import.meta.url), 'utf8'); expect(src).toMatch(/supplier_status_enabled: false/); expect(src).toMatch(/one_click_supplier_inspection_enabled: false/); expect(src).not.toMatch(/getPurchaserSupplierStatusConfig/); expect(src).not.toMatch(/getPurchaserOneClickSupplierInspectionConfig/); }); });