Skip to content

Commit

Permalink
#8 - added some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilpiech97 committed Sep 24, 2023
1 parent 3c0d792 commit 13c76ca
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions database/factories/SemesterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Database\Factories;

use App\Enums\SemesterStatus;
use Illuminate\Database\Eloquent\Factories\Factory;

class SemesterFactory extends Factory
Expand All @@ -12,6 +13,7 @@ public function definition(): array
{
return [
"name" => "Semestr" . fake()->numberBetween(1, 7),
"status" => fake()->boolean ? SemesterStatus::ACTIVE->value : SemesterStatus::INACTIVE->value,
];
}
}
26 changes: 26 additions & 0 deletions tests/Feature/SemesterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 13c76ca

Please sign in to comment.