| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- namespace Tests\Unit;
- use App\Http\Requests\UnitRequest;
- use App\Http\Resources\UnitResource;
- use App\Models\Unit;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Validator;
- use Tests\TestCase;
- class UnitSettingsTest extends TestCase
- {
- public function test_unit_request_validates_active_students_ranges(): void
- {
- $rules = (new UnitRequest)->rules();
- $validValidator = Validator::make([
- 'active_students_min' => 10,
- 'active_students_max' => 90,
- ], $rules);
- $this->assertFalse($validValidator->errors()->has('active_students_min'));
- $this->assertFalse($validValidator->errors()->has('active_students_max'));
- $invalidValidator = Validator::make([
- 'active_students_min' => -5, // Below 0
- 'active_students_max' => 'string', // Not an integer
- ], $rules);
- $this->assertTrue($invalidValidator->errors()->has('active_students_min'));
- $this->assertTrue($invalidValidator->errors()->has('active_students_max'));
- }
- public function test_unit_resource_includes_active_students_ranges(): void
- {
- $unit = current(array_filter([new class extends Unit {
- public $active_students_min = 25;
- public $active_students_max = 85;
- public $name = 'Teste';
- public $social_reason = 'Teste';
- }]));
- $resource = new UnitResource($unit);
- $array = $resource->toArray(Request::create('/'));
- $this->assertArrayHasKey('active_students_min', $array);
- $this->assertArrayHasKey('active_students_max', $array);
- $this->assertSame(25, $array['active_students_min']);
- $this->assertSame(85, $array['active_students_max']);
- }
- }
|