64 lines
2.7 KiB
PHP
64 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\EcommerceFinance;
|
|
|
|
use Modules\EcommerceFinance\Repositories\ProductMaterialBarcodeMappingRepository;
|
|
use Modules\EcommerceFinance\Services\UpstreamReadOnlyQuery;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class ProductMaterialBarcodeMappingRepositoryTest extends TestCase
|
|
{
|
|
public function test_only_91_material_codes_are_normalized_and_suffixes_are_removed(): void
|
|
{
|
|
$this->assertSame(
|
|
'91.C46324.01',
|
|
ProductMaterialBarcodeMappingRepository::normalizeMaterialCode(' 91.c46324.01-N1280 '),
|
|
);
|
|
$this->assertSame(
|
|
'91.C45340.01',
|
|
ProductMaterialBarcodeMappingRepository::normalizeMaterialCode('91.C45340.01-N09'),
|
|
);
|
|
$this->assertSame(
|
|
'91.C49784.01',
|
|
ProductMaterialBarcodeMappingRepository::normalizeMaterialCode('91.C49784.01-N1280-1'),
|
|
);
|
|
$this->assertNull(ProductMaterialBarcodeMappingRepository::normalizeMaterialCode('GBGJ-SJ025102'));
|
|
$this->assertNull(ProductMaterialBarcodeMappingRepository::normalizeMaterialCode('91.OTHER'));
|
|
}
|
|
|
|
public function test_unique_mapping_is_selected_and_ambiguous_or_missing_mapping_is_not_guessed(): void
|
|
{
|
|
$query = $this->createMock(UpstreamReadOnlyQuery::class);
|
|
$query->expects($this->once())
|
|
->method('select')
|
|
->with(
|
|
$this->callback(static fn (string $sql): bool => str_contains(
|
|
$sql,
|
|
'FROM public."BarcodePrintImportRecord"',
|
|
) && str_contains($sql, "updates->>'barcode'")
|
|
&& substr_count($sql, '?') === 3),
|
|
['91.C45340.01', '91.C45438.01', '91.C49784.01'],
|
|
)
|
|
->willReturn([
|
|
['material_no' => '91.C45340.01', 'mapped_sku' => 'GBGJ-SJ025102N09V01'],
|
|
['material_no' => '91.C45340.01', 'mapped_sku' => 'GBGJ-SJ025102N09V01'],
|
|
['material_no' => '91.C45438.01', 'mapped_sku' => 'GBGJ-DNZ036601N09V01'],
|
|
['material_no' => '91.C45438.01', 'mapped_sku' => 'MKHDNZ0409260601235'],
|
|
]);
|
|
|
|
$result = (new ProductMaterialBarcodeMappingRepository())->resolve([
|
|
'91.C45340.01-N09',
|
|
'91.C45438.01-N09',
|
|
'91.C49784.01-N1280-1',
|
|
'GBGJ-SJ025102',
|
|
], $query);
|
|
|
|
$this->assertSame(['91.C45340.01' => 'GBGJ-SJ025102N09V01'], $result['unique']);
|
|
$this->assertSame([
|
|
'91.C45438.01' => ['GBGJ-DNZ036601N09V01', 'MKHDNZ0409260601235'],
|
|
], $result['ambiguous']);
|
|
$this->assertSame(['91.C49784.01'], $result['missing']);
|
|
$this->assertSame(4, $result['source_rows']);
|
|
}
|
|
}
|