From 98e36e4a2dd917cef6e2e035cc345bb31b273986 Mon Sep 17 00:00:00 2001
From: Jonathan Foucher <jfoucher@gmail.com>
Date: Tue, 26 Mar 2024 13:03:52 +0100
Subject: [PATCH] fix tests and CS

---
 app/Calculator/MaturityAnswerLevelCalculator.php   |  2 +-
 app/Http/Controllers/Api/EvaluationsController.php |  2 +-
 app/Repository/GraphDataRepository.php             |  2 +-
 tests/Feature/EvaluationsControllerTest.php        | 14 ++++++--------
 4 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/app/Calculator/MaturityAnswerLevelCalculator.php b/app/Calculator/MaturityAnswerLevelCalculator.php
index b8926c99..f096bf7d 100644
--- a/app/Calculator/MaturityAnswerLevelCalculator.php
+++ b/app/Calculator/MaturityAnswerLevelCalculator.php
@@ -35,7 +35,7 @@ public static function calculateExecutionLevel(Evaluation $evaluation, ?Evaluati
                     return $ml->measure_id === $pml->measure_id;
                 });
 
-                return $ml->actual_level === $previousLevel->expected_level;
+                return $previousLevel && $ml->actual_level === $previousLevel->expected_level;
             });
 
             // Calculate score
diff --git a/app/Http/Controllers/Api/EvaluationsController.php b/app/Http/Controllers/Api/EvaluationsController.php
index 81c6ce7e..b913bde4 100644
--- a/app/Http/Controllers/Api/EvaluationsController.php
+++ b/app/Http/Controllers/Api/EvaluationsController.php
@@ -244,7 +244,7 @@ private function deleteMaturityStep($evaluation)
             ->delete();
     }
 
-    public function delete(?int $id = null)
+    public function delete(int $id = null)
     {
         $user = Auth::user();
 
diff --git a/app/Repository/GraphDataRepository.php b/app/Repository/GraphDataRepository.php
index d585ba94..6e868b43 100644
--- a/app/Repository/GraphDataRepository.php
+++ b/app/Repository/GraphDataRepository.php
@@ -426,7 +426,7 @@ public function getActionTerritoryGraphData(): array
         ];
     }
 
-    public function getOrganizationData(?int $territory_id = null)
+    public function getOrganizationData(int $territory_id = null)
     {
         $orgQuery = Organization::where('active', true);
 
diff --git a/tests/Feature/EvaluationsControllerTest.php b/tests/Feature/EvaluationsControllerTest.php
index fb34372b..d439b7ca 100644
--- a/tests/Feature/EvaluationsControllerTest.php
+++ b/tests/Feature/EvaluationsControllerTest.php
@@ -402,27 +402,25 @@ public function testPutEvaluationShouldSaveEvaluationWithFinishedStep()
 
         $data = $response->json();
 
-        $newEval = Evaluation::find($eval['id']);
+        $dbEval = Evaluation::with(['organization', 'dangerLevels', 'measureLevels', 'maturityLevels'])->find($eval['id']);
 
         $this->assertEquals([
-            'id' => $eval['id'],
+            'id' => $dbEval['id'],
             'status' => Evaluation::STATUS_DONE,
             'current_step' => Evaluation::STEP_RESULTS,
-            'author' => $eval['author'],
+            'author' => $dbEval['author'],
             'updated_by' => $user->firstname . ' ' . $user->lastname,
             'organization_id' => $user->organization_id,
             'organization' => $user->organization->toArray(),
             'created_at' => $data['created_at'],
             'updated_at' => $data['updated_at'],
             'danger_levels' => $data['danger_levels'],
-            'measure_levels' => $eval['measure_levels'],
-            'maturity_levels' => $eval['maturity_levels'],
+            'measure_levels' => $data['measure_levels'],
+            'maturity_levels' => $dbEval->maturityLevels->toArray(),
             'reference' => env('REFERENTIEL_VERSION'),
-            'maturity_cyber' => $newEval->maturity_cyber,
+            'maturity_cyber' => $dbEval->maturityCyber,
         ], $data);
 
-        $dbEval = Evaluation::with(['organization', 'dangerLevels', 'measureLevels', 'maturityLevels'])->find($eval['id']);
-
         $this->assertNotNull($dbEval);
 
         $this->assertEquals($dbEval->toArray(), $data);
-- 
GitLab