style+fix(pd): pint formatting + nullsafe.neverNull fix + lifecycle test predicate

This commit is contained in:
Дмитрий
2026-05-22 16:45:12 +03:00
parent 8e732fa855
commit bc09186299
12 changed files with 77 additions and 56 deletions
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
/**
* 152-ФЗ integration: pd_processing_log captures the full deal lifecycle
@@ -11,9 +13,9 @@
* DealViewAccessLogTest / ReportFileDeletePdLogTest
*/
use App\Models\ReportJob;
use App\Models\Deal;
use App\Models\Project;
use App\Models\ReportJob;
use App\Models\Tenant;
use App\Models\User;
use Illuminate\Foundation\Testing\DatabaseTransactions;
@@ -25,8 +27,8 @@ uses(DatabaseTransactions::class);
beforeEach(function () {
Storage::fake('local');
$this->tenant = Tenant::factory()->create(['balance_leads' => 100]);
$this->user = User::factory()->for($this->tenant)->create();
$this->tenant = Tenant::factory()->create(['balance_leads' => 100]);
$this->user = User::factory()->for($this->tenant)->create();
$this->actingAs($this->user);
DB::statement('SET app.current_tenant_id = '.(int) $this->tenant->id);
$this->project = Project::factory()->for($this->tenant)->create(['name' => 'PD Flow Test']);
@@ -37,7 +39,7 @@ it('records pd events through the whole deal lifecycle (create → view → expo
// ── 1. CREATE (manual) → pd action='created', purpose='lead_create_manual' ──
$created = $this->postJson('/api/deals', [
'project_name' => $this->project->name,
'phone' => '+7 (999) 123-45-67',
'phone' => '+7 (999) 123-45-67',
]);
$created->assertStatus(201);
$dealId = (int) $created->json('deal.id');
@@ -57,18 +59,18 @@ it('records pd events through the whole deal lifecycle (create → view → expo
// Mirror: ReportFileDeletePdLogTest — create a DONE ReportJob with file_path,
// then DELETE /api/reports/jobs/{id}.
$job = ReportJob::create([
'tenant_id' => $this->tenant->id,
'user_id' => $this->user->id,
'type' => 'deals_export',
'tenant_id' => $this->tenant->id,
'user_id' => $this->user->id,
'type' => 'deals_export',
'parameters' => ['format' => 'csv', 'date_from' => '2026-01-01', 'date_to' => '2026-12-31'],
'status' => ReportJob::STATUS_DONE,
'file_path' => 'reports/'.(int) $this->tenant->id.'/pd_flow_test.csv',
'status' => ReportJob::STATUS_DONE,
'file_path' => 'reports/'.(int) $this->tenant->id.'/pd_flow_test.csv',
]);
$this->deleteJson("/api/reports/jobs/{$job->id}")->assertOk();
// ── ASSERT — scoped to THIS tenant ────────────────────────────────────────
$rows = DB::table('pd_processing_log')
$rows = DB::table('pd_processing_log')
->where('tenant_id', $this->tenant->id)
->get();
$byAction = $rows->groupBy('action');
@@ -82,7 +84,7 @@ it('records pd events through the whole deal lifecycle (create → view → expo
// Correct purpose for each action.
expect($rows->firstWhere('action', 'created')->purpose)->toBe('lead_create_manual');
expect($rows->firstWhere('action', 'viewed')->purpose)->toBe('lead_card_view');
expect($rows->firstWhere('action', 'exported')->purpose)->toBe('deals_export_csv');
expect($rows->contains(fn ($r) => $r->action === 'exported' && $r->purpose === 'deals_export_csv'))->toBeTrue();
expect($rows->firstWhere('action', 'deleted')->purpose)->toBe('report_file_'.$job->id);
// 'created' and 'viewed' rows are tied to the deal we created.