来源仓库:jxc/ai-fresh-delivery 来源提交:f0b1a180e2deb7e4673b9d1c8542619f7bc0f73d 快照树: 09f679334ff38f0ff25e907961c94a8223bcaedd(与来源 HEAD 工作树逐字节一致,3801 个文件) 按约定本仓库不带任何历史提交:来源仓库的历史中含真实凭据 (生产 SSH 私钥 deploy/id_rsa_tencent、server/.env、.env.tencent/.env.production/.env.gitea、 deploy/小程序AppSecret.txt,其中 MP_APPSECRET / S3 AccessKey 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
101 lines
3.5 KiB
TypeScript
101 lines
3.5 KiB
TypeScript
import { readFileSync } from 'node:fs';
|
|
import path from 'node:path';
|
|
import { describe, expect, it } from 'vitest';
|
|
import {
|
|
normalizeCustomerInvoiceListQuery,
|
|
normalizeCustomerInvoiceWrite,
|
|
} from '../src/services/customerInvoiceWriteService';
|
|
|
|
describe('normalizeCustomerInvoiceWrite', () => {
|
|
it('forces customer type, empty statement_no, and drops OCR items', () => {
|
|
const row = normalizeCustomerInvoiceWrite({
|
|
invoice_no: '2651200004167832411',
|
|
customer_code: 'C001',
|
|
amount: 4500,
|
|
invoice_type: 'supplier',
|
|
statement_no: 'ORD-1',
|
|
ocr_data: { invoice_no: '2651200004167832411', items: [{ name: '猪肉', amount: 4500 }] },
|
|
branch_code: 'BR002',
|
|
} as Record<string, unknown>);
|
|
expect(row.invoice_type).toBe('customer');
|
|
expect(row.statement_no).toBeNull();
|
|
expect(row.supplier_code).toBeNull();
|
|
expect(row.ocr_data).toEqual({ invoice_no: '2651200004167832411' });
|
|
expect(row.ocr_data).not.toHaveProperty('items');
|
|
});
|
|
|
|
it('rejects missing customer or non-positive amount', () => {
|
|
expect(() =>
|
|
normalizeCustomerInvoiceWrite({ invoice_no: 'A', amount: 1 })
|
|
).toThrow(/客户/);
|
|
expect(() =>
|
|
normalizeCustomerInvoiceWrite({ invoice_no: 'A', customer_code: 'C001', amount: 0 })
|
|
).toThrow(/金额/);
|
|
});
|
|
});
|
|
|
|
describe('customer invoice write path', () => {
|
|
it('saves via finance workflow, not /api/data', () => {
|
|
const root = path.join(__dirname, '..');
|
|
const routes = readFileSync(
|
|
path.join(root, 'src/modules/workflow/routes/financeRoutes.ts'),
|
|
'utf8'
|
|
);
|
|
const api = readFileSync(path.join(root, '../src/utils/supplierInvoiceApi.ts'), 'utf8');
|
|
const page = readFileSync(path.join(root, '../src/pages/finance/CustomerStatements.tsx'), 'utf8');
|
|
// 上传入口在 20260923 移到共用内联上传框组件
|
|
const uploadBox = readFileSync(
|
|
path.join(root, '../src/components/finance/StatementInvoiceUploadBox.tsx'),
|
|
'utf8'
|
|
);
|
|
expect(routes).toMatch(/router\.get\(\s*'\/finance\/customer-invoices'/);
|
|
expect(routes).toMatch(/router\.post\(\s*'\/finance\/customer-invoices'/);
|
|
expect(api).toMatch(/\/workflow\/finance\/customer-invoices/);
|
|
expect(api).toContain('listCustomerInvoicesApi');
|
|
expect(api).not.toMatch(/\.insert\(/);
|
|
expect(page).not.toMatch(/handleMarkInvoicePending/);
|
|
expect(page).toContain('downloadInvoice');
|
|
expect(page).toContain('StatementInvoiceUploadBox');
|
|
expect(uploadBox).toContain('uploadInvoice');
|
|
});
|
|
|
|
it('requires upload date range, customer optional', () => {
|
|
expect(
|
|
normalizeCustomerInvoiceListQuery({
|
|
customerCode: '',
|
|
dateFrom: '2026-09-01',
|
|
dateTo: '2026-09-22',
|
|
}).customerCode
|
|
).toBeNull();
|
|
expect(() =>
|
|
normalizeCustomerInvoiceListQuery({ customerCode: 'C001' })
|
|
).toThrow(/日期/);
|
|
});
|
|
|
|
it('lists by uploaded created_at range, not invoice_date', () => {
|
|
const q = normalizeCustomerInvoiceListQuery({
|
|
customerCode: 'C001',
|
|
dateFrom: '2026-09-01',
|
|
dateTo: '2026-09-22',
|
|
});
|
|
expect(q.limit).toBe(30);
|
|
expect(q.offset).toBe(0);
|
|
expect(
|
|
normalizeCustomerInvoiceListQuery({
|
|
customerCode: 'C001',
|
|
dateFrom: '2026-09-01',
|
|
dateTo: '2026-09-22',
|
|
limit: 999,
|
|
offset: -1,
|
|
}).limit
|
|
).toBe(50);
|
|
expect(() =>
|
|
normalizeCustomerInvoiceListQuery({
|
|
customerCode: 'C001',
|
|
dateFrom: '2026-09-22',
|
|
dateTo: '2026-09-01',
|
|
})
|
|
).toThrow(/日期/);
|
|
});
|
|
});
|