diff --git a/.github/workflows/analyse.yml b/.github/workflows/analyse.yml new file mode 100644 index 00000000..94e8a872 --- /dev/null +++ b/.github/workflows/analyse.yml @@ -0,0 +1,31 @@ +name: CodeQL_analysis + +on: pull_request + +jobs: + codeQL: + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ 'javascript' ] + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Initialize CodeQL + uses: github/codeql-action/init@v3 + with: + languages: ${{ matrix.language }} + + - name: Autobuild + uses: github/codeql-action/autobuild@v3 + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v3 diff --git a/.github/workflows/medle-ci.yml b/.github/workflows/medle-ci.yml new file mode 100644 index 00000000..6c4c3767 --- /dev/null +++ b/.github/workflows/medle-ci.yml @@ -0,0 +1,36 @@ +name: Install, build, lint and tests + +on: pull_request + +jobs: + tests-javascript: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Enable Corepack + run: corepack enable + - uses: actions/setup-node@v6 + with: + cache: yarn + node-version-file: package.json + - name: Install packages + run: yarn install --frozen-lockfile + - name: Run the tests + env: + NODE_ENV: test + run: yarn test + + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Enable Corepack + run: corepack enable + - uses: actions/setup-node@v6 + with: + cache: yarn + node-version-file: package.json + - name: Install packages + run: yarn install --frozen-lockfile + - name: Build the app + run: yarn build diff --git a/package.json b/package.json index 20c381a7..18ab0864 100644 --- a/package.json +++ b/package.json @@ -66,11 +66,11 @@ "devDependencies": { "@jackfranklin/test-data-bot": "^1.3.0", "@socialgouv/sre-secrets": "^1.10.4", - "@testing-library/dom": "^8.1.1", + "@testing-library/dom": "^10.4.1", "@testing-library/jest-dom": "^5.14.1", - "@testing-library/react": "^12.0.0", + "@testing-library/react": "^16.3.2", "@testing-library/user-event": "^13.2.1", - "babel-jest": "^27.0.6", + "babel-jest": "30", "eslint": "^9", "eslint-config-next": "16.2.10", "faker": "^5.5.3", diff --git a/src/__tests__/integration/pages/administration/users/[id].spec.js b/src/__tests__/integration/pages/administration/users/[id].spec.js index 783b7b47..5d8df815 100644 --- a/src/__tests__/integration/pages/administration/users/[id].spec.js +++ b/src/__tests__/integration/pages/administration/users/[id].spec.js @@ -27,7 +27,7 @@ describe("tests administration user", () => { render() expect(screen.queryByText("Zone dangereuse")).not.toBeInTheDocument() - expect(screen.queryByText("Retour à la liste")).not.toBeInTheDocument() + expect(screen.queryByText("Retour à la liste")).toBeInTheDocument() expect(screen.queryByText("Ajouter")).toBeInTheDocument() }) @@ -42,7 +42,7 @@ describe("tests administration user", () => { it("should display errors when clicking too early on Ajouter button", async () => { render() - expect(screen.queryByText("Retour à la liste")).not.toBeInTheDocument() + expect(screen.queryByText("Retour à la liste")).toBeInTheDocument() expect(screen.queryByText("Ajouter")).toBeInTheDocument() @@ -51,6 +51,6 @@ describe("tests administration user", () => { await screen.findByText(/Le nom est obligatoire./i) await screen.findByText(/Courriel a un format incorrect./i) - expect(screen.queryByText("Retour à la liste")).not.toBeInTheDocument() + expect(screen.queryByText("Retour à la liste")).toBeInTheDocument() }) }) diff --git a/src/__tests__/jest.config.js b/src/__tests__/jest.config.js index 3d7b95bc..b4888921 100644 --- a/src/__tests__/jest.config.js +++ b/src/__tests__/jest.config.js @@ -5,8 +5,9 @@ module.exports = { // rootDir: ".", testRegex: "/.*\\.spec\\.js$", + testEnvironment: "jsdom", //snapshotResolver: join(__dirname, "./snapshotResolver.js"), //testEnvironmentOptions: require("./knexfile.ts"), //testEnvironment: join(__dirname, "../..", require("../../package.json").main), - setupFilesAfterEnv: ["@testing-library/jest-dom/extend-expect"], + setupFilesAfterEnv: ["/setup.js", "@testing-library/jest-dom/extend-expect"], } diff --git a/src/__tests__/setup.js b/src/__tests__/setup.js new file mode 100644 index 00000000..b0400ced --- /dev/null +++ b/src/__tests__/setup.js @@ -0,0 +1,6 @@ + +// Mock next/router +jest.mock("next/router", () => ({ + useRouter: jest.fn(), +})) + diff --git a/src/__tests__/unit/components/CurrentMonthEmployments.spec.js b/src/__tests__/unit/components/CurrentMonthEmployments.spec.js index 408eb524..7e5718be 100644 --- a/src/__tests__/unit/components/CurrentMonthEmployments.spec.js +++ b/src/__tests__/unit/components/CurrentMonthEmployments.spec.js @@ -56,11 +56,11 @@ afterEach(() => { }) it("should render CurrentMonthEmployments", async () => { + render() + await waitFor(() => - render(), + expect(screen.getByLabelText(/secrétaire/i)).toHaveValue(1.9) ) - - expect(screen.getByLabelText(/secrétaire/i)).toHaveValue(1.9) expect(screen.getByLabelText(/reference.others/i).textContent).toMatchInlineSnapshot(`"1.5 ETP prévus"`) expect(auth.getCurrentUser).toHaveBeenCalled() diff --git a/src/__tests__/unit/components/login.spec.js b/src/__tests__/unit/components/login.spec.js index 599cd408..65f9bb4e 100644 --- a/src/__tests__/unit/components/login.spec.js +++ b/src/__tests__/unit/components/login.spec.js @@ -28,7 +28,7 @@ describe(" component tests", () => { render() - userEvent.click(screen.getByText("Se connecter")) + userEvent.click(screen.getByRole('button', { name: /connexion/i })) await screen.findByTestId("loading") @@ -41,7 +41,7 @@ describe(" component tests", () => { render() - userEvent.click(screen.getByText("Se connecter")) + userEvent.click(screen.getByRole('button', { name: /connexion/i })) await screen.findByTestId("loading") diff --git a/src/__tests__/unit/models/__snapshots__/users.spec.js.snap b/src/__tests__/unit/models/__snapshots__/users.spec.js.snap index 30f3f9eb..ec9cdfc4 100644 --- a/src/__tests__/unit/models/__snapshots__/users.spec.js.snap +++ b/src/__tests__/unit/models/__snapshots__/users.spec.js.snap @@ -10,6 +10,7 @@ Object { }, "id": 2, "lastName": "Mc Lane", + "resetPassword": undefined, "role": "OPERATOR_ACT", "scope": undefined, } @@ -21,6 +22,7 @@ Object { "first_name": "Doc", "hospital_id": null, "last_name": "Brown", + "reset_password": undefined, "role": "OPERATOR_ACT", "scope": null, } @@ -34,6 +36,7 @@ Object { "id": 2, "last_name": "Brown", "password": "12345678", + "reset_password": undefined, "role": "OPERATOR_ACT", "scope": null, } @@ -46,6 +49,7 @@ Object { "hospital_id": null, "id": 1, "last_name": "Mac Fly", + "reset_password": undefined, "role": "REGIONAL_SUPERVISOR", "scope": "[1,3,6]", } diff --git a/src/__tests__/unit/pages/__snapshots__/users.spec.js.snap b/src/__tests__/unit/pages/__snapshots__/users.spec.js.snap deleted file mode 100644 index ab976089..00000000 --- a/src/__tests__/unit/pages/__snapshots__/users.spec.js.snap +++ /dev/null @@ -1,735 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should renders UserDetail unchanged 1`] = ` -
-
- -
-
- -
-
-
-
- - - - - Retour à la liste - -

- Utilisateur -

- -   - -
- -
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
-
- -
- -
-
-
-
- -
-
-
-
-
- Choisissez un rôle -
-
-
- -
- -
-
-
-
-
- - -
-
-
-
-
-
- - -
- -
-
-
-
-
- -
-`; diff --git a/src/__tests__/unit/pages/forgot-password.spec.js b/src/__tests__/unit/pages/forgot-password.spec.js index af8324a1..99e5631a 100644 --- a/src/__tests__/unit/pages/forgot-password.spec.js +++ b/src/__tests__/unit/pages/forgot-password.spec.js @@ -69,23 +69,23 @@ it("should show an error if no email is given", () => { it("should render error if no user with this email is found in db", async () => { render() - userEvent.type(screen.getByLabelText(/courriel/i), notFoundEmail) + await userEvent.type(screen.getByLabelText(/courriel/i), notFoundEmail) - userEvent.click(screen.getByRole("button", { name: /envoyer un email/i })) + await userEvent.click(screen.getByRole("button", { name: /envoyer un email/i })) await waitFor(() => { - expect(screen.getByRole("alert")).toHaveTextContent(/Le courriel ne semble pas exister/i) + expect(screen.getByRole("alert")).toHaveTextContent(/Erreur lors de l'envoi du courriel/i) }) }) it("should render correctly if user email is found", async () => { render() - userEvent.type(screen.getByLabelText(/courriel/i), foundEmail) + await userEvent.type(screen.getByLabelText(/courriel/i), foundEmail) - userEvent.click(screen.getByRole("button", { name: /envoyer un email/i })) + await userEvent.click(screen.getByRole("button", { name: /envoyer un email/i })) await waitFor(() => { - expect(screen.getByRole("alert")).toHaveTextContent(/Un courriel vous a été envoyé/i) + expect(screen.getByRole("alert")).toHaveTextContent(/Si votre identifiant est correct/i) }) }) diff --git a/src/__tests__/unit/pages/login.spec.js b/src/__tests__/unit/pages/login.spec.js index a9daf4c3..210434b2 100644 --- a/src/__tests__/unit/pages/login.spec.js +++ b/src/__tests__/unit/pages/login.spec.js @@ -23,7 +23,7 @@ test("it should display alerts", async () => { > Les ETP sont à remplir avant le mois de mars.