diff --git a/app/tests/Unit/Services/Project/SupplierSnapshotGuardTest.php b/app/tests/Unit/Services/Project/SupplierSnapshotGuardTest.php new file mode 100644 index 00000000..bbc8f833 --- /dev/null +++ b/app/tests/Unit/Services/Project/SupplierSnapshotGuardTest.php @@ -0,0 +1,70 @@ +guard = new SupplierSnapshotGuard; + } + + public function test_grace_until_for_pause_before_21_msk_is_next_day_21_msk(): void + { + $pausedAt = CarbonImmutable::parse('2026-05-25 14:00:00', 'Europe/Moscow'); + $graceUntil = $this->guard->computeGraceUntil($pausedAt); + + $this->assertSame( + '2026-05-26 21:00:00', + $graceUntil->setTimezone('Europe/Moscow')->format('Y-m-d H:i:s'), + ); + } + + public function test_grace_until_for_pause_after_21_msk_is_day_plus_two_21_msk(): void + { + $pausedAt = CarbonImmutable::parse('2026-05-25 22:00:00', 'Europe/Moscow'); + $graceUntil = $this->guard->computeGraceUntil($pausedAt); + + $this->assertSame( + '2026-05-27 21:00:00', + $graceUntil->setTimezone('Europe/Moscow')->format('Y-m-d H:i:s'), + ); + } + + public function test_grace_until_for_pause_exactly_at_21_msk_is_day_plus_two_21_msk(): void + { + $pausedAt = CarbonImmutable::parse('2026-05-25 21:00:00', 'Europe/Moscow'); + $graceUntil = $this->guard->computeGraceUntil($pausedAt); + + $this->assertSame( + '2026-05-27 21:00:00', + $graceUntil->setTimezone('Europe/Moscow')->format('Y-m-d H:i:s'), + ); + } + + public function test_grace_until_handles_utc_input(): void + { + // 14:00 UTC = 17:00 MSK (до 21:00) → grace = следующее 21:00 МСК +24ч + $pausedAt = CarbonImmutable::parse('2026-05-25 14:00:00', 'UTC'); + $graceUntil = $this->guard->computeGraceUntil($pausedAt); + + $this->assertSame( + '2026-05-26 21:00:00', + $graceUntil->setTimezone('Europe/Moscow')->format('Y-m-d H:i:s'), + ); + } +}