11<?php
22
33use App \Models \Client ;
4- use App \TimeOfDay ;
5- use Database \Factories \AnimalFactory ;
64use Tests \TestCase ;
5+ use Tests \TestData \AppointmentSchedule ;
76
8- $ VALID_APPOINTMENT = [
9- 'client ' => [
10- 'name ' => fake ()->name ,
11- 'email ' => fake ()->email ,
12- ],
13- 'animal ' => [
14- 'name ' => fake ()->randomElement (AnimalFactory::NAMES ),
15- 'type ' => fake ()->randomElement (AnimalFactory::TYPES ),
16- 'age_years ' => fake ()->numberBetween (1 , 20 ),
17- 'age_months ' => fake ()->numberBetween (0 , 12 ),
18- ],
19- 'appointment ' => [
20- 'preferred_date ' => fake ()->dateTimeInInterval (now (), '+30 days ' )->format ('Y-m-d ' ),
21- 'preferred_time ' => [fake ()->randomElement (TimeOfDay::selectable ())->value ],
22- 'symptoms ' => fake ()->realText (),
23- ],
24- ];
7+ $ VALID_APPOINTMENT = AppointmentSchedule::valid ();
258
269function scheduleAppointment (TestCase $ self , array $ data ): void
2710{
@@ -47,12 +30,7 @@ function scheduleAppointment(TestCase $self, array $data): void
4730test ('can schedule appointment ' , function () use ($ VALID_APPOINTMENT ) {
4831 $ data = $ VALID_APPOINTMENT ;
4932
50- // Try to schedule an appointment
51- $ response = $ this
52- ->post (route ('public.schedule-appointment ' ), $ data );
53-
54- // Check for redirect. Since we're using Inertia, it redirects the user to the homepage on success
55- $ response ->assertRedirect (route ('public.home ' ));
33+ scheduleAppointment ($ this , $ data );
5634
5735 // Check if data was saved
5836 $ this ->assertDatabaseHas ('clients ' , $ data ['client ' ]);
@@ -90,11 +68,7 @@ function scheduleAppointment(TestCase $self, array $data): void
9068
9169 // Try to schedule an appointment, twice, with the same data
9270 for ($ i = 0 ; $ i < 2 ; $ i ++) {
93- $ response = $ this
94- ->post (route ('public.schedule-appointment ' ), $ data );
95-
96- // Check for redirect. Since we're using Inertia, it redirects the user to the homepage on success
97- $ response ->assertRedirect (route ('public.home ' ));
71+ scheduleAppointment ($ this , $ data );
9872 }
9973
10074 // Check if the client was updated
0 commit comments