feat(projects): backend support for subject-level regions array (Plan 6 Task 3)
- Project model: +regions in fillable + cast via PostgresIntArray
(custom Eloquent cast for PG INT[] — Laravel stock 'array' uses JSON
which Postgres rejects on native INT[] columns)
- StoreProjectRequest / UpdateProjectRequest: drop region_mask/mode rules,
add regions array validation (1..89 each, present/sometimes)
- ProjectService::create: dual-write — regions источник истины + legacy
region_mask=255 + region_mode='include' для PhonePrefixService/LeadRouter
compatibility (Plan 6.5 cleanup will remove dual-write)
- +5 Pest tests covering create/update/dual-write/validation rejection
- Drive-by: SchemaDeltaTest indexes pin 117 → 118 (Plan 6 v8.20 carryover
from Task 1; should ideally have landed in Task 1 commit ce0b789)
- phpstan-baseline: +3 entries for Project::$regions until next ide-helper
regen; existing Pest actingAs counts bumped 9→12 / 6→8 for new tests
Verified: Pest --parallel 747/744/3sk/0/0 (5 new tests pass +
SchemaDeltaTest now green), phpstan 0 errors, pint clean, gitleaks 0.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -78,14 +78,49 @@ it('cross-tenant update returns 404', function () {
|
||||
])->assertStatus(404);
|
||||
});
|
||||
|
||||
it('updates region_mask and delivery_days_mask', function () {
|
||||
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}", [
|
||||
'region_mask' => 78, 'region_mode' => 'exclude', 'delivery_days_mask' => 31,
|
||||
'delivery_days_mask' => 31,
|
||||
])->assertOk();
|
||||
|
||||
expect($project->fresh()->region_mask)->toBe(78);
|
||||
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);
|
||||
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]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user