80275c6417
Закрывает два бага sync поставщика, обнаруженные при live-проверке создания проекта «мой номер» (call, 79135191264, лимит 15, дни Пн-Пт): 1. SyncSupplierProjectJob хардкодил workdays=[1..7] в 7 местах и в DTO для portal, и в supplier_projects.current_workdays. Заменено на реальную маску через приватный workdaysFromMask() (зеркало bitmaskToList ночного батча). 2. forceFill в update-path online mode не включал current_workdays — после первого create со старыми [1..7] последующий ресинк не подтягивал реальные дни в локальную БД (на portal летели корректные, в нашей таблице оставались stale). 3. ProjectService::update() ресинкал только при смене sms_*/signal_identifier/ regions. Добавлены daily_limit_target и delivery_days_mask — поставщик видит новый лимит и дни сразу, не дожидаясь ночного батча 18:00 МСК. Тесты: - SyncSupplierProjectJobTest: +2 specs (real-workdays create-path, update-path current_workdays refresh). - ProjectsUpdateTest: «without resync» переписан в name-only, +2 specs (daily_limit_target и delivery_days_mask change → resync). - Pest 146/146 (Supplier + Plan5/Projects scope), Pint passed, Larastan 0. Live-ресинк проекта id=5 «мой номер» в dev DB выполнен — current_workdays теперь [1,2,3,4,5], HTTP ушёл к crm.bp-gr.ru с теми же днями. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
217 lines
8.6 KiB
PHP
217 lines
8.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\Queue;
|
|
|
|
beforeEach(fn () => Queue::fake());
|
|
|
|
it('updates name without resync (name is local-only)', function () {
|
|
$tenant = Tenant::factory()->create();
|
|
$user = User::factory()->create(['tenant_id' => $tenant->id]);
|
|
$project = Project::factory()->create([
|
|
'tenant_id' => $tenant->id, 'signal_type' => 'site',
|
|
'signal_identifier' => 'a.ru', 'daily_limit_target' => 10,
|
|
]);
|
|
|
|
$this->actingAs($user)->patchJson("/api/projects/{$project->id}", [
|
|
'name' => 'New name',
|
|
])->assertOk();
|
|
|
|
expect($project->fresh()->name)->toBe('New name');
|
|
Queue::assertNotPushed(SyncSupplierProjectJob::class);
|
|
});
|
|
|
|
it('changing daily_limit_target triggers resync (poster must see new limit immediately)', function () {
|
|
$tenant = Tenant::factory()->create();
|
|
$user = User::factory()->create(['tenant_id' => $tenant->id]);
|
|
$project = Project::factory()->create([
|
|
'tenant_id' => $tenant->id, 'signal_type' => 'site',
|
|
'signal_identifier' => 'a.ru', 'daily_limit_target' => 10,
|
|
]);
|
|
|
|
$this->actingAs($user)->patchJson("/api/projects/{$project->id}", [
|
|
'daily_limit_target' => 50,
|
|
])->assertOk();
|
|
|
|
expect($project->fresh()->daily_limit_target)->toBe(50);
|
|
Queue::assertPushed(SyncSupplierProjectJob::class);
|
|
});
|
|
|
|
it('changing delivery_days_mask triggers resync (poster must see new days immediately)', function () {
|
|
$tenant = Tenant::factory()->create();
|
|
$user = User::factory()->create(['tenant_id' => $tenant->id]);
|
|
$project = Project::factory()->create([
|
|
'tenant_id' => $tenant->id, 'signal_type' => 'site',
|
|
'signal_identifier' => 'a.ru', 'delivery_days_mask' => 31,
|
|
]);
|
|
|
|
$this->actingAs($user)->patchJson("/api/projects/{$project->id}", [
|
|
'delivery_days_mask' => 63, // +Сб
|
|
])->assertOk();
|
|
|
|
expect($project->fresh()->delivery_days_mask)->toBe(63);
|
|
Queue::assertPushed(SyncSupplierProjectJob::class);
|
|
});
|
|
|
|
it('changing sms_senders triggers resync', function () {
|
|
$tenant = Tenant::factory()->create();
|
|
$user = User::factory()->create(['tenant_id' => $tenant->id]);
|
|
$project = Project::factory()->create([
|
|
'tenant_id' => $tenant->id, 'signal_type' => 'sms',
|
|
'sms_senders' => ['OLD'], 'sms_keyword' => 'x',
|
|
]);
|
|
|
|
$this->actingAs($user)->patchJson("/api/projects/{$project->id}", [
|
|
'sms_senders' => ['NEW'],
|
|
])->assertOk();
|
|
|
|
Queue::assertPushed(SyncSupplierProjectJob::class);
|
|
});
|
|
|
|
it('rejects daily_limit_target below delivered_today', function () {
|
|
$tenant = Tenant::factory()->create();
|
|
$user = User::factory()->create(['tenant_id' => $tenant->id]);
|
|
$project = Project::factory()->create([
|
|
'tenant_id' => $tenant->id, 'daily_limit_target' => 50, 'delivered_today' => 30,
|
|
]);
|
|
|
|
$this->actingAs($user)->patchJson("/api/projects/{$project->id}", [
|
|
'daily_limit_target' => 20,
|
|
])->assertStatus(422);
|
|
});
|
|
|
|
it('rejects update of signal_type (immutable)', function () {
|
|
$tenant = Tenant::factory()->create();
|
|
$user = User::factory()->create(['tenant_id' => $tenant->id]);
|
|
$project = Project::factory()->create(['tenant_id' => $tenant->id, 'signal_type' => 'site', 'signal_identifier' => 'test.ru']);
|
|
|
|
$response = $this->actingAs($user)->patchJson("/api/projects/{$project->id}", [
|
|
'signal_type' => 'call',
|
|
]);
|
|
|
|
// signal_type должен быть проигнорирован (не падает 422, но и не меняется)
|
|
expect($project->fresh()->signal_type)->toBe('site');
|
|
});
|
|
|
|
it('cross-tenant update returns 404', function () {
|
|
$tenantA = Tenant::factory()->create();
|
|
$tenantB = Tenant::factory()->create();
|
|
$userA = User::factory()->create(['tenant_id' => $tenantA->id]);
|
|
$project = Project::factory()->create(['tenant_id' => $tenantB->id]);
|
|
|
|
$this->actingAs($userA)->patchJson("/api/projects/{$project->id}", [
|
|
'name' => 'hack',
|
|
])->assertStatus(404);
|
|
});
|
|
|
|
it('updates delivery_days_mask (region_mask now read-only — see regions[] tests below)', function () {
|
|
// Plan 6: region_mask/region_mode больше не клиент-controllable через UpdateProjectRequest
|
|
// (validation rules удалены, ProjectService::create dual-writes 255/include).
|
|
// Источник истины для региональной фильтрации — projects.regions INT[] (Plan 6).
|
|
// Этот тест адаптирован: проверяет, что delivery_days_mask остаётся writeable через PATCH.
|
|
$tenant = Tenant::factory()->create();
|
|
$user = User::factory()->create(['tenant_id' => $tenant->id]);
|
|
$project = Project::factory()->create(['tenant_id' => $tenant->id]);
|
|
|
|
$this->actingAs($user)->patchJson("/api/projects/{$project->id}", [
|
|
'delivery_days_mask' => 31,
|
|
])->assertOk();
|
|
|
|
expect($project->fresh()->delivery_days_mask)->toBe(31);
|
|
});
|
|
|
|
// Plan 6 — subject-level regions[] support.
|
|
|
|
it('updates regions array via PATCH', function () {
|
|
$tenant = Tenant::factory()->create();
|
|
$user = User::factory()->create(['tenant_id' => $tenant->id]);
|
|
$project = Project::factory()->create(['tenant_id' => $tenant->id, 'regions' => []]);
|
|
|
|
$response = $this->actingAs($user)->patchJson("/api/projects/{$project->id}", [
|
|
'regions' => [82],
|
|
]);
|
|
|
|
$response->assertStatus(200);
|
|
$response->assertJsonPath('data.regions', [82]);
|
|
expect($project->fresh()->regions)->toBe([82]);
|
|
});
|
|
|
|
it('preserves regions when PATCH omits the field (sometimes rule)', function () {
|
|
$tenant = Tenant::factory()->create();
|
|
$user = User::factory()->create(['tenant_id' => $tenant->id]);
|
|
$project = Project::factory()->create([
|
|
'tenant_id' => $tenant->id,
|
|
'regions' => [82, 83],
|
|
]);
|
|
|
|
$response = $this->actingAs($user)->patchJson("/api/projects/{$project->id}", [
|
|
'name' => 'Renamed Project',
|
|
]);
|
|
|
|
$response->assertStatus(200);
|
|
expect($project->fresh()->regions)->toBe([82, 83]);
|
|
});
|
|
|
|
/* ---------------------------------------------------------------------
|
|
* 18.05.2026 UX-request (Task 5 плана): редактирование источника
|
|
* (signal_identifier для site/call) — Sync поставщику обязателен.
|
|
* --------------------------------------------------------------------- */
|
|
|
|
it('updates signal_identifier for site project + triggers resync', function () {
|
|
$tenant = Tenant::factory()->create();
|
|
$user = User::factory()->create(['tenant_id' => $tenant->id]);
|
|
$project = Project::factory()->create([
|
|
'tenant_id' => $tenant->id, 'signal_type' => 'site', 'signal_identifier' => 'old.ru',
|
|
]);
|
|
|
|
$this->actingAs($user)->patchJson("/api/projects/{$project->id}", [
|
|
'signal_identifier' => 'new-source.ru',
|
|
])->assertOk();
|
|
|
|
expect($project->fresh()->signal_identifier)->toBe('new-source.ru');
|
|
Queue::assertPushed(SyncSupplierProjectJob::class);
|
|
});
|
|
|
|
it('updates signal_identifier for call project (11-digit phone)', function () {
|
|
$tenant = Tenant::factory()->create();
|
|
$user = User::factory()->create(['tenant_id' => $tenant->id]);
|
|
$project = Project::factory()->create([
|
|
'tenant_id' => $tenant->id, 'signal_type' => 'call', 'signal_identifier' => '79991111111',
|
|
]);
|
|
|
|
$this->actingAs($user)->patchJson("/api/projects/{$project->id}", [
|
|
'signal_identifier' => '79992222222',
|
|
])->assertOk();
|
|
|
|
expect($project->fresh()->signal_identifier)->toBe('79992222222');
|
|
});
|
|
|
|
it('rejects invalid signal_identifier for site (not a domain)', function () {
|
|
$tenant = Tenant::factory()->create();
|
|
$user = User::factory()->create(['tenant_id' => $tenant->id]);
|
|
$project = Project::factory()->create([
|
|
'tenant_id' => $tenant->id, 'signal_type' => 'site', 'signal_identifier' => 'ok.ru',
|
|
]);
|
|
|
|
$this->actingAs($user)->patchJson("/api/projects/{$project->id}", [
|
|
'signal_identifier' => 'not-a-domain',
|
|
])->assertStatus(422)->assertJsonValidationErrors(['signal_identifier']);
|
|
});
|
|
|
|
it('rejects invalid signal_identifier for call (not 7\d{10})', function () {
|
|
$tenant = Tenant::factory()->create();
|
|
$user = User::factory()->create(['tenant_id' => $tenant->id]);
|
|
$project = Project::factory()->create([
|
|
'tenant_id' => $tenant->id, 'signal_type' => 'call', 'signal_identifier' => '79991111111',
|
|
]);
|
|
|
|
$this->actingAs($user)->patchJson("/api/projects/{$project->id}", [
|
|
'signal_identifier' => '12345',
|
|
])->assertStatus(422)->assertJsonValidationErrors(['signal_identifier']);
|
|
});
|