2026-05-27 15:18:26 +03:00
|
|
|
<?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();
|
|
|
|
|
|
2026-06-17 05:17:12 +03:00
|
|
|
expect(DB::table('project_routing_snapshots')->where('snapshot_date', '2026-05-27')->count())->toBe(1);
|
2026-05-27 15:18:26 +03:00
|
|
|
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();
|
|
|
|
|
|
2026-06-17 05:17:12 +03:00
|
|
|
expect(DB::table('project_routing_snapshots')->count())->toBe(1);
|
2026-05-27 15:18:26 +03:00
|
|
|
Carbon::setTestNow();
|
|
|
|
|
});
|