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); });