From d51ba5f57df3d181e4a67af5a56abdd682ed92ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9?= Date: Tue, 26 May 2026 11:17:53 +0300 Subject: [PATCH] test(supplier-snapshot-guard): failing unit tests for computeGraceUntil --- .../Project/SupplierSnapshotGuardTest.php | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 app/tests/Unit/Services/Project/SupplierSnapshotGuardTest.php 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'), + ); + } +}