diff --git a/app/Http/Controllers/PatientController.php b/app/Http/Controllers/PatientController.php new file mode 100644 index 0000000..c672716 --- /dev/null +++ b/app/Http/Controllers/PatientController.php @@ -0,0 +1,18 @@ +validate([ + 'first_name' => 'required', + 'last_name' => 'required', + 'birthdate' => 'required', + ]); + Patient::create($data); + } +} diff --git a/app/Models/Patient.php b/app/Models/Patient.php new file mode 100644 index 0000000..5e390d3 --- /dev/null +++ b/app/Models/Patient.php @@ -0,0 +1,13 @@ + + */ +class PatientFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition() + { + return [ + // + ]; + } +} diff --git a/database/migrations/2023_06_03_234547_create_patients_table.php b/database/migrations/2023_06_03_234547_create_patients_table.php new file mode 100644 index 0000000..bdde4cf --- /dev/null +++ b/database/migrations/2023_06_03_234547_create_patients_table.php @@ -0,0 +1,34 @@ +id(); + $table->string('first_name', 50); + $table->string('last_name', 50); + $table->date('birthdate'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('patients'); + } +}; diff --git a/database/seeders/PatientSeeder.php b/database/seeders/PatientSeeder.php new file mode 100644 index 0000000..664eb40 --- /dev/null +++ b/database/seeders/PatientSeeder.php @@ -0,0 +1,19 @@ + + + diff --git a/routes/web.php b/routes/web.php index b130397..0d9acd6 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,5 +1,6 @@ get('/'); - - $response->assertStatus(200); - } -} diff --git a/tests/Feature/PatientTest.php b/tests/Feature/PatientTest.php new file mode 100644 index 0000000..5e29c6e --- /dev/null +++ b/tests/Feature/PatientTest.php @@ -0,0 +1,45 @@ +withoutExceptionHandling(); + $response = $this->get('/'); + $response->assertStatus(200); + } + + /** @test */ + public function a_patient_can_be_added() + { + $this->withoutExceptionHandling(); + $response = $this->post('/patient/create', [ + 'first_name' => 'Markus', + 'last_name' => 'Cobb', + 'birthdate' => '16/11/2002', + ]); + + $response->assertOk(); + $this->assertCount(1, Patient::all()); + } + + /** @test */ + public function is_required() + { + $response = $this->post('/patient/create', [ + 'first_name' => '', + 'last_name' => '', + 'birthdate' => '', + ]); + + $response->assertSessionHasErrors(['first_name', 'last_name', 'birthdate']); + } +}