Files
portal/app/tests/Feature/Console/SnapshotBackfillCommandTest.php
T
Дмитрий 7eac4b33db feat(slepok): Task 2.3 — snapshot:backfill artisan command
One-time use at Stage 2 deploy + manual recovery if cron fails.
Idempotent via ON CONFLICT (snapshot_date, project_id) DO NOTHING.

Plan: docs/superpowers/plans/2026-05-26-slepok-routing-protection.md §Task 2.3
Spec: docs/superpowers/specs/2026-05-26-slepok-routing-protection-design.md §4.2.6

Tests: tests/Feature/Console/SnapshotBackfillCommandTest.php (2 tests).
Status — same as Task 2.2: RED locally on Windows-native PG test env
(Project factory signal_type override does not persist — both create([...])
and asCallSignal() state-method tried; both produce NULL in INSERT). GREEN
expected on CI Linux per memory project_slepok_protection.md.
2026-05-27 15:18:26 +03:00

40 lines
1.4 KiB
PHP

<?php
declare(strict_types=1);
use App\Models\Project;
use App\Models\Tenant;
use Carbon\Carbon;
it('creates snapshot for given date from current live state', function () {
Carbon::setTestNow('2026-05-27 14:00:00', 'Europe/Moscow');
$tenant = Tenant::factory()->create(['frozen_by_balance_at' => null]);
Project::factory()->for($tenant)->asCallSignal('79161234567')->create([
'is_active' => true,
'delivery_days_mask' => 127,
'daily_limit_target' => 10,
]);
$this->artisan('snapshot:backfill', ['--date' => '2026-05-27'])
->assertSuccessful();
expect(\DB::table('project_routing_snapshots')->where('snapshot_date', '2026-05-27')->count())->toBe(1);
Carbon::setTestNow();
});
it('is idempotent — does not duplicate on re-run', function () {
Carbon::setTestNow('2026-05-27 14:00:00', 'Europe/Moscow');
$tenant = Tenant::factory()->create(['frozen_by_balance_at' => null]);
Project::factory()->for($tenant)->asCallSignal('79161234567')->create([
'is_active' => true,
'delivery_days_mask' => 127,
'daily_limit_target' => 10,
]);
$this->artisan('snapshot:backfill', ['--date' => '2026-05-27'])->assertSuccessful();
$this->artisan('snapshot:backfill', ['--date' => '2026-05-27'])->assertSuccessful();
expect(\DB::table('project_routing_snapshots')->count())->toBe(1);
Carbon::setTestNow();
});