|
3 | 3 | use App\Models\Client; |
4 | 4 | use App\TimeOfDay; |
5 | 5 | use Database\Factories\AnimalFactory; |
| 6 | +use Tests\TestCase; |
6 | 7 |
|
7 | 8 | $VALID_APPOINTMENT = [ |
8 | 9 | 'client' => [ |
|
22 | 23 | ], |
23 | 24 | ]; |
24 | 25 |
|
| 26 | +function scheduleAppointment(TestCase $self, array $data): void |
| 27 | +{ |
| 28 | + // Try to schedule an appointment |
| 29 | + $response = $self |
| 30 | + ->post(route('public.schedule-appointment'), $data); |
| 31 | + |
| 32 | + // Check for redirect. Since we're using Inertia, it redirects the user to the homepage on success |
| 33 | + $response->assertRedirect(route('public.home')); |
| 34 | +} |
| 35 | + |
25 | 36 | test('can not empty schedule appointment', function () { |
26 | 37 | $response = $this |
27 | 38 | ->post(route('public.schedule-appointment')); |
|
41 | 52 | ->post(route('public.schedule-appointment'), $data); |
42 | 53 |
|
43 | 54 | // Check for redirect. Since we're using Inertia, it redirects the user to the homepage on success |
44 | | - $response->assertRedirect(route('public.schedule-appointment')); |
| 55 | + $response->assertRedirect(route('public.home')); |
45 | 56 |
|
46 | 57 | // Check if data was saved |
47 | 58 | $this->assertDatabaseHas('clients', $data['client']); |
|
67 | 78 | // Ensure it exists |
68 | 79 | $this->assertDatabaseHas('clients', $clientData); |
69 | 80 |
|
70 | | - // Try to schedule an appointment |
71 | | - $response = $this |
72 | | - ->post(route('public.schedule-appointment'), $data); |
73 | | - |
74 | | - // Check for redirect. Since we're using Inertia, it redirects the user to the homepage on success |
75 | | - $response->assertRedirect(route('public.schedule-appointment')); |
| 81 | + scheduleAppointment($this, $data); |
76 | 82 |
|
77 | 83 | // Check if the client was updated |
78 | 84 | $this->assertDatabaseHas('clients', $data['client']); |
|
88 | 94 | ->post(route('public.schedule-appointment'), $data); |
89 | 95 |
|
90 | 96 | // Check for redirect. Since we're using Inertia, it redirects the user to the homepage on success |
91 | | - $response->assertRedirect(route('public.schedule-appointment')); |
| 97 | + $response->assertRedirect(route('public.home')); |
92 | 98 | } |
93 | 99 |
|
94 | 100 | // Check if the client was updated |
|
0 commit comments