diff --git a/.dockerignore b/.dockerignore index 1eaab02..e9795c7 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,4 +1,9 @@ node_modules/ *.env -Dockerfile +.angular +.idea +.vscode +coverage +Docker* +start.sh package-lock.json diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..5a14efc --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,32 @@ +name: Docker Build Check + +# Déclencheur pour chaque pull request +on: + workflow_call: + +jobs: + build: + runs-on: ubuntu-latest + + steps: + # 1. Checkout du code source du dépôt + - name: Checkout code + uses: actions/checkout@v3 + + # 2. Installation Node.js + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '22.18' # Spécifie la version de Node.js + + # 3. Installation des dépendances + - name: Install dependencies + run: npm ci + + # 4. Exécution des tests unitaires + - name: Run tests + run: npm run test:ci + + # 5. CI terminée + - name: CI completed + run: echo "✅CI process completed successfully.✅" diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml deleted file mode 100644 index a0dbf5a..0000000 --- a/.github/workflows/main.yaml +++ /dev/null @@ -1,16 +0,0 @@ -name: Main Workflow - -on: - push: - branches: - - main - pull_request: - branches: - - main - - dev - - feat/* - - fix/* - -jobs: - run-tests: - uses: ./.github/workflows/tests/docker-build.yaml diff --git a/.github/workflows/tests/docker-build.yaml b/.github/workflows/tests/docker-build.yaml deleted file mode 100644 index 097e1ba..0000000 --- a/.github/workflows/tests/docker-build.yaml +++ /dev/null @@ -1,62 +0,0 @@ -name: Docker Build Check - -# Déclencheur pour chaque pull request -on: - workflow_call: - -jobs: - build: - runs-on: ubuntu-latest - - steps: - # 1. Checkout du code source du dépôt - - name: Checkout code - uses: actions/checkout@v3 - - # 2. Configuration de QEMU pour le support multi-plateformes - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - # 3. Configuration de Docker Buildx pour la construction multi-arch - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - with: - platforms: linux/amd64,linux/arm64 - - # 4. Test de la construction du Dockerfile pour les architectures amd64 et arm64 - - name: Build local container - uses: docker/build-push-action@v4 - with: - tags: lastrea/trouvetonprofile:latest - push: false - platforms: linux/arm64 - load: true - - # 5. Vérification de la taille de l'image construite - - name: Check image size - run: docker images lastrea/trouvetonprofile:latest --format "{{.Size}}" - - # 6. Scan de l'image Docker pour détecter les vulnérabilités - - name: Scan Image - uses: anchore/scan-action@v3 - id: scan - with: - image: "lastrea/trouvetonprofile:latest" - fail-build: true - severity-cutoff: critical - output-format: sarif - - - name: Upload Anchore Scan SARIF Report - uses: github/codeql-action/upload-sarif@v2 - with: - sarif_file: ${{ steps.scan.outputs.sarif }} - - # 7. Vérification si la construction et le scan ont réussi - - name: Build and Scan verification - if: ${{ success() }} - run: echo "Dockerfile built and scanned successfully!" - - # 8. Envoi d'un message d'échec en cas d'erreur lors de la construction ou du scan - - name: Notify on failure - if: ${{ failure() }} - run: echo "The Dockerfile build or scan failed! Please review the changes." diff --git a/compose.yaml b/compose.yaml deleted file mode 100644 index 1690207..0000000 --- a/compose.yaml +++ /dev/null @@ -1,22 +0,0 @@ -volumes: - pb_data: - -networks: - ttp-net: - -services: - pocketbase: - image: ghcr.io/muchobien/pocketbase:latest - container_name: pocketbase - restart: unless-stopped - ports: - - 8090:8090 - networks: - - ttp-net - volumes: - - pb_data:/pb_data - healthcheck: - test: wget --no-verbose --tries=1 --spider http://localhost:8090/api/health || exit 1 - interval: 5s - timeout: 5s - retries: 5 diff --git a/package-lock.json b/package-lock.json index 33a5d5d..2d8ff36 100644 --- a/package-lock.json +++ b/package-lock.json @@ -44,11 +44,13 @@ "@types/jasmine": "~5.1.0", "@types/jest": "^30.0.0", "@types/node": "^18.18.0", + "@types/node-fetch": "^2.6.13", "autoprefixer": "^10.4.20", "jasmine-core": "~5.1.0", "jest": "^29.7.0", "jest-environment-jsdom": "^29.7.0", "jest-preset-angular": "^14.6.1", + "node-fetch": "^2.7.0", "postcss": "^8.4.47", "tailwindcss": "^3.4.12", "typescript": "~5.2.2" @@ -5562,6 +5564,17 @@ "undici-types": "~5.26.4" } }, + "node_modules/@types/node-fetch": { + "version": "2.6.13", + "resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.6.13.tgz", + "integrity": "sha512-QGpRVpzSaUs30JBSGPjOg4Uveu384erbHBoT1zeONvyCfwQxIkUshLAOqN/k9EjGviPRmWTTe6aH2qySWKTVSw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/node": "*", + "form-data": "^4.0.4" + } + }, "node_modules/@types/node-forge": { "version": "1.3.13", "resolved": "https://registry.npmjs.org/@types/node-forge/-/node-forge-1.3.13.tgz", @@ -13026,8 +13039,6 @@ "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", "dev": true, "license": "MIT", - "optional": true, - "peer": true, "dependencies": { "whatwg-url": "^5.0.0" }, @@ -13048,18 +13059,14 @@ "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==", "dev": true, - "license": "MIT", - "optional": true, - "peer": true + "license": "MIT" }, "node_modules/node-fetch/node_modules/webidl-conversions": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==", "dev": true, - "license": "BSD-2-Clause", - "optional": true, - "peer": true + "license": "BSD-2-Clause" }, "node_modules/node-fetch/node_modules/whatwg-url": { "version": "5.0.0", @@ -13067,8 +13074,6 @@ "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", "dev": true, "license": "MIT", - "optional": true, - "peer": true, "dependencies": { "tr46": "~0.0.3", "webidl-conversions": "^3.0.0" diff --git a/package.json b/package.json index ec0d5e5..34642c2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "trouve-ton-profile", - "version": "0.0.0", + "version": "1.0.0", "scripts": { "ng": "ng", "start": "ng serve", @@ -10,6 +10,7 @@ "test": "jest", "test:watch": "jest --watch", "test:coverage": "jest --coverage", + "test:ci": "jest --runInBand", "serve:ssr:TrouveTonProfile": "node dist/trouve-ton-profile/server/server.mjs" }, "private": true, @@ -50,11 +51,13 @@ "@types/jasmine": "~5.1.0", "@types/jest": "^30.0.0", "@types/node": "^18.18.0", + "@types/node-fetch": "^2.6.13", "autoprefixer": "^10.4.20", "jasmine-core": "~5.1.0", "jest": "^29.7.0", "jest-environment-jsdom": "^29.7.0", "jest-preset-angular": "^14.6.1", + "node-fetch": "^2.7.0", "postcss": "^8.4.47", "tailwindcss": "^3.4.12", "typescript": "~5.2.2" diff --git a/src/app/shared/features/login/login.component.spec.ts b/src/app/shared/features/login/login.component.spec.ts index 7ed316a..ebbfad5 100644 --- a/src/app/shared/features/login/login.component.spec.ts +++ b/src/app/shared/features/login/login.component.spec.ts @@ -21,6 +21,7 @@ describe('LoginComponent', () => { mockToastrService = { warning: jest.fn(), success: jest.fn(), + info: jest.fn(), error: jest.fn() }; @@ -41,6 +42,11 @@ describe('LoginComponent', () => { fixture.detectChanges(); }); + afterEach(() => { + // si le composant instancie subscriptions/timers + fixture.destroy(); + }); + it('should create', () => { expect(component).toBeTruthy(); }); @@ -79,9 +85,9 @@ describe('LoginComponent', () => { await component.login({email: 'fail@test.com', password: 'fail'}); - expect(mockToastrService.warning).toHaveBeenCalledWith( + expect(mockToastrService.info).toHaveBeenCalledWith( 'Vous devez vérifier votre adresse e-mail avant de vous connecter.', - 'Erreur de connexion', + 'Information de connexion', { closeButton: true, progressAnimation: 'decreasing', diff --git a/src/setup-jest.ts b/src/setup-jest.ts index 9c43e18..c7798c1 100644 --- a/src/setup-jest.ts +++ b/src/setup-jest.ts @@ -1,2 +1,9 @@ import { setupZoneTestEnv } from "jest-preset-angular/setup-env/zone"; +import * as fetch from 'node-fetch'; + +(global as any).fetch = fetch; +(global as any).Headers = fetch.Headers; +(global as any).Request = fetch.Request; +(global as any).Response = fetch.Response; + setupZoneTestEnv();