Files
SupplierSystem/server/tests/customerSkuPriceEdit.test.ts
T
Ubuntu 94de4e60de feat(商城管理): 客户商品库后台一期
新增 /customers/mall 卡片管理、Excel 导入、上下架/描述/收藏/移出;复用客户销售价接口;修复共享报价单并发改价、i18n、迁移空 schema、并发计数。
2026-10-28 20:23:43 +08:00

69 lines
3.6 KiB
TypeScript

import { readFileSync } from 'node:fs';
import { describe, expect, it } from 'vitest';
const read = (rel: string) => readFileSync(new URL(`../${rel}`, import.meta.url), 'utf8');
const migration = read('../migrations/20261087_customer_sku_price_fields.sql');
const svc = read('src/services/customerSkuPriceService.ts');
const route = read('src/modules/workflow/routes/customerRoutes.ts');
const markup = read('src/services/quoteMarkupSalePriceService.ts');
const pricing = read('src/services/orderPricingService.ts');
const helpers = readFileSync(new URL('../../src/utils/orderItemHelpers.ts', import.meta.url), 'utf8');
const margin = read('src/services/marginQueryService.ts');
const page = readFileSync(
new URL('../../src/pages/finance/costAccounting/CostAccountingPanel.tsx', import.meta.url),
'utf8'
);
describe('客户 SKU 销售价二期', () => {
it('迁移幂等且覆盖 4 列 + 手工标记,不删旧列', () => {
expect(migration).toContain('ADD COLUMN IF NOT EXISTS sale_price NUMERIC(12,4)');
expect(migration).toContain('ADD COLUMN IF NOT EXISTS cost_price NUMERIC(12,4)');
expect(migration).toContain('ADD COLUMN IF NOT EXISTS price_updated_at TIMESTAMPTZ');
expect(migration).toContain('ADD COLUMN IF NOT EXISTS price_updated_by UUID');
expect(migration).toContain('ADD COLUMN IF NOT EXISTS sale_price_manual BOOLEAN NOT NULL DEFAULT false');
});
it('接口:报价单优先,否则 customer_skus;审计;不写订单/库存/结算', () => {
expect(svc).toContain("target = 'quote_sheet'");
expect(svc).toContain('sale_price_manual = true');
// 自动选择报价单也必须校验共享单,避免商城/排行改价串改其他客户价格
expect(svc).toContain('先锁报价单条目');
expect(svc).toContain('customer_quote_sheet_customers');
expect(svc).toContain('INSERT INTO customer_skus');
expect(svc).toContain('customer_sku_sale_price_update');
expect(svc).not.toMatch(/UPDATE orders|INSERT INTO order_items|inventory|settlement/i);
expect(route).toContain("'/customers/:customerCode/sku-sale-price'");
expect(route).toContain("['cost_manage', 'finance_manage', 'customer_manage']");
});
it('自动加成跳过人工改价', () => {
expect(markup).toContain('i.sale_price_manual');
expect(markup).toContain('sale_price_manual === true');
expect(markup).toContain('COALESCE(sale_price_manual, false) = false');
});
it('录单取价:报价单 → customer_skus.sale_price → 最近成交;前端 helper 同序', () => {
expect(pricing).toContain('resolveCustomerSkuSalePrices');
expect(pricing).toContain('customerSkuSale > 0');
expect(helpers).toContain("select('sku_code, price_preference, discount_rate, sale_price')");
expect(helpers).toContain('customerSkuSaleMap.get(code)');
});
it('排行合并 quote_sheet/customer_sku targets 且不改金额字段', () => {
expect(margin).toContain("target_type: 'quote_sheet'");
expect(margin).toContain("target_type: 'customer_sku'");
expect(margin).toContain("price_source");
const attach = margin.slice(margin.indexOf('const rows = paged.data'), margin.indexOf('return rows;', margin.indexOf('const rows = paged.data')));
expect(attach).not.toContain('gross_margin =');
expect(attach).not.toContain('total_cost =');
});
it('前端单客户铅笔 + 全部客户逐目标输入,无保存按钮', () => {
expect(page).toContain('setCustomerSkuSalePriceApi');
expect(page).toContain('Pencil');
expect(page).toContain("t('finance.cost.rank.editSalePrice')");
expect(page).toContain('onBlur={(e) => {');
expect(page).not.toContain("t('finance.cost.rank.savePrice')");
});
});