79 lines
2.8 KiB
PHP
79 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\EcommerceFinance;
|
|
|
|
use Modules\EcommerceFinance\Services\DingInvoiceRecordNormalizer;
|
|
use Tests\TestCase;
|
|
|
|
class DingInvoiceRecordNormalizerTest extends TestCase
|
|
{
|
|
public function test_same_invoice_number_is_merged(): void
|
|
{
|
|
$records = app(DingInvoiceRecordNormalizer::class)->deduplicate([
|
|
[
|
|
'invoice_number' => '26320000000000000001',
|
|
'seller_name' => '测试供应商',
|
|
'invoice_total' => 100,
|
|
],
|
|
[
|
|
'invoice_number' => '2632 0000 0000 0000 0001',
|
|
'seller_name' => '',
|
|
'invoice_total' => 100,
|
|
'invoice_date' => '2026-10-10',
|
|
],
|
|
]);
|
|
|
|
$this->assertCount(1, $records);
|
|
$this->assertSame('测试供应商', $records[0]['seller_name']);
|
|
$this->assertSame('2026-10-10', $records[0]['invoice_date']);
|
|
}
|
|
|
|
public function test_equal_amounts_with_different_invoice_numbers_are_kept(): void
|
|
{
|
|
$records = app(DingInvoiceRecordNormalizer::class)->deduplicate([
|
|
[
|
|
'invoice_number' => '26320000000000000001',
|
|
'seller_name' => '测试供应商',
|
|
'invoice_total' => 100,
|
|
],
|
|
[
|
|
'invoice_number' => '26320000000000000002',
|
|
'seller_name' => '测试供应商',
|
|
'invoice_total' => 100,
|
|
],
|
|
]);
|
|
|
|
$this->assertCount(2, $records);
|
|
}
|
|
|
|
public function test_scanned_attachment_enriches_imported_invoice_without_overwriting_it(): void
|
|
{
|
|
$merged = app(DingInvoiceRecordNormalizer::class)->mergeScanned(
|
|
[
|
|
'invoice_number' => '26320000000000000001',
|
|
'invoice_total' => 100,
|
|
'seller_name' => '已核对供应商',
|
|
'ocr_provider' => 'imported_workbook',
|
|
'source_file_id' => null,
|
|
'updated_at' => '2026-11-25 10:00:00',
|
|
],
|
|
[
|
|
'invoice_number' => '26320000000000000001',
|
|
'invoice_total' => 99.5,
|
|
'seller_name' => 'OCR 供应商',
|
|
'ocr_provider' => 'pdf_text',
|
|
'source_file_id' => 'FILE-1',
|
|
'source_file_name' => '发票.pdf',
|
|
'updated_at' => '2026-11-27 10:00:00',
|
|
],
|
|
);
|
|
|
|
$this->assertSame(100, $merged['invoice_total']);
|
|
$this->assertSame('已核对供应商', $merged['seller_name']);
|
|
$this->assertSame('imported_workbook', $merged['ocr_provider']);
|
|
$this->assertSame('FILE-1', $merged['source_file_id']);
|
|
$this->assertSame('发票.pdf', $merged['source_file_name']);
|
|
$this->assertSame('2026-11-27 10:00:00', $merged['updated_at']);
|
|
}
|
|
}
|