Files
portal/app/tests/Feature/Project/ProjectDeleteTest.php
T
Дмитрий 7408bc4232 feat(projects): hard delete with deals-guard, replace archive
- ProjectService: add delete() with DB-level deals check (bypasses SoftDeletes
  scope via DB::table), captures supplier pivot IDs before cascade, dispatches
  DeleteSupplierProjectJob; add bulkDelete() private method; replace archive
  match arm with delete; remove archive() method
- ProjectController: destroy() calls delete() not archive(); update docblocks
- BulkProjectActionRequest: replace 'archive' with 'delete' in Rule::in for action
- Tests: ProjectDeleteTest (2 new TDD tests), ProjectsActionsTest updated
  (destroy → hard delete, 409-already-archived → 422-has-deals, bulk archive → bulk delete)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-21 08:08:33 +03:00

41 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
use App\Models\Project;
use App\Models\Tenant;
use App\Services\Project\ProjectService;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Queue;
beforeEach(fn () => Queue::fake());
it('hard-deletes an empty project', function () {
$tenant = Tenant::factory()->create(['balance_leads' => 100]);
$project = app(ProjectService::class)->create($tenant, [
'name' => 'Empty', 'signal_type' => 'call', 'signal_identifier' => '79991110000',
'daily_limit_target' => 5, 'regions' => [], 'delivery_days_mask' => 31,
]);
app(ProjectService::class)->delete($project);
expect(Project::find($project->id))->toBeNull();
});
it('blocks delete when project has deals', function () {
$tenant = Tenant::factory()->create(['balance_leads' => 100]);
$project = app(ProjectService::class)->create($tenant, [
'name' => 'WithDeals', 'signal_type' => 'call', 'signal_identifier' => '79991110000',
'daily_limit_target' => 5, 'regions' => [], 'delivery_days_mask' => 31,
]);
DB::table('deals')->insert([
'tenant_id' => $tenant->id, 'project_id' => $project->id, 'phone' => '79990001122',
'status' => 'new', 'received_at' => now(), 'created_at' => now(),
]);
expect(fn () => app(ProjectService::class)->delete($project))
->toThrow(HttpResponseException::class);
expect(Project::find($project->id))->not->toBeNull();
});