Az Apolló-oldali szállítási alegység-azonosító egyeztetéséhez: profitcenterenként egy sor, több szállítási címes telephelynél címenként egy sor (a multiAddress jelzőt követve, mint a megrendelő felület), a Hooreyca azonosítóval, a nameId betűkóddal és a beszállítói vevőkóddal. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
118 lines
4.7 KiB
PHP
118 lines
4.7 KiB
PHP
<?php
|
|
|
|
use App\Console\Commands\MaryKerDeliveryAddressReport;
|
|
use App\Models\Address;
|
|
use App\Models\ProfitCenter;
|
|
use App\Models\ProfitCenterSupplierCode;
|
|
use App\Models\Supplier;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
|
use Tests\TestCase;
|
|
|
|
uses(TestCase::class, RefreshDatabase::class);
|
|
|
|
function reportProfitCenter(Supplier $supplier, array $attributes = []): ProfitCenter
|
|
{
|
|
$profitCenter = ProfitCenter::factory()->create(array_merge(['hooreycaId' => 'AKG', 'nameId' => 'AKGB'], $attributes));
|
|
$supplier->profitCenter()->attach($profitCenter->id);
|
|
|
|
return $profitCenter;
|
|
}
|
|
|
|
function reportAddress(ProfitCenter $profitCenter, string $name, string $street): Address
|
|
{
|
|
return Address::create([
|
|
'name' => $name, 'postCode' => '7623', 'city' => 'Pécs', 'street' => $street,
|
|
'attachable_id' => $profitCenter->id, 'attachable_type' => ProfitCenter::class,
|
|
]);
|
|
}
|
|
|
|
beforeEach(function () {
|
|
$this->supplier = Supplier::factory()->create(['nameId' => 'MARY']);
|
|
$this->command = app(MaryKerDeliveryAddressReport::class);
|
|
});
|
|
|
|
it('egyetlen alap sort ad a telephelynek, ha nincs több szállítási cím', function () {
|
|
$profitCenter = reportProfitCenter($this->supplier, ['multiAddress' => '0', 'addressEqual' => '1']);
|
|
|
|
$rows = $this->command->rows($this->supplier);
|
|
|
|
expect($rows)->toHaveCount(1)
|
|
->and($rows[0][0])->toBe($profitCenter->id)
|
|
->and($rows[0][2])->toBe('AKG')
|
|
->and($rows[0][3])->toBe('AKGB')
|
|
->and($rows[0][5])->toBe(MaryKerDeliveryAddressReport::TYPE_BASE)
|
|
->and($rows[0][6])->toBe($profitCenter->fullAddress)
|
|
->and($rows[0][7])->toBe('')
|
|
->and($rows[0][10])->toBe('');
|
|
});
|
|
|
|
it('szállítási címenként egy sort ad, a cím azonosítójával', function () {
|
|
$profitCenter = reportProfitCenter($this->supplier, ['multiAddress' => '1', 'addressEqual' => '0']);
|
|
$first = reportAddress($profitCenter, 'Kórház', 'Rákóczi út 2.');
|
|
$second = reportAddress($profitCenter, 'Kávézó', 'Ifjúság útja 13');
|
|
|
|
$rows = $this->command->rows($this->supplier);
|
|
|
|
expect($rows)->toHaveCount(2)
|
|
->and($rows[0][5])->toBe(MaryKerDeliveryAddressReport::TYPE_DELIVERY)
|
|
->and($rows[0][7])->toBe((string) $first->id)
|
|
->and($rows[0][8])->toBe('Kórház')
|
|
->and($rows[1][7])->toBe((string) $second->id)
|
|
->and($rows[1][8])->toBe('Kávézó');
|
|
});
|
|
|
|
it('a jelzőt követi, nem a címrekordok számát, és figyelmeztet az eltérésre', function () {
|
|
$profitCenter = reportProfitCenter($this->supplier, ['multiAddress' => '0', 'addressEqual' => '1']);
|
|
reportAddress($profitCenter, 'Maradvány', 'Régi utca 1.');
|
|
|
|
$rows = $this->command->rows($this->supplier);
|
|
|
|
expect($rows)->toHaveCount(1)
|
|
->and($rows[0][5])->toBe(MaryKerDeliveryAddressReport::TYPE_BASE)
|
|
->and($rows[0][10])->toContain('1 további címrekord');
|
|
});
|
|
|
|
it('jelzi, ha a több szállítási cím be van kapcsolva, de nincs cím rögzítve', function () {
|
|
reportProfitCenter($this->supplier, ['multiAddress' => '1']);
|
|
|
|
$rows = $this->command->rows($this->supplier);
|
|
|
|
expect($rows)->toHaveCount(1)->and($rows[0][10])->not->toBe('');
|
|
});
|
|
|
|
it('a beszállítói vevőkódot szövegként, a vezető nullákkal adja vissza', function () {
|
|
$profitCenter = reportProfitCenter($this->supplier, ['multiAddress' => '0', 'addressEqual' => '1']);
|
|
ProfitCenterSupplierCode::create([
|
|
'profit_center_id' => $profitCenter->id, 'supplier_id' => $this->supplier->id, 'customerCode' => '002934',
|
|
]);
|
|
|
|
expect($this->command->rows($this->supplier)[0][4])->toBe('002934');
|
|
});
|
|
|
|
it('csak az adott beszállító telephelyeit listázza', function () {
|
|
reportProfitCenter($this->supplier, ['multiAddress' => '0', 'addressEqual' => '1']);
|
|
ProfitCenter::factory()->create(['hooreycaId' => 'IDEGEN']);
|
|
|
|
expect($this->command->rows($this->supplier))->toHaveCount(1);
|
|
});
|
|
|
|
it('xlsx fájlt készít a megadott útvonalra', function () {
|
|
reportProfitCenter($this->supplier, ['multiAddress' => '0', 'addressEqual' => '1']);
|
|
$path = sys_get_temp_dir() . '/maryker_cimek_' . uniqid() . '.xlsx';
|
|
|
|
$this->artisan('maryker:delivery-addresses', ['--path' => $path])->assertSuccessful();
|
|
|
|
$sheet = IOFactory::load($path)->getActiveSheet();
|
|
expect($sheet->getCell('A5')->getValue())->toBe('Profitcenter ID')
|
|
->and($sheet->getCell('C6')->getValue())->toBe('AKG')
|
|
->and($sheet->getCell('D6')->getValue())->toBe('AKGB')
|
|
->and($sheet->getCell('F6')->getValue())->toBe(MaryKerDeliveryAddressReport::TYPE_BASE);
|
|
|
|
unlink($path);
|
|
});
|
|
|
|
it('hibával áll le, ha nincs ilyen betűkódú beszállító', function () {
|
|
$this->artisan('maryker:delivery-addresses', ['--supplier' => 'NINCS'])->assertFailed();
|
|
});
|