Files
portal/app/tests/Feature/Autopodbor/AutopodborManualCompetitorApiTest.php
T

56 lines
2.3 KiB
PHP
Raw Normal View History

<?php
declare(strict_types=1);
use App\Models\AutopodborCompetitor;
use App\Models\Tenant;
use App\Models\User;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\DB;
use Tests\Concerns\SharesSupplierPdo;
uses(DatabaseTransactions::class, SharesSupplierPdo::class);
it('POST competitors/manual — заводит конкурента сразу в поле без изучения', function () {
$tenant = Tenant::factory()->create();
$user = User::factory()->create(['tenant_id' => $tenant->id]);
DB::statement('SET app.current_tenant_id = '.$tenant->id);
$this->actingAs($user)->postJson('/api/autopodbor/competitors/manual', [
'name' => 'Окна Ромашка',
'site_url' => 'romashka.ru',
'description' => 'Местный конкурент',
])->assertCreated()
->assertJsonPath('data.name', 'Окна Ромашка')
->assertJsonPath('data.box', 'field')
->assertJsonPath('data.origin', 'manual');
$comp = AutopodborCompetitor::where('tenant_id', $tenant->id)->where('name', 'Окна Ромашка')->first();
expect($comp)->not->toBeNull()
->and($comp->box)->toBe('field')
->and($comp->origin)->toBe('manual')
->and($comp->search_run_id)->toBeNull()
->and($comp->study_run_id)->toBeNull(); // изучение НЕ запускалось
});
it('POST competitors/manual — имя обязательно (422)', function () {
$tenant = Tenant::factory()->create();
$user = User::factory()->create(['tenant_id' => $tenant->id]);
DB::statement('SET app.current_tenant_id = '.$tenant->id);
$this->actingAs($user)->postJson('/api/autopodbor/competitors/manual', [
'site_url' => 'romashka.ru',
])->assertStatus(422);
});
it('POST competitors/manual — конкурент привязан к своему тенанту', function () {
$tenant = Tenant::factory()->create();
$user = User::factory()->create(['tenant_id' => $tenant->id]);
DB::statement('SET app.current_tenant_id = '.$tenant->id);
$this->actingAs($user)->postJson('/api/autopodbor/competitors/manual', ['name' => 'Берёзка'])
->assertCreated();
expect(AutopodborCompetitor::where('name', 'Берёзка')->first()->tenant_id)->toBe($tenant->id);
});