来源仓库: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 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
112 lines
4.0 KiB
TypeScript
112 lines
4.0 KiB
TypeScript
import { createRequire } from 'node:module';
|
|
import { readFileSync } from 'node:fs';
|
|
import { dirname, join } from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { describe, expect, it } from 'vitest';
|
|
import { getPromptDefault } from '../src/prompts/defaults';
|
|
import { parseFreeCostDocumentKind } from '../src/services/costAiService';
|
|
|
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
const require = createRequire(import.meta.url);
|
|
const {
|
|
expandFreeCostGroupToEntries,
|
|
pickInvoiceVoucher,
|
|
normalizeDocumentKind,
|
|
} = require(join(here, '../../miniprogram/utils/costManagement.js'));
|
|
|
|
describe('free cost add invoice kind', () => {
|
|
it('prompt default asks for document_kind and prefers voucher when unsure', () => {
|
|
const tpl = getPromptDefault('cost.free.voucher_amount')!.systemTemplate;
|
|
expect(tpl).toContain('"document_kind":"voucher"');
|
|
expect(tpl).toContain('吃不准时 document_kind 必须填 voucher');
|
|
expect(tpl).not.toMatch(/invoice\.ocr/);
|
|
});
|
|
|
|
it('parse defaults unknown/missing kind to voucher', () => {
|
|
expect(parseFreeCostDocumentKind('invoice')).toBe('invoice');
|
|
expect(parseFreeCostDocumentKind('发票')).toBe('invoice');
|
|
expect(parseFreeCostDocumentKind('voucher')).toBe('voucher');
|
|
expect(parseFreeCostDocumentKind('')).toBe('voucher');
|
|
expect(parseFreeCostDocumentKind(undefined)).toBe('voucher');
|
|
expect(parseFreeCostDocumentKind('receipt')).toBe('voucher');
|
|
expect(normalizeDocumentKind('发票')).toBe('invoice');
|
|
expect(normalizeDocumentKind('')).toBe('voucher');
|
|
});
|
|
|
|
it('split submit only attaches invoice local path on invoice images', () => {
|
|
const group = {
|
|
subtype: 'misc',
|
|
amount: '30.00',
|
|
remark: '',
|
|
_amountTouched: false,
|
|
vouchers: [
|
|
{
|
|
path: 'free-cost/a.jpg',
|
|
localPath: '/tmp/a.jpg',
|
|
amount: 10,
|
|
document_kind: 'invoice',
|
|
},
|
|
{
|
|
path: 'free-cost/b.jpg',
|
|
localPath: '/tmp/b.jpg',
|
|
amount: 20,
|
|
document_kind: 'voucher',
|
|
},
|
|
],
|
|
};
|
|
expect(expandFreeCostGroupToEntries(group)).toEqual([
|
|
{
|
|
subtype: 'misc',
|
|
amount: 10,
|
|
remark: '',
|
|
voucher_urls: [],
|
|
invoice_local_path: '/tmp/a.jpg',
|
|
},
|
|
{
|
|
subtype: 'misc',
|
|
amount: 20,
|
|
remark: '',
|
|
voucher_urls: ['free-cost/b.jpg'],
|
|
invoice_local_path: '',
|
|
},
|
|
]);
|
|
});
|
|
|
|
it('unsplit group with multiple invoices picks the closest amount', () => {
|
|
const vouchers = [
|
|
{ path: 'free-cost/a.jpg', localPath: '/tmp/a.jpg', amount: 40, document_kind: 'invoice' },
|
|
{ path: 'free-cost/b.jpg', localPath: '/tmp/b.jpg', amount: 99, document_kind: 'invoice' },
|
|
{ path: 'free-cost/c.jpg', localPath: '/tmp/c.jpg', amount: 12, document_kind: 'voucher' },
|
|
];
|
|
const picked = pickInvoiceVoucher(vouchers, 100);
|
|
expect(picked.localPath).toBe('/tmp/b.jpg');
|
|
const entries = expandFreeCostGroupToEntries({
|
|
subtype: 'misc',
|
|
amount: '100.00',
|
|
remark: '',
|
|
_amountTouched: true,
|
|
vouchers,
|
|
});
|
|
expect(entries).toHaveLength(1);
|
|
expect(entries[0].invoice_local_path).toBe('/tmp/b.jpg');
|
|
expect(entries[0].voucher_urls).toEqual(['free-cost/c.jpg']);
|
|
});
|
|
|
|
it('history candidates already exclude linked cost_detail ids', () => {
|
|
const src = readFileSync(join(here, '../src/services/freeCostInvoiceService.ts'), 'utf8');
|
|
expect(src).toMatch(/listUnlinkedMineEntries/);
|
|
expect(src).toMatch(/NOT EXISTS/);
|
|
expect(src).toMatch(/free_cost_invoice_links/);
|
|
});
|
|
|
|
it('invoice-only rows skip voucher_url and satisfy required photo via invoice_photo', () => {
|
|
const createSrc = readFileSync(join(here, '../src/services/freeCostService.ts'), 'utf8');
|
|
expect(createSrc).toMatch(/voucherPaths\.length < 1 && !input\.invoicePhoto/);
|
|
const routes = readFileSync(
|
|
join(here, '../src/modules/workflow/routes/financeRoutes.ts'),
|
|
'utf8'
|
|
);
|
|
expect(routes).toMatch(/invoicePhoto: mpFreeCost && \(req\.body\?\.invoice_photo/);
|
|
});
|
|
});
|