来源仓库: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 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
61 lines
2.5 KiB
TypeScript
61 lines
2.5 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import {
|
|
assertAllocationsWithinInvoiceAmount,
|
|
invoiceWithLinksCteSql,
|
|
normalizeInvoiceAllocations,
|
|
} from '../src/services/invoiceStatementLinkService';
|
|
|
|
/**
|
|
* 结算发票「上传即绑定」纯逻辑单测(设计 docs/design/20260923-invoice-statement-binding.md)。
|
|
* 归属校验需要 DB,另由页面/接口验收覆盖。
|
|
*/
|
|
describe('invoice statement allocations', () => {
|
|
it('合并同一结算单的多行分配,金额归到分', () => {
|
|
expect(
|
|
normalizeInvoiceAllocations([
|
|
{ statement_no: 'O20260801001', amount: 100.005 },
|
|
{ statement_no: 'O20260801001', amount: 200.004 },
|
|
{ statement_no: 'O20260802001', amount: 50 },
|
|
])
|
|
).toEqual([
|
|
{ statement_no: 'O20260801001', amount: 300.01 },
|
|
{ statement_no: 'O20260802001', amount: 50 },
|
|
]);
|
|
});
|
|
|
|
it('缺省/空数组视为无绑定,不抛错', () => {
|
|
expect(normalizeInvoiceAllocations(undefined)).toEqual([]);
|
|
expect(normalizeInvoiceAllocations(null)).toEqual([]);
|
|
expect(normalizeInvoiceAllocations([])).toEqual([]);
|
|
});
|
|
|
|
it('非数组、空单号、非正金额一律 400', () => {
|
|
expect(() => normalizeInvoiceAllocations({ statement_no: 'A', amount: 1 })).toThrow();
|
|
expect(() => normalizeInvoiceAllocations([{ statement_no: ' ', amount: 1 }])).toThrow();
|
|
expect(() => normalizeInvoiceAllocations([{ statement_no: 'A', amount: 0 }])).toThrow();
|
|
expect(() => normalizeInvoiceAllocations([{ statement_no: 'A', amount: -5 }])).toThrow();
|
|
});
|
|
|
|
it('分配合计不得超过票面金额(分位容差内放行)', () => {
|
|
expect(() =>
|
|
assertAllocationsWithinInvoiceAmount([{ statement_no: 'A', amount: 1000 }], 1000)
|
|
).not.toThrow();
|
|
// 分位浮点容差
|
|
expect(() =>
|
|
assertAllocationsWithinInvoiceAmount([{ statement_no: 'A', amount: 1000.004 }], 1000)
|
|
).not.toThrow();
|
|
expect(() =>
|
|
assertAllocationsWithinInvoiceAmount([{ statement_no: 'A', amount: 1000.01 }], 1000)
|
|
).toThrow();
|
|
});
|
|
|
|
it('单语句同时写发票与绑定链接(数据修改 CTE)', () => {
|
|
const sql = invoiceWithLinksCteSql('customer_code');
|
|
expect(sql).toContain('INSERT INTO invoices');
|
|
expect(sql).toContain('INSERT INTO invoice_statement_links');
|
|
expect(sql).toContain('invoice_id, statement_type, statement_no, amount, branch_code');
|
|
expect(sql).toContain('unnest($13::text[], $14::numeric[])');
|
|
expect(sql).toContain('SELECT * FROM inv');
|
|
});
|
|
});
|