-
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.
* #5 - wip: crud for students * #5 - added creating students * #5 - wip: added editing students * #5 - added students deleting * #5 - cr fixes * #5 - added tests and search input on student index page * #5 - updated .env.ci
- Loading branch information
1 parent
abd9465
commit ddbb902
Showing
4 changed files
with
133 additions
and
4 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
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,90 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Feature\Frontend; | ||
|
||
use App\Models\Student; | ||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use Illuminate\Support\Str; | ||
use Tests\TestCase; | ||
|
||
class StudentTest extends TestCase | ||
{ | ||
use RefreshDatabase; | ||
|
||
public function testStudentCanBeCreated(): void | ||
{ | ||
$this->assertDatabaseCount("students", 0); | ||
|
||
$this->post("/dashboard/students", [ | ||
"name" => "Name", | ||
"surname" => "Surname", | ||
"index_number" => "12345", | ||
])->assertSessionHasNoErrors(); | ||
|
||
$this->assertDatabaseCount("students", 1); | ||
} | ||
|
||
public function testStudentCanBeUpdated(): void | ||
{ | ||
$student = Student::factory()->create(); | ||
|
||
$this->assertDatabaseMissing("students", [ | ||
"name" => "Name", | ||
"surname" => "Surname", | ||
"index_number" => "12345", | ||
]); | ||
|
||
$this->patch("/dashboard/students/{$student->id}", [ | ||
"name" => "Name", | ||
"surname" => "Surname", | ||
"index_number" => "12345", | ||
])->assertSessionHasNoErrors(); | ||
|
||
$this->assertDatabaseHas("students", [ | ||
"name" => "Name", | ||
"surname" => "Surname", | ||
"index_number" => "12345", | ||
]); | ||
} | ||
|
||
public function testStudentCannotBeCreatedWithBusyIndex(): void | ||
{ | ||
Student::factory()->create(["index_number" => "12345"]); | ||
$this->assertDatabaseCount("students", 1); | ||
|
||
$this->post("/dashboard/students", [ | ||
"name" => "Name", | ||
"surname" => "Surname", | ||
"index_number" => "12345", | ||
])->assertSessionHasErrors("index_number"); | ||
|
||
$this->assertDatabaseCount("students", 1); | ||
} | ||
|
||
public function testStudentCannotBeCreatedWithInvalidData(): void | ||
{ | ||
$this->post("/dashboard/students", [ | ||
"name" => Str::random(256), | ||
"surname" => Str::random(256), | ||
"index_number" => Str::random(256), | ||
])->assertSessionHasErrors([ | ||
"name", | ||
"surname", | ||
"index_number", | ||
]); | ||
|
||
$this->assertDatabaseCount("students", 0); | ||
} | ||
|
||
public function testStudentCanBeDeleted(): void | ||
{ | ||
$student = Student::factory()->create(); | ||
$this->assertDatabaseCount("students", 1); | ||
|
||
$this->delete("/dashboard/students/{$student->id}"); | ||
|
||
$this->assertDatabaseCount("students", 0); | ||
} | ||
} |