diff --git a/app/Calculator/MaturityAnswerLevelCalculator.php b/app/Calculator/MaturityAnswerLevelCalculator.php index b8926c99fb5909e19c84fba550c9d2e5bbf11f17..f096bf7dd4156b9968d44c8cbd4ac1f9712e0f47 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 81c6ce7ec38bc5545f65e88fefaade12059d5f02..b913bde442e710969bb45027d18cde54312272c8 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 d585ba94a0c2982380fa5f63d1bc6b29b259db0a..6e868b43cb6092981507507d8cf4125af40525e4 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 fb34372b8d8bb865dc1e0c9d431a6189734960a7..d439b7ca35ca4a02f8ff751f4d4ec0d7dd391d61 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);