来源仓库: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 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
84 lines
3.1 KiB
TypeScript
84 lines
3.1 KiB
TypeScript
import { readFileSync } from 'node:fs';
|
|
import path from 'node:path';
|
|
import { describe, expect, it } from 'vitest';
|
|
import { normalizeSupplierInvoiceListQuery, normalizeSupplierInvoiceWrite } from '../src/services/supplierInvoiceWriteService';
|
|
|
|
describe('normalizeSupplierInvoiceWrite', () => {
|
|
it('forces supplier type, empty statement_no, and drops OCR items', () => {
|
|
const row = normalizeSupplierInvoiceWrite({
|
|
invoice_no: '2651200004167832411',
|
|
supplier_code: 'S001',
|
|
amount: 4500,
|
|
invoice_type: 'sales',
|
|
statement_no: 'SS-1',
|
|
ocr_data: { invoice_no: '2651200004167832411', items: [{ name: '猪肉', amount: 4500 }] },
|
|
branch_code: 'BR002',
|
|
} as Record<string, unknown>);
|
|
expect(row.invoice_type).toBe('supplier');
|
|
expect(row.statement_no).toBeNull();
|
|
expect(row.ocr_data).toEqual({ invoice_no: '2651200004167832411' });
|
|
expect(row.ocr_data).not.toHaveProperty('items');
|
|
});
|
|
|
|
it('rejects missing supplier or non-positive amount', () => {
|
|
expect(() =>
|
|
normalizeSupplierInvoiceWrite({ invoice_no: 'A', amount: 1 })
|
|
).toThrow(/供应商/);
|
|
expect(() =>
|
|
normalizeSupplierInvoiceWrite({ invoice_no: 'A', supplier_code: 'S001', amount: 0 })
|
|
).toThrow(/金额/);
|
|
});
|
|
});
|
|
|
|
describe('supplier 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/SupplierStatements.tsx'), 'utf8');
|
|
expect(routes).toMatch(/router\.get\(\s*'\/finance\/supplier-invoices'/);
|
|
expect(routes).toMatch(/router\.post\(\s*'\/finance\/supplier-invoices'/);
|
|
expect(api).toMatch(/\/workflow\/finance\/supplier-invoices/);
|
|
expect(api).toContain('listSupplierInvoicesApi');
|
|
expect(api).not.toMatch(/\.insert\(/);
|
|
expect(page).not.toMatch(/invoiceOcrItems/);
|
|
expect(page).toContain('downloadInvoice');
|
|
});
|
|
|
|
it('requires upload date range, supplier optional', () => {
|
|
expect(
|
|
normalizeSupplierInvoiceListQuery({
|
|
supplierCode: '',
|
|
dateFrom: '2026-09-01',
|
|
dateTo: '2026-09-22',
|
|
}).supplierCode
|
|
).toBeNull();
|
|
expect(() =>
|
|
normalizeSupplierInvoiceListQuery({ supplierCode: 'S001' })
|
|
).toThrow(/日期/);
|
|
});
|
|
|
|
it('lists by uploaded created_at range, not invoice_date', () => {
|
|
const q = normalizeSupplierInvoiceListQuery({
|
|
supplierCode: 'S001',
|
|
dateFrom: '2026-09-01',
|
|
dateTo: '2026-09-22',
|
|
});
|
|
expect(q.limit).toBe(30);
|
|
expect(q.offset).toBe(0);
|
|
expect(normalizeSupplierInvoiceListQuery({
|
|
supplierCode: 'S001',
|
|
dateFrom: '2026-09-01',
|
|
dateTo: '2026-09-22',
|
|
limit: 999,
|
|
offset: -1,
|
|
}).limit).toBe(50);
|
|
expect(() =>
|
|
normalizeSupplierInvoiceListQuery({ supplierCode: 'S001', dateFrom: '2026-09-22', dateTo: '2026-09-01' })
|
|
).toThrow(/日期/);
|
|
});
|
|
});
|