create(); $user = User::factory()->create(['tenant_id' => $tenant->id]); DB::statement('SET app.current_tenant_id = '.$tenant->id); $run = AutopodborRun::create(['tenant_id' => $tenant->id, 'kind' => 'search', 'status' => 'done', 'region_code' => 16, 'params' => []]); $comp = AutopodborCompetitor::create(['tenant_id' => $tenant->id, 'search_run_id' => $run->id, 'name' => 'Окна Комфорт', 'dedup_key' => 'okna']); return [$tenant, $user, $run, $comp]; } it('PATCH competitors/{id}/box — переносит конкурента в поле и обратно', function () { [$tenant, $user, $run, $comp] = boxSetup(); $this->actingAs($user)->patchJson("/api/autopodbor/competitors/{$comp->id}/box", ['box' => 'field']) ->assertOk() ->assertJsonPath('data.box', 'field'); expect($comp->fresh()->box)->toBe('field'); $this->actingAs($user)->patchJson("/api/autopodbor/competitors/{$comp->id}/box", ['box' => 'proposal']) ->assertOk() ->assertJsonPath('data.box', 'proposal'); }); it('PATCH competitors/{id}/box — отвергает чужое значение ящика (422)', function () { [$tenant, $user, $run, $comp] = boxSetup(); $this->actingAs($user)->patchJson("/api/autopodbor/competitors/{$comp->id}/box", ['box' => 'garbage']) ->assertStatus(422); }); it('PATCH competitors/{id}/box — чужой тенант не видит конкурента (404)', function () { [$tenant, $user, $run, $comp] = boxSetup(); $other = User::factory()->create(['tenant_id' => Tenant::factory()->create()->id]); $this->actingAs($other)->patchJson("/api/autopodbor/competitors/{$comp->id}/box", ['box' => 'field']) ->assertStatus(404); }); it('PATCH sources/{id}/box — переносит источник в работу и обратно', function () { [$tenant, $user, $run, $comp] = boxSetup(); $src = AutopodborSource::create([ 'tenant_id' => $tenant->id, 'competitor_id' => $comp->id, 'study_run_id' => $run->id, 'signal_type' => 'site', 'identifier' => 'okna-komfort.ru', 'dedup_key' => 'site:okna-komfort.ru', ]); $this->actingAs($user)->patchJson("/api/autopodbor/sources/{$src->id}/box", ['box' => 'field']) ->assertOk() ->assertJsonPath('data.box', 'field'); expect($src->fresh()->box)->toBe('field'); }); it('PATCH sources/{id}/box — чужой тенант не видит источник (404)', function () { [$tenant, $user, $run, $comp] = boxSetup(); $src = AutopodborSource::create([ 'tenant_id' => $tenant->id, 'competitor_id' => $comp->id, 'study_run_id' => $run->id, 'signal_type' => 'site', 'identifier' => 'okna-komfort.ru', 'dedup_key' => 'site:okna-komfort.ru', ]); $other = User::factory()->create(['tenant_id' => Tenant::factory()->create()->id]); $this->actingAs($other)->patchJson("/api/autopodbor/sources/{$src->id}/box", ['box' => 'field']) ->assertStatus(404); });