1be2d62f9e
Закрывает замечания заказчика (22.05.2026) по проектам/поставщику. Все 4 куска имеют общий корень: online-синхронизация одного проекта работала с данными ЭТОГО проекта, а не пересчитывала всю «группу» (проекты разных tenant'ов с одним identifier) — отсюда переплата ×3 при изменении лимита, затирание регионов/дней группы, неотправленная пауза, и осиротевшие проекты при смене источника. 1. Групповой пересчёт в SyncSupplierProjectJob::handleOnline (#1 при изменении, #2 дни, #3 регионы, C2/C3): union regions, computeOrder eligible, distributeForPlatform — те же расчёты, что в ночном syncGroup. Online и ночной теперь дают идентичный supplier-state, расхождение устранено. 2. Пауза #10: - ProjectController::toggleActive — диспатчит SyncSupplierProjectJob; - ProjectService::bulkPauseResume — диспатчит sync per project; - DTO status вычисляется из groupActive (paused когда группа без активных); - sp.inactive_since пишется при пересинке (для UI/DTO консистентности). 3. Смена источника #8/#9 в ProjectService::update: - до update снимается старый buildUniqueKeyAgnostic; - если изменился — отвязываем старые supplier_projects от этого project (pivot + legacy FK), DeleteSupplierProjectJob удаляет их у поставщика при отсутствии других потребителей, либо пересинкает агрегат. 4. Перенос auto-link корня из feat/root-domain-auto-link: новый App\Support\SupplierIdentifier::extractRootDomain + блоки auto-link в обоих джобах (online + nightly). Тесты: TDD на каждый кусок. SyncSupplierProjectJobTest +2 (group recompute, pause). ProjectUpdateDedupTest +1 (source detach + cleanup dispatch). ProjectsActionsTest +2 (toggle + bulk pause dispatches). Регрессия: 186/186 passed (Project/Plan5/Projects + Supplier), 502 assertions. Деплой: дельтой на боевой (база = root-domain ветка; на боевом джобы СТАРЕЕ main, deliver через копию изменённых файлов + config:cache + restart queue). План: docs/superpowers/plans/2026-05-22-замечания-проекты-чеклист.md Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
143 lines
5.6 KiB
PHP
143 lines
5.6 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;
|
|
|
|
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);
|
|
});
|