From 05b557390ae8f2a53f185fd59dcd0bb8e56aeb49 Mon Sep 17 00:00:00 2001
From: Hugo SUBTIL <ext.sopra.husubtil@grandlyon.com>
Date: Thu, 12 May 2022 16:07:28 +0000
Subject: [PATCH] fix: add sonar again

---
 .gitlab-ci.yml                                | 85 ++++++++++++-------
 .../manage-users/manage-users.component.ts    |  6 +-
 .../structure-print-header.component.html     |  9 +-
 .../structure-list-search.component.spec.ts   | 14 ++-
 4 files changed, 69 insertions(+), 45 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 11f699b5d..0f3a7115d 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,5 +1,5 @@
 stages:
-  - sonar-analysis
+  - quality
   - build
   - deploy
 
@@ -16,6 +16,8 @@ build_branch:
     DOCKER_TLS_CERTDIR: ''
     DOCKER_HOST: tcp://docker:2375/
     DOCKER_DRIVER: overlay2
+  only:
+    - merge_requests
   image: ${CI_DEPENDENCY_PROXY_DIRECT_GROUP_IMAGE_PREFIX}/docker:18.09
   stage: build
   except:
@@ -102,36 +104,53 @@ deploy_rec:
   environment:
     name: rec
     url: https://resin-rec.grandlyon.com
-# code_analysis:
-#   image: skilldlabs/sonar-scanner:3.4.0
-#   services:
-#     - docker:18.09-dind
-#   stage: sonar-analysis
-#   only:
-#     - dev
-#   before_script:
-#     - export NODE_PATH=$NODE_PATH:`npm root -g`
-#     - npm install -g typescript
-#   script:
-#     - >
-#       sonar-scanner
-#       -Dsonar.projectName=${SONAR_PROJECT_KEY}
-#       -Dsonar.projectVersion=1.0
-#       -Dsonar.sourceEncoding=UTF-8
-#       -Dsonar.projectBaseDir=.
-#       -Dsonar.host.url=${SONAR_URL}
-#       -Dsonar.projectKey=${SONAR_PROJECT_KEY}
-#       -Dsonar.login=${SONAR_TOKEN}
 
-# mr:
-#   variables:
-#     DOCKER_TLS_CERTDIR: ''
-#     DOCKER_HOST: tcp://docker:2375/
-#     DOCKER_DRIVER: overlay2
-#   image: ${CI_DEPENDENCY_PROXY_DIRECT_GROUP_IMAGE_PREFIX}/docker:18.09
-#   stage: build
-#   only:
-#     - merge_requests
-#   script:
-#     - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
-#     - docker build --pull -t "$CI_REGISTRY_IMAGE:dev" --build-arg conf=dev .
+sonarqube:
+  stage: quality
+  only:
+    - dev
+  image: ${CI_DEPENDENCY_PROXY_DIRECT_GROUP_IMAGE_PREFIX}/sonarsource/sonar-scanner-cli:4
+  variables:
+    SONAR_USER_HOME: '${CI_PROJECT_DIR}/.sonar' # Defines the location of the analysis task cache
+    GIT_DEPTH: '0' # T
+  cache:
+    key: '${CI_JOB_NAME}'
+    paths:
+      - .sonar/cache
+  script:
+    - >
+      sonar-scanner
+      -Dsonar.projectName=${SONAR_PROJECT_KEY}
+      -Dsonar.projectVersion=1.0
+      -Dsonar.sourceEncoding=UTF-8
+      -Dsonar.projectBaseDir=.
+      -Dsonar.host.url=${SONAR_URL}
+      -Dsonar.projectKey=${SONAR_PROJECT_KEY}
+      -Dsonar.login=${SONAR_TOKEN}
+      -Dsonar.cpd.exclusions=tests/**,src/**/*.spec.ts*
+      -Dsonar.qualitygate.wait=true
+
+sonarqube-mr:
+  stage: quality
+  only:
+    - merge_requests
+  image: ${CI_DEPENDENCY_PROXY_DIRECT_GROUP_IMAGE_PREFIX}/sonarsource/sonar-scanner-cli:4
+  variables:
+    SONAR_USER_HOME: '${CI_PROJECT_DIR}/.sonar' # Defines the location of the analysis task cache
+    GIT_DEPTH: '0' # T
+  cache:
+    key: '${CI_JOB_NAME}'
+    paths:
+      - .sonar/cache
+  script:
+    - >
+      sonar-scanner
+      -Dsonar.projectName=${SONAR_PROJECT_KEY}
+      -Dsonar.projectVersion=1.0
+      -Dsonar.sourceEncoding=UTF-8
+      -Dsonar.projectBaseDir=.
+      -Dsonar.host.url=${SONAR_URL}
+      -Dsonar.projectKey=${SONAR_PROJECT_KEY}
+      -Dsonar.login=${SONAR_MR_TOKEN}
+      -Dsonar.cpd.exclusions=tests/**,src/**/*.spec.ts*
+      -Dsonar.qualitygate.wait=true
diff --git a/src/app/admin/components/manage-users/manage-users.component.ts b/src/app/admin/components/manage-users/manage-users.component.ts
index d4713e661..03399985c 100644
--- a/src/app/admin/components/manage-users/manage-users.component.ts
+++ b/src/app/admin/components/manage-users/manage-users.component.ts
@@ -1,8 +1,8 @@
 import { Component } from '@angular/core';
 import { User } from '../../../models/user.model';
 import { AdminService } from '../../services/admin.service';
