|
|
@@ -0,0 +1,58 @@
|
|
|
+<?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_medium' => 40,
|
|
|
+ 'active_students_max' => 90,
|
|
|
+ ], $rules);
|
|
|
+
|
|
|
+ $this->assertFalse($validValidator->errors()->has('active_students_min'));
|
|
|
+ $this->assertFalse($validValidator->errors()->has('active_students_medium'));
|
|
|
+ $this->assertFalse($validValidator->errors()->has('active_students_max'));
|
|
|
+
|
|
|
+ $invalidValidator = Validator::make([
|
|
|
+ 'active_students_min' => -5, // Below 0
|
|
|
+ 'active_students_medium' => 'string', // Not an integer
|
|
|
+ ], $rules);
|
|
|
+
|
|
|
+ $this->assertTrue($invalidValidator->errors()->has('active_students_min'));
|
|
|
+ $this->assertTrue($invalidValidator->errors()->has('active_students_medium'));
|
|
|
+ }
|
|
|
+
|
|
|
+ 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_medium = 55;
|
|
|
+ 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_medium', $array);
|
|
|
+ $this->assertArrayHasKey('active_students_max', $array);
|
|
|
+
|
|
|
+ $this->assertSame(25, $array['active_students_min']);
|
|
|
+ $this->assertSame(55, $array['active_students_medium']);
|
|
|
+ $this->assertSame(85, $array['active_students_max']);
|
|
|
+ }
|
|
|
+}
|