Files
portal/app/tests/Feature/Autopodbor/CompetitorElementsTest.php
T
Дмитрий d7c63a2962 feat(autopodbor): конкурент из элементов - слияние без потерь
Конкурент хранит список элементов {name,sites,cards} - подкомпании/ЖК холдинга.
Слияние складывает элементы всех объединяемых, ничего не роняет.
Миграция бэкфилла: один элемент из текущих site_url + directory_urls.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-04 18:14:39 +03:00

45 lines
1.6 KiB
PHP

<?php
declare(strict_types=1);
use App\Http\Resources\Autopodbor\CompetitorResource;
use App\Models\AutopodborCompetitor;
use App\Models\Tenant;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Tests\Concerns\SharesSupplierPdo;
uses(DatabaseTransactions::class, SharesSupplierPdo::class);
function elementsTenant(): Tenant
{
$t = Tenant::factory()->create();
DB::statement('SET app.current_tenant_id = '.$t->id);
return $t;
}
it('elements кастуется как массив', function () {
$t = elementsTenant();
$c = AutopodborCompetitor::create([
'tenant_id' => $t->id, 'name' => 'Сибиряк', 'box' => 'field', 'dedup_key' => 'c:'.md5(uniqid('', true)),
'elements' => [['name' => 'Нанжуль-Солнечный', 'sites' => ['nanzhul.ru'], 'cards' => []]],
]);
expect($c->fresh()->elements)->toBeArray()
->and($c->fresh()->elements[0]['name'])->toBe('Нанжуль-Солнечный');
});
it('ресурс конкурента отдаёт elements', function () {
$t = elementsTenant();
$c = AutopodborCompetitor::create([
'tenant_id' => $t->id, 'name' => 'Сибиряк', 'box' => 'field', 'dedup_key' => 'c:'.md5(uniqid('', true)),
'elements' => [['name' => 'Плодово-Ягодный', 'sites' => ['plodovo.ru'], 'cards' => []]],
]);
$arr = (new CompetitorResource($c))->toArray(Request::create('/'));
expect($arr['elements'])->toBe([['name' => 'Плодово-Ягодный', 'sites' => ['plodovo.ru'], 'cards' => []]]);
});