diff --git a/database/factories/SemesterFactory.php b/database/factories/SemesterFactory.php index 914628c..a94da5e 100644 --- a/database/factories/SemesterFactory.php +++ b/database/factories/SemesterFactory.php @@ -4,6 +4,7 @@ namespace Database\Factories; +use App\Enums\SemesterStatus; use Illuminate\Database\Eloquent\Factories\Factory; class SemesterFactory extends Factory @@ -12,6 +13,7 @@ public function definition(): array { return [ "name" => "Semestr" . fake()->numberBetween(1, 7), + "status" => fake()->boolean ? SemesterStatus::ACTIVE->value : SemesterStatus::INACTIVE->value, ]; } } diff --git a/tests/Feature/SemesterTest.php b/tests/Feature/SemesterTest.php index 92238bb..af76a6f 100644 --- a/tests/Feature/SemesterTest.php +++ b/tests/Feature/SemesterTest.php @@ -61,4 +61,30 @@ public function testSemesterCanBeDeleted(): void $this->assertDatabaseCount("semesters", 0); } + + public function testSemesterCanBeSetToActiveStatus(): void + { + $semester = Semester::factory()->create(["status" => "inactive"]); + $this->assertSame("inactive", $semester->status->value); + + $this->post("/dashboard/semesters/{$semester->id}/activate"); + + $semester->refresh(); + $this->assertSame("active", $semester->status->value); + } + + public function testOnlyOneSemesterCanBeActive(): void + { + $inactiveSemester = Semester::factory()->create(["status" => "inactive"]); + $activeSemester = Semester::factory()->create(["status" => "active"]); + $this->assertSame("inactive", $inactiveSemester->status->value); + $this->assertSame("active", $activeSemester->status->value); + + $this->post("/dashboard/semesters/{$inactiveSemester->id}/activate"); + + $inactiveSemester->refresh(); + $activeSemester->refresh(); + $this->assertSame("active", $inactiveSemester->status->value); + $this->assertSame("inactive", $activeSemester->status->value); + } }