2ec70b338f
Accessibility (Pa11y live) / a11y (push) Has been cancelled
Закрыто 36 из 55 пре-существующих падений backend-набора (55 to 19), всё тест-сторона, код продукта не тронут. Группы: - incident-показ/РКН: добавлен SharesSupplierPdo + синхрон уровня транзакции в трейте (вложенный transaction на общем PDO теперь делает SAVEPOINT, не повторный BEGIN). - auto-pause и lead-delivery: тесты создают project_routing_snapshots, от которого зависит выбор кандидатов в LeadRouter (slepok-инвариант). - изоляция 16 протекающих тестов: добавлен DatabaseTransactions (где нужно плюс SharesSupplierPdo) — перестали оставлять committed-строки, отравлявшие глобально сканирующие тесты (snapshot, verify-audit, size-N). - partition time-bombs: ensureRange месячных партиций для тестов на дату 2026-05. - устаревшие ассерты: SchemaDelta метрики v8.35 to v8.52, ProjectsStore телефон 8 to 7 нормализуется, incidents-watch фильтр активного admin, register captcha_token, impersonation активный юзер тенанта, activity_log.deal_id, ProjectUpdateDedup пауза. Остаток 19 (отдельно): verify-audit-chains и size-N (протекатели audit-строк), webhook B-префикс (решение владельца), пара env/каскадных. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
145 lines
5.7 KiB
PHP
145 lines
5.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Jobs\SyncSupplierProjectJob;
|
|
use App\Models\Project;
|
|
use App\Models\Tenant;
|
|
use App\Models\User;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Queue;
|
|
|
|
uses(\Illuminate\Foundation\Testing\DatabaseTransactions::class);
|
|
|
|
beforeEach(fn () => Queue::fake());
|
|
|
|
it('destroy hard-deletes a project with no deals', function () {
|
|
$tenant = Tenant::factory()->create();
|
|
$user = User::factory()->create(['tenant_id' => $tenant->id]);
|
|
$project = Project::factory()->create(['tenant_id' => $tenant->id, 'is_active' => true]);
|
|
|
|
$this->actingAs($user)->deleteJson("/api/projects/{$project->id}")->assertNoContent();
|
|
|
|
expect(Project::find($project->id))->toBeNull();
|
|
});
|
|
|
|
it('destroy returns 422 if project has deals', function () {
|
|
$tenant = Tenant::factory()->create();
|
|
$user = User::factory()->create(['tenant_id' => $tenant->id]);
|
|
$project = Project::factory()->create(['tenant_id' => $tenant->id, 'is_active' => true]);
|
|
DB::table('deals')->insert([
|
|
'tenant_id' => $tenant->id, 'project_id' => $project->id,
|
|
'phone' => '79990001100', 'status' => 'new',
|
|
'received_at' => now(), 'created_at' => now(),
|
|
]);
|
|
|
|
$this->actingAs($user)->deleteJson("/api/projects/{$project->id}")->assertStatus(422);
|
|
|
|
expect(Project::find($project->id))->not->toBeNull();
|
|
});
|
|
|
|
it('sync re-dispatches SyncSupplierProjectJob', function () {
|
|
$tenant = Tenant::factory()->create();
|
|
$user = User::factory()->create(['tenant_id' => $tenant->id]);
|
|
$project = Project::factory()->create(['tenant_id' => $tenant->id]);
|
|
|
|
$this->actingAs($user)->postJson("/api/projects/{$project->id}/sync")
|
|
->assertStatus(202)
|
|
->assertJsonPath('queued', true);
|
|
|
|
Queue::assertPushed(SyncSupplierProjectJob::class);
|
|
});
|
|
|
|
it('toggle-active flips is_active flag', function () {
|
|
$tenant = Tenant::factory()->create();
|
|
$user = User::factory()->create(['tenant_id' => $tenant->id]);
|
|
$project = Project::factory()->create(['tenant_id' => $tenant->id, 'is_active' => true]);
|
|
|
|
$this->actingAs($user)->patchJson("/api/projects/{$project->id}/toggle-active", ['is_active' => false])
|
|
->assertOk();
|
|
|
|
expect($project->fresh()->is_active)->toBeFalse();
|
|
});
|
|
|
|
it('toggle-active dispatches supplier sync so pause/resume reaches the supplier (#10)', function () {
|
|
$tenant = Tenant::factory()->create();
|
|
$user = User::factory()->create(['tenant_id' => $tenant->id]);
|
|
$project = Project::factory()->create(['tenant_id' => $tenant->id, 'is_active' => true]);
|
|
|
|
$this->actingAs($user)->patchJson("/api/projects/{$project->id}/toggle-active", ['is_active' => false])
|
|
->assertOk();
|
|
|
|
Queue::assertPushed(SyncSupplierProjectJob::class, fn ($job) => $job->projectId === $project->id);
|
|
});
|
|
|
|
it('bulk pause dispatches supplier sync for each affected project (#10)', function () {
|
|
$tenant = Tenant::factory()->create();
|
|
$user = User::factory()->create(['tenant_id' => $tenant->id]);
|
|
$p1 = Project::factory()->create(['tenant_id' => $tenant->id, 'is_active' => true]);
|
|
$p2 = Project::factory()->create(['tenant_id' => $tenant->id, 'is_active' => true]);
|
|
|
|
$this->actingAs($user)->postJson('/api/projects/bulk', [
|
|
'action' => 'pause', 'ids' => [$p1->id, $p2->id],
|
|
])->assertOk()->assertJsonPath('updated', 2);
|
|
|
|
Queue::assertPushed(SyncSupplierProjectJob::class, fn ($job) => in_array($job->projectId, [$p1->id, $p2->id], true));
|
|
});
|
|
|
|
it('bulk pause sets is_active=false on multiple', function () {
|
|
$tenant = Tenant::factory()->create();
|
|
$user = User::factory()->create(['tenant_id' => $tenant->id]);
|
|
$p1 = Project::factory()->create(['tenant_id' => $tenant->id, 'is_active' => true]);
|
|
$p2 = Project::factory()->create(['tenant_id' => $tenant->id, 'is_active' => true]);
|
|
|
|
$this->actingAs($user)->postJson('/api/projects/bulk', [
|
|
'action' => 'pause', 'ids' => [$p1->id, $p2->id],
|
|
])->assertOk()->assertJsonPath('updated', 2);
|
|
|
|
expect($p1->fresh()->is_active)->toBeFalse();
|
|
expect($p2->fresh()->is_active)->toBeFalse();
|
|
});
|
|
|
|
it('bulk filters out cross-tenant ids silently', function () {
|
|
$tenantA = Tenant::factory()->create();
|
|
$tenantB = Tenant::factory()->create();
|
|
$userA = User::factory()->create(['tenant_id' => $tenantA->id]);
|
|
$pA = Project::factory()->create(['tenant_id' => $tenantA->id, 'is_active' => true]);
|
|
$pB = Project::factory()->create(['tenant_id' => $tenantB->id, 'is_active' => true]);
|
|
|
|
$this->actingAs($userA)->postJson('/api/projects/bulk', [
|
|
'action' => 'pause', 'ids' => [$pA->id, $pB->id],
|
|
])->assertOk()->assertJsonPath('updated', 1);
|
|
|
|
expect($pB->fresh()->is_active)->toBeTrue();
|
|
});
|
|
|
|
it('bulk delete removes project with no deals', function () {
|
|
$tenant = Tenant::factory()->create();
|
|
$user = User::factory()->create(['tenant_id' => $tenant->id]);
|
|
$p1 = Project::factory()->create(['tenant_id' => $tenant->id]);
|
|
|
|
$this->actingAs($user)->postJson('/api/projects/bulk', [
|
|
'action' => 'delete', 'ids' => [$p1->id],
|
|
])->assertOk()->assertJsonPath('updated', 1);
|
|
|
|
expect(Project::find($p1->id))->toBeNull();
|
|
});
|
|
|
|
it('bulk rejects > 500 ids', function () {
|
|
$tenant = Tenant::factory()->create();
|
|
$user = User::factory()->create(['tenant_id' => $tenant->id]);
|
|
|
|
$this->actingAs($user)->postJson('/api/projects/bulk', [
|
|
'action' => 'pause', 'ids' => range(1, 501),
|
|
])->assertStatus(422);
|
|
});
|
|
|
|
it('bulk rejects unknown action', function () {
|
|
$tenant = Tenant::factory()->create();
|
|
$user = User::factory()->create(['tenant_id' => $tenant->id]);
|
|
|
|
$this->actingAs($user)->postJson('/api/projects/bulk', [
|
|
'action' => 'destroy_all', 'ids' => [1],
|
|
])->assertStatus(422);
|
|
});
|