|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Studio\Totem\Tests\Feature; |
| 4 | + |
| 5 | +use Studio\Totem\Tests\TestCase; |
| 6 | + |
| 7 | +class TaskRequestTest extends TestCase |
| 8 | +{ |
| 9 | + private function validPayload(): array |
| 10 | + { |
| 11 | + return [ |
| 12 | + 'description' => 'Run cache:clear', |
| 13 | + 'command' => 'cache:clear', |
| 14 | + 'type' => 'expression', |
| 15 | + 'expression' => '* * * * *', |
| 16 | + ]; |
| 17 | + } |
| 18 | + |
| 19 | + public function test_description_is_required(): void |
| 20 | + { |
| 21 | + $this->signIn(); |
| 22 | + |
| 23 | + $this->post(route('totem.task.create'), array_merge($this->validPayload(), ['description' => ''])) |
| 24 | + ->assertSessionHasErrors('description'); |
| 25 | + } |
| 26 | + |
| 27 | + public function test_command_is_required(): void |
| 28 | + { |
| 29 | + $this->signIn(); |
| 30 | + |
| 31 | + $this->post(route('totem.task.create'), array_merge($this->validPayload(), ['command' => ''])) |
| 32 | + ->assertSessionHasErrors('command'); |
| 33 | + } |
| 34 | + |
| 35 | + public function test_expression_required_when_type_is_expression(): void |
| 36 | + { |
| 37 | + $this->signIn(); |
| 38 | + |
| 39 | + $this->post(route('totem.task.create'), array_merge($this->validPayload(), ['expression' => ''])) |
| 40 | + ->assertSessionHasErrors('expression'); |
| 41 | + } |
| 42 | + |
| 43 | + public function test_invalid_cron_expression_fails(): void |
| 44 | + { |
| 45 | + $this->signIn(); |
| 46 | + |
| 47 | + $this->post(route('totem.task.create'), array_merge($this->validPayload(), ['expression' => 'not-a-cron'])) |
| 48 | + ->assertSessionHasErrors('expression'); |
| 49 | + } |
| 50 | + |
| 51 | + public function test_frequencies_required_when_type_is_frequency(): void |
| 52 | + { |
| 53 | + $this->signIn(); |
| 54 | + |
| 55 | + $this->post(route('totem.task.create'), [ |
| 56 | + 'description' => 'Run cache:clear', |
| 57 | + 'command' => 'cache:clear', |
| 58 | + 'type' => 'frequency', |
| 59 | + ])->assertSessionHasErrors('frequencies'); |
| 60 | + } |
| 61 | + |
| 62 | + public function test_invalid_notification_email_fails(): void |
| 63 | + { |
| 64 | + $this->signIn(); |
| 65 | + |
| 66 | + $this->post(route('totem.task.create'), array_merge($this->validPayload(), [ |
| 67 | + 'notification_email_address' => 'not-an-email', |
| 68 | + ]))->assertSessionHasErrors('notification_email_address'); |
| 69 | + } |
| 70 | + |
| 71 | + public function test_notification_phone_too_short_fails(): void |
| 72 | + { |
| 73 | + $this->signIn(); |
| 74 | + |
| 75 | + $this->post(route('totem.task.create'), array_merge($this->validPayload(), [ |
| 76 | + 'notification_phone_number' => '1234567890', // 10 digits — below minimum of 11 |
| 77 | + ]))->assertSessionHasErrors('notification_phone_number'); |
| 78 | + } |
| 79 | +} |
0 commit comments