/ tests / Services / ValidationTypeServiceTest.php
ValidationTypeServiceTest.php
 1  <?php
 2  
 3  namespace Tests\Services;
 4  
 5  use App\Http\Services\ValidationTypeService;
 6  use App\Models\Norm;
 7  use App\Models\RequirementTemplate;
 8  use App\Models\ValidationRequirement;
 9  use App\Models\ValidationType;
10  use Illuminate\Support\Collection;
11  use Tests\TestCase;
12  
13  class ValidationTypeServiceTest extends TestCase
14  {
15      public RequirementTemplate $template;
16      public Norm $norm;
17  
18      public function setUp(): void
19      {
20          parent::setUp();
21          $this->norm = Norm::factory()->create();
22          $this->template = RequirementTemplate::factory()->create([
23              'validation_type_id' => ValidationType::first()->id,
24          ]);
25      }
26  
27      public function testFind()
28      {
29          $this->assertInstanceOf(ValidationType::class, ValidationTypeService::find(ValidationType::first()->id));
30      }
31  
32      public function testValidationTypesName()
33      {
34          $this->assertInstanceOf(Collection::class, ValidationTypeService::validationTypesName());
35      }
36  
37      public function testSearchValidationTypes()
38      {
39          $query = ValidationTypeService::searchValidationTypes('hi', '', 'id', 'asc', []);
40          $this->assertInstanceOf(
41              \Illuminate\Database\Eloquent\Builder::class,
42              $query
43          );
44      }
45  
46      /**
47       * @throws \Throwable
48       */
49      public function testCreateRequirement()
50      {
51          $data = $this->exampleDataArray();
52          $created = ValidationTypeService::createRequirement($data['requirementData'], $data['relation']);
53          $this->assertTrue($created);
54      }
55  
56      /**
57       * @throws \Throwable
58       */
59      public function testUpdateRequirement()
60      {
61          $updated = ValidationTypeService::updateRequirement($this->exampleDataArray()['requirementData'], $this->template->id);
62          $this->assertTrue($updated);
63      }
64  
65      /**
66       * @throws \Throwable
67       */
68      public function testRemoveRequirement()
69      {
70          ValidationTypeService::removeRequirement($this->template->id);
71          $this->assertSoftDeleted($this->template);
72      }
73  
74      private function exampleDataArray() : array
75      {
76          $validationType = ValidationType::factory()->create();
77          return [
78              'requirementData' => [
79                  'title' => fake()->title,
80                  'automagic_class' => 'App\Utils\AutoRequirements\AutoValidators\Validation_1',
81                  'description' => 'New Description',
82                  'expertTip' => 'New Expert Tip',
83              ],
84              'relation' => [
85                  'validation_type_id' => $validationType->id,
86              ]
87          ];
88      }
89  }