diff --git a/app/Services/ReleasePlanner.php b/app/Services/ReleasePlanner.php new file mode 100644 index 0000000..96f2e24 --- /dev/null +++ b/app/Services/ReleasePlanner.php @@ -0,0 +1,45 @@ + "{$maj}.{$min}.".($pat + 1), + 'minor' => "{$maj}.".($min + 1).'.0', + 'major' => ($maj + 1).'.0.0', + ]; + + if (str_contains($current, '-beta')) { + $targets['continueBeta'] = "{$maj}.{$min}.{$pat}"; + } + + return $targets; + } + + /** + * The flat list of allowed target versions — the server-side allow-list for a posted target. + * + * @return array + */ + public function allowedTargets(string $current): array + { + return array_values($this->proposedTargets($current)); + } +} diff --git a/tests/Unit/ReleasePlannerTest.php b/tests/Unit/ReleasePlannerTest.php new file mode 100644 index 0000000..2469301 --- /dev/null +++ b/tests/Unit/ReleasePlannerTest.php @@ -0,0 +1,51 @@ +planner = new ReleasePlanner; + } + + public function test_stable_version_offers_patch_minor_major_without_continue_beta(): void + { + $t = $this->planner->proposedTargets('0.9.58'); + + $this->assertSame('0.9.59', $t['patch']); + $this->assertSame('0.10.0', $t['minor']); + $this->assertSame('1.0.0', $t['major']); + $this->assertArrayNotHasKey('continueBeta', $t); + } + + public function test_beta_version_also_offers_continue_beta_of_its_base(): void + { + $t = $this->planner->proposedTargets('0.10.0-beta3'); + + $this->assertSame('0.10.0', $t['continueBeta']); + $this->assertSame('0.10.1', $t['patch']); + $this->assertSame('0.11.0', $t['minor']); + $this->assertSame('1.0.0', $t['major']); + } + + public function test_strips_a_leading_v(): void + { + $this->assertSame('0.9.59', $this->planner->proposedTargets('v0.9.58')['patch']); + } + + public function test_allowed_targets_are_the_proposed_values(): void + { + $allowed = $this->planner->allowedTargets('0.10.0-beta1'); + + $this->assertContains('0.10.0', $allowed); // continueBeta + $this->assertContains('0.11.0', $allowed); // minor + $this->assertNotContains('0.9.0', $allowed); + } +}