| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- <?php
- namespace Tests\Unit\Requests;
- use App\Http\Requests\StoreReclamationRequest;
- use Illuminate\Support\Facades\Validator;
- use Tests\TestCase;
- class StoreReclamationRequestTest extends TestCase
- {
- /**
- * Return rules with exists constraints replaced so we can test
- * required/type/format rules without a database connection.
- */
- private function rulesWithoutExists(): array
- {
- $rules = (new StoreReclamationRequest())->rules();
- $rules['user_id'] = 'required';
- $rules['status_id'] = 'required';
- $rules['brigadier_id'] = 'nullable';
- return $rules;
- }
- public function test_empty_data_fails(): void
- {
- $validator = Validator::make([], $this->rulesWithoutExists());
- $this->assertTrue($validator->fails());
- }
- public function test_missing_user_id_fails(): void
- {
- $data = [
- 'status_id' => 1,
- 'create_date' => '2026-01-01',
- 'finish_date' => '2026-02-01',
- ];
- $validator = Validator::make($data, $this->rulesWithoutExists());
- $this->assertTrue($validator->fails());
- $this->assertArrayHasKey('user_id', $validator->errors()->toArray());
- }
- public function test_missing_status_id_fails(): void
- {
- $data = [
- 'user_id' => 1,
- 'create_date' => '2026-01-01',
- 'finish_date' => '2026-02-01',
- ];
- $validator = Validator::make($data, $this->rulesWithoutExists());
- $this->assertTrue($validator->fails());
- $this->assertArrayHasKey('status_id', $validator->errors()->toArray());
- }
- public function test_missing_create_date_fails(): void
- {
- $data = [
- 'user_id' => 1,
- 'status_id' => 1,
- 'finish_date' => '2026-02-01',
- ];
- $validator = Validator::make($data, $this->rulesWithoutExists());
- $this->assertTrue($validator->fails());
- $this->assertArrayHasKey('create_date', $validator->errors()->toArray());
- }
- public function test_missing_finish_date_fails(): void
- {
- $data = [
- 'user_id' => 1,
- 'status_id' => 1,
- 'create_date' => '2026-01-01',
- ];
- $validator = Validator::make($data, $this->rulesWithoutExists());
- $this->assertTrue($validator->fails());
- $this->assertArrayHasKey('finish_date', $validator->errors()->toArray());
- }
- public function test_invalid_create_date_format_fails(): void
- {
- $data = [
- 'user_id' => 1,
- 'status_id' => 1,
- 'create_date' => 'not-a-date',
- 'finish_date' => '2026-02-01',
- ];
- $validator = Validator::make($data, $this->rulesWithoutExists());
- $this->assertTrue($validator->fails());
- $this->assertArrayHasKey('create_date', $validator->errors()->toArray());
- }
- public function test_invalid_finish_date_format_fails(): void
- {
- $data = [
- 'user_id' => 1,
- 'status_id' => 1,
- 'create_date' => '2026-01-01',
- 'finish_date' => 'bad-date',
- ];
- $validator = Validator::make($data, $this->rulesWithoutExists());
- $this->assertTrue($validator->fails());
- $this->assertArrayHasKey('finish_date', $validator->errors()->toArray());
- }
- public function test_valid_required_fields_pass_non_exists_rules(): void
- {
- $data = [
- 'user_id' => 1,
- 'status_id' => 1,
- 'create_date' => '2026-01-01',
- 'finish_date' => '2026-06-30',
- ];
- $validator = Validator::make($data, $this->rulesWithoutExists());
- $this->assertFalse($validator->fails());
- }
- public function test_nullable_fields_accept_null_values(): void
- {
- $data = [
- 'user_id' => 1,
- 'status_id' => 1,
- 'create_date' => '2026-01-01',
- 'finish_date' => '2026-06-30',
- 'reason' => null,
- 'guarantee' => null,
- 'whats_done' => null,
- 'comment' => null,
- 'work_days' => null,
- ];
- $validator = Validator::make($data, $this->rulesWithoutExists());
- $this->assertFalse($validator->fails());
- }
- public function test_factory_reclamation_number_max_length_fails(): void
- {
- $data = [
- 'user_id' => 1,
- 'status_id' => 1,
- 'create_date' => '2026-01-01',
- 'finish_date' => '2026-06-30',
- 'factory_reclamation_number' => str_repeat('a', 256),
- ];
- $validator = Validator::make($data, $this->rulesWithoutExists());
- $this->assertTrue($validator->fails());
- $this->assertArrayHasKey('factory_reclamation_number', $validator->errors()->toArray());
- }
- public function test_invalid_start_work_date_fails(): void
- {
- $data = [
- 'user_id' => 1,
- 'status_id' => 1,
- 'create_date' => '2026-01-01',
- 'finish_date' => '2026-06-30',
- 'start_work_date' => 'invalid',
- ];
- $validator = Validator::make($data, $this->rulesWithoutExists());
- $this->assertTrue($validator->fails());
- $this->assertArrayHasKey('start_work_date', $validator->errors()->toArray());
- }
- }
|