-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
479a66b
commit d1bdb8f
Showing
9 changed files
with
289 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Requests; | ||
|
||
use Illuminate\Foundation\Http\FormRequest; | ||
|
||
class GroupRequest extends FormRequest | ||
{ | ||
public function rules(): array | ||
{ | ||
return [ | ||
"name" => ["required", "max:255"], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Database\Factories; | ||
|
||
use App\Enums\StudyForm; | ||
use App\Models\Course; | ||
use App\Models\Semester; | ||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
|
||
class CourseSemesterFactory extends Factory | ||
{ | ||
public function definition(): array | ||
{ | ||
return [ | ||
"semester_id" => Semester::factory(), | ||
"course_id" => Course::factory(), | ||
"form" => StudyForm::Stationary->value, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Database\Factories; | ||
|
||
use App\Models\CourseSemester; | ||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
|
||
class GroupFactory extends Factory | ||
{ | ||
public function definition(): array | ||
{ | ||
return [ | ||
"name" => fake()->asciify("******"), | ||
"course_semester_id" => CourseSemester::factory(), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Feature; | ||
|
||
use App\Models\Course; | ||
use App\Models\CourseSemester; | ||
use App\Models\Semester; | ||
use App\Models\User; | ||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use Tests\TestCase; | ||
|
||
class CourseSemesterTest extends TestCase | ||
{ | ||
use RefreshDatabase; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->user = User::factory()->create(); | ||
$this->semester = Semester::factory()->create(); | ||
$this->course = Course::factory()->create(); | ||
$this->actingAs($this->user); | ||
} | ||
|
||
public function testCourseSemesterCanBeCreated(): void | ||
{ | ||
$this->post("/dashboard/course-semester", [ | ||
"course" => $this->course->id, | ||
"semester" => $this->semester->id, | ||
"form" => "stationary", | ||
])->assertSessionHasNoErrors(); | ||
} | ||
|
||
public function testCourseCanBeUpdated(): void | ||
{ | ||
$course = CourseSemester::factory()->create(["form" => "part-time"]); | ||
|
||
$this->assertDatabaseMissing("course_semester", [ | ||
"course_id" => $this->course->id, | ||
"semester_id" => $this->semester->id, | ||
"form" => "stationary", | ||
]); | ||
|
||
$this->patch("/dashboard/course-semester/{$course->id}", [ | ||
"course" => $this->course->id, | ||
"semester" => $this->semester->id, | ||
"form" => "stationary", | ||
])->assertSessionHasNoErrors(); | ||
|
||
$this->assertDatabaseHas("course_semester", [ | ||
"course_id" => $this->course->id, | ||
"semester_id" => $this->semester->id, | ||
"form" => "stationary", | ||
]); | ||
} | ||
|
||
public function testCourseCannotBeCreatedWithInvalidData(): void | ||
{ | ||
$this->post("/dashboard/course-semester", [ | ||
"course" => 123, | ||
"semester" => 312, | ||
"form" => "bad-stationary", | ||
])->assertSessionHasErrors([ | ||
"course", | ||
"semester", | ||
"form", | ||
]); | ||
|
||
$this->assertDatabaseCount("course_semester", 0); | ||
} | ||
|
||
public function testCourseCanBeDeleted(): void | ||
{ | ||
$course = CourseSemester::factory()->create(); | ||
$this->assertDatabaseCount("course_semester", 1); | ||
|
||
$this->delete("/dashboard/course-semester/{$course->id}"); | ||
|
||
$this->assertDatabaseCount("course_semester", 0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Feature; | ||
|
||
use App\Models\CourseSemester; | ||
use App\Models\Group; | ||
use App\Models\Student; | ||
use App\Models\User; | ||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use Illuminate\Support\Str; | ||
use Tests\TestCase; | ||
|
||
class GroupTest extends TestCase | ||
{ | ||
use RefreshDatabase; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->user = User::factory()->create(); | ||
$this->course = CourseSemester::factory()->create(); | ||
$this->actingAs($this->user); | ||
} | ||
|
||
public function testStudentGroupSemesterCanBeCreated(): void | ||
{ | ||
$this->post("/dashboard/course-semester/{$this->course->id}/groups", [ | ||
"name" => "s1INF_1(1)", | ||
])->assertSessionHasNoErrors(); | ||
} | ||
|
||
public function testStudentGroupCanBeUpdated(): void | ||
{ | ||
$group = Group::factory()->create(); | ||
|
||
$this->assertDatabaseMissing("groups", [ | ||
"name" => "s1INF_1(1)", | ||
]); | ||
|
||
$this->patch("/dashboard/course-semester/{$group->course_semester_id}/groups/{$group->id}", [ | ||
"name" => "s1INF_1(1)", | ||
])->assertSessionHasNoErrors(); | ||
|
||
$this->assertDatabaseHas("groups", [ | ||
"name" => "s1INF_1(1)", | ||
]); | ||
} | ||
|
||
public function testStudentGroupCannotBeCreatedWithInvalidData(): void | ||
{ | ||
$this->post("/dashboard/course-semester/{$this->course->id}/groups", [ | ||
"name" => Str::random(256), | ||
])->assertSessionHasErrors([ | ||
"name", | ||
]); | ||
|
||
$this->assertDatabaseCount("groups", 0); | ||
} | ||
|
||
public function testStudentGroupCanBeDeleted(): void | ||
{ | ||
$group = Group::factory()->create(); | ||
$this->assertDatabaseCount("groups", 1); | ||
|
||
$this->delete("/dashboard/course-semester/{$group->course_semester_id}/groups/{$group->id}"); | ||
|
||
$this->assertDatabaseCount("groups", 0); | ||
} | ||
|
||
public function testStudentCanBeAddedToStudentGroup(): void | ||
{ | ||
$group = Group::factory()->create(); | ||
$student = Student::factory()->create(); | ||
$this->assertCount(0, $group->students); | ||
|
||
$this->post( | ||
"/dashboard/course-semester/{$group->course_semester_id}/groups/{$group->id}/students", | ||
[ | ||
"student" => $student->id, | ||
], | ||
)->assertSessionHasNoErrors(); | ||
|
||
$group->refresh(); | ||
$this->assertCount(1, $group->students); | ||
} | ||
|
||
public function testStudentCanBeAddedToStudentGroupOnlyOnce(): void | ||
{ | ||
$group = Group::factory()->create(); | ||
$student = Student::factory()->create(); | ||
$this->assertCount(0, $group->students); | ||
|
||
$this->post( | ||
"/dashboard/course-semester/{$group->course_semester_id}/groups/{$group->id}/students", | ||
[ | ||
"student" => $student->id, | ||
], | ||
)->assertSessionHasNoErrors(); | ||
|
||
$group->refresh(); | ||
$this->assertCount(1, $group->students); | ||
|
||
$this->post( | ||
"/dashboard/course-semester/{$group->course_semester_id}/groups/{$group->id}/students", | ||
[ | ||
"student" => $student->id, | ||
], | ||
)->assertSessionHasNoErrors(); | ||
|
||
$group->refresh(); | ||
$this->assertCount(1, $group->students); | ||
} | ||
|
||
public function testStudentCanBeRemovedFromStudentGroup(): void | ||
{ | ||
$group = Group::factory()->create(); | ||
$student = Student::factory()->create(); | ||
$this->assertCount(0, $group->students); | ||
|
||
$this->post( | ||
"/dashboard/course-semester/{$group->course_semester_id}/groups/{$group->id}/students", | ||
[ | ||
"student" => $student->id, | ||
], | ||
)->assertSessionHasNoErrors(); | ||
|
||
$group->refresh(); | ||
$this->assertCount(1, $group->students); | ||
|
||
$this->delete("/dashboard/course-semester/{$group->course_semester_id}/groups/{$group->id}/students/{$student->id}"); | ||
|
||
$group->refresh(); | ||
$this->assertCount(0, $group->students); | ||
} | ||
} |