-import { DeleteUserComponent } from './delete-user/delete-user.component';
 import { AdministredStructuresComponent } from './administred-structures/administred-structures.component';
+import { DeleteUserComponent } from './delete-user/delete-user.component';
 
 @Component({
   selector: 'app-admin-manage-users',
@@ -105,7 +105,7 @@ export class ManageUsersComponent {
   public findAttachedUsers(): void {
     this.adminService.getAttachedUsers().subscribe((users) => {
       this.attachedUsers = users;
-      this.attachedUsers.map((user) => {
+      this.attachedUsers.forEach((user) => {
         user._id = user['id'];
       });
     });
@@ -120,7 +120,7 @@ export class ManageUsersComponent {
   public findUnVerifiedUsers(): void {
     this.adminService.getUnVerifiedUsers().subscribe((users) => {
       this.unVerifiedUsers = users;
-      this.unVerifiedUsers.map((user) => {
+      this.unVerifiedUsers.forEach((user) => {
         user._id = user['id'];
       });
     });
diff --git a/src/app/form/orientation-form/component/structure-print-header/structure-print-header.component.html b/src/app/form/orientation-form/component/structure-print-header/structure-print-header.component.html
index 7c09be927..2e40f7336 100644
--- a/src/app/form/orientation-form/component/structure-print-header/structure-print-header.component.html
+++ b/src/app/form/orientation-form/component/structure-print-header/structure-print-header.component.html
@@ -25,8 +25,15 @@
     </div>
     <div class="beneficiary">
       <div class="informationHeader">{{ 'Bénéficiaire' | uppercase }}</div>
-      <!-- Name -->
+
       <table class="beneficiaryNeeds">
+        <caption style="display: none">
+          Résumé du besoin de l'utilisateur pour impresion.
+        </caption>
+        <thead style="display: none">
+          <th>Résumé de besoin</th>
+        </thead>
+        <!-- Name -->
         <tr>
           <td class="informationHeader">Nom</td>
           <td class="bold">{{ beneficiaryName }}</td>
diff --git a/src/app/structure-list/components/structure-list-search/structure-list-search.component.spec.ts b/src/app/structure-list/components/structure-list-search/structure-list-search.component.spec.ts
index d3480a964..1cac4adfa 100644
--- a/src/app/structure-list/components/structure-list-search/structure-list-search.component.spec.ts
+++ b/src/app/structure-list/components/structure-list-search/structure-list-search.component.spec.ts
@@ -1,13 +1,13 @@
+import { HttpClientTestingModule } from '@angular/common/http/testing';
 import { ComponentFixture, TestBed } from '@angular/core/testing';
 import { ReactiveFormsModule } from '@angular/forms';
+import { of } from 'rxjs';
+import { GeoJson } from '../../../map/models/geojson.model';
+import { GeojsonService } from '../../../services/geojson.service';
+import { TypeModal } from '../../enum/typeModal.enum';
 import { Filter } from '../../models/filter.model';
-import { HttpClientTestingModule } from '@angular/common/http/testing';
-import { StructureListSearchComponent } from './structure-list-search.component';
 import { Module } from '../../models/module.model';
-import { TypeModal } from '../../enum/typeModal.enum';
-import { GeojsonService } from '../../../services/geojson.service';
-import { GeoJson } from '../../../map/models/geojson.model';
-import { of } from 'rxjs';
+import { StructureListSearchComponent } from './structure-list-search.component';
 
 describe('StructureListSearchComponent', () => {
   let component: StructureListSearchComponent;
@@ -104,7 +104,6 @@ describe('StructureListSearchComponent', () => {
     const checkedModules: Module[] = [{ id: evt.target.value, text: categ, count: 0 }];
     component.checkedModulesFilter = checkedModules;
     component.externalCheckboxCheck(evt, categ);
-    new Module(evt.target.value, categ);
     expect(component.checkedModulesFilter.length).toEqual(0);
     expect(component.numberMoreFiltersChecked).toEqual(0);
   });
@@ -122,7 +121,6 @@ describe('StructureListSearchComponent', () => {
     const checkedModules: Module[] = [{ id: evt.target.value, text: categ, count: 0 }];
     component.checkedModulesFilter = checkedModules;
     component.externalCheckboxCheck(evt, categ);
-    new Module(evt.target.value, categ);
     expect(component.checkedModulesFilter.length).toEqual(0);
     expect(component.numberMoreFiltersChecked).toEqual(0);
   });
-- 
GitLab