From 598633daacabbcbf19b0738ce3de5e2f758ff556 Mon Sep 17 00:00:00 2001 From: Douglas DUTEIL Date: Tue, 18 Feb 2025 10:14:34 +0100 Subject: [PATCH] refactor: from mocha chai to vitest --- package-lock.json | 546 +++++++++++++++--- package.json | 11 +- packages/identite/package.json | 14 +- .../email-domain/add-domain.test.ts | 4 +- ...d-email-domains-by-organization-id.test.ts | 4 +- .../organization/find-by-id.test.ts | 4 +- .../get-users-by-organization.test.ts | 4 +- .../repositories/organization/upset.test.ts | 4 +- .../src/repositories/user/create.test.ts | 15 +- .../repositories/user/find-by-email.test.ts | 39 +- .../src/repositories/user/find-by-id.test.ts | 39 +- .../update-user-organization-link.test.ts | 60 +- .../src/repositories/user/update.test.ts | 29 +- test/acr-checks.test.ts | 50 +- test/api-annuaire-education-nationale.test.ts | 12 +- test/api-annuaire-service-public.test.ts | 17 +- test/base64.test.ts | 8 +- test/email.test.ts | 6 +- test/env.zod.test.ts | 189 +++--- test/epoch-time.test.ts | 18 +- ...thub-passkey-authenticator-aaguids.test.ts | 19 +- test/hash-to-postgres-params.test.ts | 4 +- test/is-expired.test.ts | 23 +- test/json-parse-with-date.test.ts | 6 +- ...return-one-organization-in-payload.test.ts | 22 +- ...l-contact-email-verification-token.test.ts | 25 +- test/organization.test.ts | 84 ++- test/symmetric-encryption.test.ts | 10 +- 28 files changed, 810 insertions(+), 456 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1fcd87dd2..fb1db933c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -70,8 +70,6 @@ "@simplewebauthn/types": "^10.0.0", "@simplewebauthn/typescript-types": "^8.3.4", "@sinonjs/fake-timers": "^11.2.2", - "@types/chai": "^5.0.1", - "@types/chai-as-promised": "^7.1.8", "@types/console-log-level": "^1.4.5", "@types/cookie-parser": "^1.4.7", "@types/ejs": "^3.1.5", @@ -81,7 +79,6 @@ "@types/http-errors": "^2.0.4", "@types/lodash": "^4.17.10", "@types/lodash-es": "^4.17.12", - "@types/mocha": "^10.0.10", "@types/morgan": "^1.9.9", "@types/node": "^22.10.2", "@types/nodemailer": "^6.4.16", @@ -89,8 +86,6 @@ "@types/qrcode": "^1.5.5", "@types/sinonjs__fake-timers": "^8.1.5", "axe-core": "^4.8.4", - "chai": "^5.1.2", - "chai-as-promised": "^8.0.1", "concurrently": "^9.0.1", "copy-and-watch": "^0.1.6", "csv": "^6.3.9", @@ -98,7 +93,6 @@ "cypress-axe": "^1.6.0", "cypress-maildev": "^1.3.2", "lodash": "^4.17.21", - "mocha": "^11.0.1", "nock": "^13.5.6", "node-pg-migrate": "^7.6.1", "npm-run-all2": "^6.1.2", @@ -106,7 +100,8 @@ "prettier-plugin-organize-imports": "^4.1.0", "tld-extract": "^2.1.0", "typescript": "^5.7.2", - "vite": "^5.4.12" + "vite": "^5.4.12", + "vitest": "^3.0.5" }, "engines": { "node": "^22.13.1" @@ -2745,25 +2740,6 @@ "@types/node": "*" } }, - "node_modules/@types/chai": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/@types/chai/-/chai-5.0.1.tgz", - "integrity": "sha512-5T8ajsg3M/FOncpLYW7sdOcD6yf4+722sze/tc4KQV0P8Z2rAr3SAuHCIkYmYpt8VbcQlnz8SxlOlPQYefe4cA==", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/deep-eql": "*" - } - }, - "node_modules/@types/chai-as-promised": { - "version": "7.1.8", - "resolved": "https://registry.npmjs.org/@types/chai-as-promised/-/chai-as-promised-7.1.8.tgz", - "integrity": "sha512-ThlRVIJhr69FLlh6IctTXFkmhtP3NpMZ2QGq69StYLyKZFp/HOp1VdKZj7RvfNWYYcJ1xlbLGLLWj1UvP5u/Gw==", - "dev": true, - "dependencies": { - "@types/chai": "*" - } - }, "node_modules/@types/connect": { "version": "3.4.36", "resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.36.tgz", @@ -2807,13 +2783,6 @@ "@types/node": "*" } }, - "node_modules/@types/deep-eql": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/@types/deep-eql/-/deep-eql-4.0.2.tgz", - "integrity": "sha512-c9h9dVVMigMPc4bwTvC5dxqtqJZwQPePsWjPlpSOnojbor6pGqdk541lfA7AqFQr5pB1BRdq0juY9db81BwyFw==", - "dev": true, - "license": "MIT" - }, "node_modules/@types/ejs": { "version": "3.1.5", "resolved": "https://registry.npmjs.org/@types/ejs/-/ejs-3.1.5.tgz", @@ -3055,14 +3024,14 @@ } }, "node_modules/@vitest/expect": { - "version": "2.1.8", - "resolved": "https://registry.npmjs.org/@vitest/expect/-/expect-2.1.8.tgz", - "integrity": "sha512-8ytZ/fFHq2g4PJVAtDX57mayemKgDR6X3Oa2Foro+EygiOJHUXhCqBAAKQYYajZpFoIfvBCF1j6R6IYRSIUFuw==", + "version": "2.1.9", + "resolved": "https://registry.npmjs.org/@vitest/expect/-/expect-2.1.9.tgz", + "integrity": "sha512-UJCIkTBenHeKT1TTlKMJWy1laZewsRIzYighyYiJKZreqtdxSos/S1t+ktRMQWu2CKqaarrkeszJx1cgC5tGZw==", "dev": true, "license": "MIT", "dependencies": { - "@vitest/spy": "2.1.8", - "@vitest/utils": "2.1.8", + "@vitest/spy": "2.1.9", + "@vitest/utils": "2.1.9", "chai": "^5.1.2", "tinyrainbow": "^1.2.0" }, @@ -3070,10 +3039,60 @@ "url": "https://opencollective.com/vitest" } }, + "node_modules/@vitest/mocker": { + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/@vitest/mocker/-/mocker-3.0.5.tgz", + "integrity": "sha512-CLPNBFBIE7x6aEGbIjaQAX03ZZlBMaWwAjBdMkIf/cAn6xzLTiM3zYqO/WAbieEjsAZir6tO71mzeHZoodThvw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vitest/spy": "3.0.5", + "estree-walker": "^3.0.3", + "magic-string": "^0.30.17" + }, + "funding": { + "url": "https://opencollective.com/vitest" + }, + "peerDependencies": { + "msw": "^2.4.9", + "vite": "^5.0.0 || ^6.0.0" + }, + "peerDependenciesMeta": { + "msw": { + "optional": true + }, + "vite": { + "optional": true + } + } + }, + "node_modules/@vitest/mocker/node_modules/@vitest/spy": { + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/@vitest/spy/-/spy-3.0.5.tgz", + "integrity": "sha512-5fOzHj0WbUNqPK6blI/8VzZdkBlQLnT25knX0r4dbZI9qoZDf3qAdjoMmDcLG5A83W6oUUFJgUd0EYBc2P5xqg==", + "dev": true, + "license": "MIT", + "dependencies": { + "tinyspy": "^3.0.2" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/mocker/node_modules/estree-walker": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-3.0.3.tgz", + "integrity": "sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/estree": "^1.0.0" + } + }, "node_modules/@vitest/pretty-format": { - "version": "2.1.8", - "resolved": "https://registry.npmjs.org/@vitest/pretty-format/-/pretty-format-2.1.8.tgz", - "integrity": "sha512-9HiSZ9zpqNLKlbIDRWOnAWqgcA7xu+8YxXSekhr0Ykab7PAYFkhkwoqVArPOtJhPmYeE2YHgKZlj3CP36z2AJQ==", + "version": "2.1.9", + "resolved": "https://registry.npmjs.org/@vitest/pretty-format/-/pretty-format-2.1.9.tgz", + "integrity": "sha512-KhRIdGV2U9HOUzxfiHmY8IFHTdqtOhIzCpd8WRdJiE7D/HUcZVD0EgQCVjm+Q9gkUXWgBvMmTtZgIG48wq7sOQ==", "dev": true, "license": "MIT", "dependencies": { @@ -3083,10 +3102,100 @@ "url": "https://opencollective.com/vitest" } }, + "node_modules/@vitest/runner": { + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/@vitest/runner/-/runner-3.0.5.tgz", + "integrity": "sha512-BAiZFityFexZQi2yN4OX3OkJC6scwRo8EhRB0Z5HIGGgd2q+Nq29LgHU/+ovCtd0fOfXj5ZI6pwdlUmC5bpi8A==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vitest/utils": "3.0.5", + "pathe": "^2.0.2" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/runner/node_modules/@vitest/pretty-format": { + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/@vitest/pretty-format/-/pretty-format-3.0.5.tgz", + "integrity": "sha512-CjUtdmpOcm4RVtB+up8r2vVDLR16Mgm/bYdkGFe3Yj/scRfCpbSi2W/BDSDcFK7ohw8UXvjMbOp9H4fByd/cOA==", + "dev": true, + "license": "MIT", + "dependencies": { + "tinyrainbow": "^2.0.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/runner/node_modules/@vitest/utils": { + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/@vitest/utils/-/utils-3.0.5.tgz", + "integrity": "sha512-N9AX0NUoUtVwKwy21JtwzaqR5L5R5A99GAbrHfCCXK1lp593i/3AZAXhSP43wRQuxYsflrdzEfXZFo1reR1Nkg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vitest/pretty-format": "3.0.5", + "loupe": "^3.1.2", + "tinyrainbow": "^2.0.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/runner/node_modules/tinyrainbow": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/tinyrainbow/-/tinyrainbow-2.0.0.tgz", + "integrity": "sha512-op4nsTR47R6p0vMUUoYl/a+ljLFVtlfaXkLQmqfLR1qHma1h/ysYk4hEXZ880bf2CYgTskvTa/e196Vd5dDQXw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/@vitest/snapshot": { + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/@vitest/snapshot/-/snapshot-3.0.5.tgz", + "integrity": "sha512-GJPZYcd7v8QNUJ7vRvLDmRwl+a1fGg4T/54lZXe+UOGy47F9yUfE18hRCtXL5aHN/AONu29NGzIXSVFh9K0feA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vitest/pretty-format": "3.0.5", + "magic-string": "^0.30.17", + "pathe": "^2.0.2" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/snapshot/node_modules/@vitest/pretty-format": { + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/@vitest/pretty-format/-/pretty-format-3.0.5.tgz", + "integrity": "sha512-CjUtdmpOcm4RVtB+up8r2vVDLR16Mgm/bYdkGFe3Yj/scRfCpbSi2W/BDSDcFK7ohw8UXvjMbOp9H4fByd/cOA==", + "dev": true, + "license": "MIT", + "dependencies": { + "tinyrainbow": "^2.0.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/snapshot/node_modules/tinyrainbow": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/tinyrainbow/-/tinyrainbow-2.0.0.tgz", + "integrity": "sha512-op4nsTR47R6p0vMUUoYl/a+ljLFVtlfaXkLQmqfLR1qHma1h/ysYk4hEXZ880bf2CYgTskvTa/e196Vd5dDQXw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=14.0.0" + } + }, "node_modules/@vitest/spy": { - "version": "2.1.8", - "resolved": "https://registry.npmjs.org/@vitest/spy/-/spy-2.1.8.tgz", - "integrity": "sha512-5swjf2q95gXeYPevtW0BLk6H8+bPlMb4Vw/9Em4hFxDcaOxS+e0LOX4yqNxoHzMR2akEB2xfpnWUzkZokmgWDg==", + "version": "2.1.9", + "resolved": "https://registry.npmjs.org/@vitest/spy/-/spy-2.1.9.tgz", + "integrity": "sha512-E1B35FwzXXTs9FHNK6bDszs7mtydNi5MIfUWpceJ8Xbfb1gBMscAnwLbEu+B44ed6W3XjL9/ehLPHR1fkf1KLQ==", "dev": true, "license": "MIT", "dependencies": { @@ -3097,13 +3206,13 @@ } }, "node_modules/@vitest/utils": { - "version": "2.1.8", - "resolved": "https://registry.npmjs.org/@vitest/utils/-/utils-2.1.8.tgz", - "integrity": "sha512-dwSoui6djdwbfFmIgbIjX2ZhIoG7Ex/+xpxyiEgIGzjliY8xGkcpITKTlp6B4MgtGkF2ilvm97cPM96XZaAgcA==", + "version": "2.1.9", + "resolved": "https://registry.npmjs.org/@vitest/utils/-/utils-2.1.9.tgz", + "integrity": "sha512-v0psaMSkNJ3A2NMrUEHFRzJtDPFn+/VWZ5WxImB21T9fjucJRmS7xCS3ppEnARb9y11OAzaD+P2Ps+b+BGX5iQ==", "dev": true, "license": "MIT", "dependencies": { - "@vitest/pretty-format": "2.1.8", + "@vitest/pretty-format": "2.1.9", "loupe": "^3.1.2", "tinyrainbow": "^1.2.0" }, @@ -3585,6 +3694,16 @@ "node": ">= 0.8" } }, + "node_modules/cac": { + "version": "6.7.14", + "resolved": "https://registry.npmjs.org/cac/-/cac-6.7.14.tgz", + "integrity": "sha512-b6Ilus+c3RrdDk+JhLKUAQfzzgLEPy6wcXqS7f/xe1EETvsDP6GORG7SFuOs6cID5YkqchW/LXZbX5bc8j7ZcQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, "node_modules/cache-content-type": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/cache-content-type/-/cache-content-type-1.0.1.tgz", @@ -3714,19 +3833,6 @@ "node": ">=12" } }, - "node_modules/chai-as-promised": { - "version": "8.0.1", - "resolved": "https://registry.npmjs.org/chai-as-promised/-/chai-as-promised-8.0.1.tgz", - "integrity": "sha512-OIEJtOL8xxJSH8JJWbIoRjybbzR52iFuDHuF8eb+nTPD6tgXLjRqsgnUGqQfFODxYvq5QdirT0pN9dZ0+Gz6rA==", - "dev": true, - "license": "MIT", - "dependencies": { - "check-error": "^2.0.0" - }, - "peerDependencies": { - "chai": ">= 2.1.2 < 6" - } - }, "node_modules/chalk": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", @@ -4745,6 +4851,13 @@ "node": ">= 0.4" } }, + "node_modules/es-module-lexer": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-1.6.0.tgz", + "integrity": "sha512-qqnD1yMU6tk/jnaMosogGySTZP8YtUgAffA9nMN+E/rjxcfRQ6IEk7IiozUjgxKoFHBGjTLnrHB/YC45r/59EQ==", + "dev": true, + "license": "MIT" + }, "node_modules/esbuild": { "version": "0.23.1", "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.23.1.tgz", @@ -4906,6 +5019,16 @@ "node": ">=4" } }, + "node_modules/expect-type": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/expect-type/-/expect-type-1.1.0.tgz", + "integrity": "sha512-bFi65yM+xZgk+u/KRIpekdSYkTB5W1pEf0Lt8Q8Msh7b+eQ7LXVtIB1Bkm4fvclDEL1b2CZkMhv2mOeF8tMdkA==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=12.0.0" + } + }, "node_modules/express": { "version": "4.21.1", "resolved": "https://registry.npmjs.org/express/-/express-4.21.1.tgz", @@ -7646,6 +7769,13 @@ "node": ">=8" } }, + "node_modules/pathe": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/pathe/-/pathe-2.0.3.tgz", + "integrity": "sha512-WUjGcAqP1gQacoQe+OBJsFA7Ld4DyXuUIjZ5cc75cLHvJ7dtNsTugphxIADwspS+AraAUePCKrSVtPLFj/F88w==", + "dev": true, + "license": "MIT" + }, "node_modules/pathval": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/pathval/-/pathval-2.0.0.tgz", @@ -9255,6 +9385,13 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/siginfo": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/siginfo/-/siginfo-2.0.0.tgz", + "integrity": "sha512-ybx0WO1/8bSBLEWXZvEd7gMW3Sn3JFlW3TvX1nREbDLRNQNaeNN8WK0meBwPdAaOI7TtRRRJn/Es1zhrrCHu7g==", + "dev": true, + "license": "ISC" + }, "node_modules/signal-exit": { "version": "3.0.7", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", @@ -9369,6 +9506,13 @@ "node": ">=0.10.0" } }, + "node_modules/stackback": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/stackback/-/stackback-0.0.2.tgz", + "integrity": "sha512-1XMJE5fQo1jGH6Y/7ebnwPOBEkIEnT4QF32d5R1+VXdXveM0IBMJt8zfaxX1P3QhVwrYe+576+jkANtSS2mBbw==", + "dev": true, + "license": "MIT" + }, "node_modules/standard-as-callback": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/standard-as-callback/-/standard-as-callback-2.1.0.tgz", @@ -9382,6 +9526,13 @@ "node": ">= 0.6" } }, + "node_modules/std-env": { + "version": "3.8.0", + "resolved": "https://registry.npmjs.org/std-env/-/std-env-3.8.0.tgz", + "integrity": "sha512-Bc3YwwCB+OzldMxOXJIIvC6cPRWr/LxOp48CdQTOkPyk/t4JWWJbrilwBd7RJzKV8QW7tJkcgAmeuLLJugl5/w==", + "dev": true, + "license": "MIT" + }, "node_modules/stream-transform": { "version": "3.3.2", "resolved": "https://registry.npmjs.org/stream-transform/-/stream-transform-3.3.2.tgz", @@ -9527,6 +9678,30 @@ "integrity": "sha512-w89qg7PI8wAdvX60bMDP+bFoD5Dvhm9oLheFp5O4a2QF0cSBGsBX4qZmadPMvVqlLJBBci+WqGGOAPvcDeNSVg==", "dev": true }, + "node_modules/tinybench": { + "version": "2.9.0", + "resolved": "https://registry.npmjs.org/tinybench/-/tinybench-2.9.0.tgz", + "integrity": "sha512-0+DUvqWMValLmha6lr4kD8iAMK1HzV0/aKnCtWb9v9641TnP/MFb7Pc2bxoxQjTXAErryXVgUOfv2YqNllqGeg==", + "dev": true, + "license": "MIT" + }, + "node_modules/tinyexec": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/tinyexec/-/tinyexec-0.3.2.tgz", + "integrity": "sha512-KQQR9yN7R5+OSwaK0XQoj22pwHoTlgYqmUscPYoknOoWCWfj/5/ABTMRi69FrKU5ffPVh5QcFikpWJI/P1ocHA==", + "dev": true, + "license": "MIT" + }, + "node_modules/tinypool": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/tinypool/-/tinypool-1.0.2.tgz", + "integrity": "sha512-al6n+QEANGFOMf/dmUMsuS5/r9B06uwlyNjZZql/zv8J7ybHCgoihBNORZCY2mzUuAnomQa2JdhyHKzZxPCrFA==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^18.0.0 || >=20.0.0" + } + }, "node_modules/tinyrainbow": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/tinyrainbow/-/tinyrainbow-1.2.0.tgz", @@ -9910,6 +10085,54 @@ } } }, + "node_modules/vite-node": { + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/vite-node/-/vite-node-3.0.5.tgz", + "integrity": "sha512-02JEJl7SbtwSDJdYS537nU6l+ktdvcREfLksk/NDAqtdKWGqHl+joXzEubHROmS3E6pip+Xgu2tFezMu75jH7A==", + "dev": true, + "license": "MIT", + "dependencies": { + "cac": "^6.7.14", + "debug": "^4.4.0", + "es-module-lexer": "^1.6.0", + "pathe": "^2.0.2", + "vite": "^5.0.0 || ^6.0.0" + }, + "bin": { + "vite-node": "vite-node.mjs" + }, + "engines": { + "node": "^18.0.0 || ^20.0.0 || >=22.0.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/vite-node/node_modules/debug": { + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.0.tgz", + "integrity": "sha512-6WTZ/IxCY/T6BALoZHaE4ctp9xm+Z5kY/pzYaCHRFeyVhojxlrm+46y68HA6hr0TcwEssoxNiDEUJQjfPZ/RYA==", + "dev": true, + "license": "MIT", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/vite-node/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "dev": true, + "license": "MIT" + }, "node_modules/vite/node_modules/@esbuild/aix-ppc64": { "version": "0.21.5", "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.21.5.tgz", @@ -10340,6 +10563,168 @@ "@esbuild/win32-x64": "0.21.5" } }, + "node_modules/vitest": { + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/vitest/-/vitest-3.0.5.tgz", + "integrity": "sha512-4dof+HvqONw9bvsYxtkfUp2uHsTN9bV2CZIi1pWgoFpL1Lld8LA1ka9q/ONSsoScAKG7NVGf2stJTI7XRkXb2Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vitest/expect": "3.0.5", + "@vitest/mocker": "3.0.5", + "@vitest/pretty-format": "^3.0.5", + "@vitest/runner": "3.0.5", + "@vitest/snapshot": "3.0.5", + "@vitest/spy": "3.0.5", + "@vitest/utils": "3.0.5", + "chai": "^5.1.2", + "debug": "^4.4.0", + "expect-type": "^1.1.0", + "magic-string": "^0.30.17", + "pathe": "^2.0.2", + "std-env": "^3.8.0", + "tinybench": "^2.9.0", + "tinyexec": "^0.3.2", + "tinypool": "^1.0.2", + "tinyrainbow": "^2.0.0", + "vite": "^5.0.0 || ^6.0.0", + "vite-node": "3.0.5", + "why-is-node-running": "^2.3.0" + }, + "bin": { + "vitest": "vitest.mjs" + }, + "engines": { + "node": "^18.0.0 || ^20.0.0 || >=22.0.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + }, + "peerDependencies": { + "@edge-runtime/vm": "*", + "@types/debug": "^4.1.12", + "@types/node": "^18.0.0 || ^20.0.0 || >=22.0.0", + "@vitest/browser": "3.0.5", + "@vitest/ui": "3.0.5", + "happy-dom": "*", + "jsdom": "*" + }, + "peerDependenciesMeta": { + "@edge-runtime/vm": { + "optional": true + }, + "@types/debug": { + "optional": true + }, + "@types/node": { + "optional": true + }, + "@vitest/browser": { + "optional": true + }, + "@vitest/ui": { + "optional": true + }, + "happy-dom": { + "optional": true + }, + "jsdom": { + "optional": true + } + } + }, + "node_modules/vitest/node_modules/@vitest/expect": { + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/@vitest/expect/-/expect-3.0.5.tgz", + "integrity": "sha512-nNIOqupgZ4v5jWuQx2DSlHLEs7Q4Oh/7AYwNyE+k0UQzG7tSmjPXShUikn1mpNGzYEN2jJbTvLejwShMitovBA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vitest/spy": "3.0.5", + "@vitest/utils": "3.0.5", + "chai": "^5.1.2", + "tinyrainbow": "^2.0.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/vitest/node_modules/@vitest/pretty-format": { + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/@vitest/pretty-format/-/pretty-format-3.0.5.tgz", + "integrity": "sha512-CjUtdmpOcm4RVtB+up8r2vVDLR16Mgm/bYdkGFe3Yj/scRfCpbSi2W/BDSDcFK7ohw8UXvjMbOp9H4fByd/cOA==", + "dev": true, + "license": "MIT", + "dependencies": { + "tinyrainbow": "^2.0.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/vitest/node_modules/@vitest/spy": { + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/@vitest/spy/-/spy-3.0.5.tgz", + "integrity": "sha512-5fOzHj0WbUNqPK6blI/8VzZdkBlQLnT25knX0r4dbZI9qoZDf3qAdjoMmDcLG5A83W6oUUFJgUd0EYBc2P5xqg==", + "dev": true, + "license": "MIT", + "dependencies": { + "tinyspy": "^3.0.2" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/vitest/node_modules/@vitest/utils": { + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/@vitest/utils/-/utils-3.0.5.tgz", + "integrity": "sha512-N9AX0NUoUtVwKwy21JtwzaqR5L5R5A99GAbrHfCCXK1lp593i/3AZAXhSP43wRQuxYsflrdzEfXZFo1reR1Nkg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vitest/pretty-format": "3.0.5", + "loupe": "^3.1.2", + "tinyrainbow": "^2.0.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/vitest/node_modules/debug": { + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.0.tgz", + "integrity": "sha512-6WTZ/IxCY/T6BALoZHaE4ctp9xm+Z5kY/pzYaCHRFeyVhojxlrm+46y68HA6hr0TcwEssoxNiDEUJQjfPZ/RYA==", + "dev": true, + "license": "MIT", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/vitest/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "dev": true, + "license": "MIT" + }, + "node_modules/vitest/node_modules/tinyrainbow": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/tinyrainbow/-/tinyrainbow-2.0.0.tgz", + "integrity": "sha512-op4nsTR47R6p0vMUUoYl/a+ljLFVtlfaXkLQmqfLR1qHma1h/ysYk4hEXZ880bf2CYgTskvTa/e196Vd5dDQXw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=14.0.0" + } + }, "node_modules/wait-on": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/wait-on/-/wait-on-7.2.0.tgz", @@ -10394,6 +10779,23 @@ "resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.1.tgz", "integrity": "sha512-iBdZ57RDvnOR9AGBhML2vFZf7h8vmBjhoaZqODJBFWHVtKkDmKuHai3cx5PgVMrX5YDNp27AofYbAwctSS+vhQ==" }, + "node_modules/why-is-node-running": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/why-is-node-running/-/why-is-node-running-2.3.0.tgz", + "integrity": "sha512-hUrmaWBdVDcxvYqnyh09zunKzROWjbZTiNy8dBEjkS7ehEDQibXJ7XvlmtbwuTclUiIyN+CyXQD4Vmko8fNm8w==", + "dev": true, + "license": "MIT", + "dependencies": { + "siginfo": "^2.0.0", + "stackback": "0.0.2" + }, + "bin": { + "why-is-node-running": "cli.js" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/workerpool": { "version": "6.5.1", "resolved": "https://registry.npmjs.org/workerpool/-/workerpool-6.5.1.tgz", @@ -10698,28 +11100,10 @@ "@types/mocha": "^10.0.10", "@types/node": "^22.10.2", "await-to-js": "^3.0.0", - "chai": "^5.1.2", - "mocha": "^11.0.1", "node-pg-migrate": "^7.6.1", "pg": "^8.13.0", - "tsx": "^4.19.2" - } - }, - "packages/identity-repository": { - "name": "@gouvfr-lasuite/proconnect.identity-repository", - "version": "0.2.0", - "extraneous": true, - "license": "MIT", - "devDependencies": { - "@electric-sql/pglite": "^0.2.15", - "@gouvfr-lasuite/proconnect.core": "^0.2.0", - "@tsconfig/node22": "^22.0.0", - "@types/mocha": "^10.0.10", - "@types/node": "^22.10.2", - "chai": "^5.1.2", - "mocha": "^11.0.1", - "pg": "^8.13.0", - "tsx": "^4.19.2" + "tsx": "^4.19.2", + "vitest": "^3.0.5" } }, "packages/insee": { diff --git a/package.json b/package.json index 7b6e507fe..f778dac44 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "test": "run-s test:*", "test:lint": "prettier '**/*.ts' --list-different", "test:type-check": "tsc --noEmit", - "test:unit": "NODE_ENV=test mocha --require tsx test/*.ts", + "test:unit": "NODE_ENV=test vitest --exclude=build --exclude=packages", "test:unit:watch": "npm run test:unit -- --watch --watch-files src/**/*.ts,test/**/*.ts", "test:workspaces": "npm run test --if-present --workspaces", "update-organization-info": "tsx scripts/update-organizations-info.ts", @@ -106,8 +106,6 @@ "@simplewebauthn/types": "^10.0.0", "@simplewebauthn/typescript-types": "^8.3.4", "@sinonjs/fake-timers": "^11.2.2", - "@types/chai": "^5.0.1", - "@types/chai-as-promised": "^7.1.8", "@types/console-log-level": "^1.4.5", "@types/cookie-parser": "^1.4.7", "@types/ejs": "^3.1.5", @@ -117,7 +115,6 @@ "@types/http-errors": "^2.0.4", "@types/lodash": "^4.17.10", "@types/lodash-es": "^4.17.12", - "@types/mocha": "^10.0.10", "@types/morgan": "^1.9.9", "@types/node": "^22.10.2", "@types/nodemailer": "^6.4.16", @@ -125,8 +122,6 @@ "@types/qrcode": "^1.5.5", "@types/sinonjs__fake-timers": "^8.1.5", "axe-core": "^4.8.4", - "chai": "^5.1.2", - "chai-as-promised": "^8.0.1", "concurrently": "^9.0.1", "copy-and-watch": "^0.1.6", "csv": "^6.3.9", @@ -134,7 +129,6 @@ "cypress-axe": "^1.6.0", "cypress-maildev": "^1.3.2", "lodash": "^4.17.21", - "mocha": "^11.0.1", "nock": "^13.5.6", "node-pg-migrate": "^7.6.1", "npm-run-all2": "^6.1.2", @@ -142,7 +136,8 @@ "prettier-plugin-organize-imports": "^4.1.0", "tld-extract": "^2.1.0", "typescript": "^5.7.2", - "vite": "^5.4.12" + "vite": "^5.4.12", + "vitest": "^3.0.5" }, "packageManager": "npm@11.1.0+sha512.acf301ad9b9ddba948fcb72341e2f0fcae477f56a95cc2a092934d133a7461062633cefbf93d5934a3dc0768674e2edee9f04dcfcc4bb4c327ff0e3a7d552a1b", "engines": { diff --git a/packages/identite/package.json b/packages/identite/package.json index 6576124dd..3c78bfb4d 100644 --- a/packages/identite/package.json +++ b/packages/identite/package.json @@ -37,14 +37,7 @@ "check": "npm run build -- --noEmit", "clean": "rm -rf dist tsconfig*.tsbuildinfo", "dev": "npm run build -- --watch --preserveWatchOutput", - "test": "mocha" - }, - "mocha": { - "reporter": "spec", - "require": [ - "tsx" - ], - "spec": "src/**/*.test.ts" + "test": "vitest --moduleResolution node" }, "dependencies": { "sql-template-tag": "^5.2.1" @@ -57,11 +50,10 @@ "@types/mocha": "^10.0.10", "@types/node": "^22.10.2", "await-to-js": "^3.0.0", - "chai": "^5.1.2", - "mocha": "^11.0.1", "node-pg-migrate": "^7.6.1", "pg": "^8.13.0", - "tsx": "^4.19.2" + "tsx": "^4.19.2", + "vitest": "^3.0.5" }, "publishConfig": { "access": "public", diff --git a/packages/identite/src/repositories/email-domain/add-domain.test.ts b/packages/identite/src/repositories/email-domain/add-domain.test.ts index c8c451ec1..14427ee29 100644 --- a/packages/identite/src/repositories/email-domain/add-domain.test.ts +++ b/packages/identite/src/repositories/email-domain/add-domain.test.ts @@ -2,7 +2,7 @@ import { emptyDatabase, migrate, pg } from "#testing"; import { expect } from "chai"; -import { before, describe, it } from "mocha"; +import { describe, it } from "mocha"; import { addDomainFactory } from "./add-domain.js"; // @@ -10,7 +10,7 @@ import { addDomainFactory } from "./add-domain.js"; const addDomain = addDomainFactory({ pg: pg as any }); describe(addDomainFactory.name, () => { - before(migrate); + beforeAll(migrate); beforeEach(emptyDatabase); it("should add domain", async () => { diff --git a/packages/identite/src/repositories/email-domain/find-email-domains-by-organization-id.test.ts b/packages/identite/src/repositories/email-domain/find-email-domains-by-organization-id.test.ts index e6153fc15..60db3a7c9 100644 --- a/packages/identite/src/repositories/email-domain/find-email-domains-by-organization-id.test.ts +++ b/packages/identite/src/repositories/email-domain/find-email-domains-by-organization-id.test.ts @@ -2,7 +2,7 @@ import { emptyDatabase, migrate, pg } from "#testing"; import { expect } from "chai"; -import { before, describe, it } from "mocha"; +import { describe, it } from "mocha"; import { findEmailDomainsByOrganizationIdFactory } from "./find-email-domains-by-organization-id.js"; // @@ -11,7 +11,7 @@ const findEmailDomainsByOrganizationId = findEmailDomainsByOrganizationIdFactory({ pg: pg as any }); describe(findEmailDomainsByOrganizationIdFactory.name, () => { - before(migrate); + beforeAll(migrate); beforeEach(emptyDatabase); it("should find email domains by organization id", async () => { diff --git a/packages/identite/src/repositories/organization/find-by-id.test.ts b/packages/identite/src/repositories/organization/find-by-id.test.ts index 98392fb8f..58643cfe4 100644 --- a/packages/identite/src/repositories/organization/find-by-id.test.ts +++ b/packages/identite/src/repositories/organization/find-by-id.test.ts @@ -2,7 +2,7 @@ import { emptyDatabase, migrate, pg } from "#testing"; import { expect } from "chai"; -import { before, describe, it } from "mocha"; +import { describe, it } from "mocha"; import { findByIdFactory } from "./find-by-id.js"; // @@ -10,7 +10,7 @@ import { findByIdFactory } from "./find-by-id.js"; const findById = findByIdFactory({ pg: pg as any }); describe(findByIdFactory.name, () => { - before(migrate); + beforeAll(migrate); beforeEach(emptyDatabase); it("should find the Necron organization", async () => { diff --git a/packages/identite/src/repositories/organization/get-users-by-organization.test.ts b/packages/identite/src/repositories/organization/get-users-by-organization.test.ts index 39904ac59..1caedc8dd 100644 --- a/packages/identite/src/repositories/organization/get-users-by-organization.test.ts +++ b/packages/identite/src/repositories/organization/get-users-by-organization.test.ts @@ -2,7 +2,7 @@ import { emptyDatabase, migrate, pg } from "#testing"; import { expect } from "chai"; -import { before, describe, it } from "mocha"; +import { describe, it } from "mocha"; import { getUsersByOrganizationFactory } from "./get-users-by-organization.js"; // @@ -10,7 +10,7 @@ import { getUsersByOrganizationFactory } from "./get-users-by-organization.js"; const getUsersByOrganization = getUsersByOrganizationFactory({ pg: pg as any }); describe(getUsersByOrganizationFactory.name, () => { - before(migrate); + beforeAll(migrate); beforeEach(emptyDatabase); it("should find users by organization id", async () => { diff --git a/packages/identite/src/repositories/organization/upset.test.ts b/packages/identite/src/repositories/organization/upset.test.ts index 5c2a4cdff..35224baa0 100644 --- a/packages/identite/src/repositories/organization/upset.test.ts +++ b/packages/identite/src/repositories/organization/upset.test.ts @@ -2,7 +2,7 @@ import { emptyDatabase, migrate, pg } from "#testing"; import { expect } from "chai"; -import { before, describe, it } from "mocha"; +import { describe, it } from "mocha"; import { upsertFactory } from "./upsert.js"; // @@ -10,7 +10,7 @@ import { upsertFactory } from "./upsert.js"; const upset = upsertFactory({ pg: pg as any }); describe("upset", () => { - before(migrate); + beforeAll(migrate); beforeEach(emptyDatabase); it("should create the Tau Empire organization", async () => { diff --git a/packages/identite/src/repositories/user/create.test.ts b/packages/identite/src/repositories/user/create.test.ts index 2ecd06008..b1ae06685 100644 --- a/packages/identite/src/repositories/user/create.test.ts +++ b/packages/identite/src/repositories/user/create.test.ts @@ -1,20 +1,17 @@ // import { emptyDatabase, migrate, pg } from "#testing"; -import { expect } from "chai"; -import { before, describe, it } from "mocha"; +import { beforeAll, beforeEach, expect, test } from "vitest"; import { createUserFactory } from "./create.js"; // const createUser = createUserFactory({ pg: pg as any }); -describe(createUserFactory.name, () => { - before(migrate); - beforeEach(emptyDatabase); +beforeAll(migrate); +beforeEach(emptyDatabase); - it("should create the god-emperor of mankind", async () => { - const user = await createUser({ email: "god-emperor@mankind" }); - expect(user.email).to.equal("god-emperor@mankind"); - }); +test("should create the god-emperor of mankind", async () => { + const user = await createUser({ email: "god-emperor@mankind" }); + expect(user.email).toBe("god-emperor@mankind"); }); diff --git a/packages/identite/src/repositories/user/find-by-email.test.ts b/packages/identite/src/repositories/user/find-by-email.test.ts index 62caa8fac..f910b2cdf 100644 --- a/packages/identite/src/repositories/user/find-by-email.test.ts +++ b/packages/identite/src/repositories/user/find-by-email.test.ts @@ -1,36 +1,33 @@ // import { emptyDatabase, migrate, pg } from "#testing"; -import { expect } from "chai"; -import { before, describe, it } from "mocha"; +import { beforeAll, beforeEach, expect, test } from "vitest"; import { findByEmailFactory } from "./find-by-email.js"; // const findByEmail = findByEmailFactory({ pg: pg as any }); -describe(findByEmailFactory.name, () => { - before(migrate); - beforeEach(emptyDatabase); +beforeAll(migrate); +beforeEach(emptyDatabase); - it("should find a user by email", async () => { - await pg.sql` - INSERT INTO users - (id, email, created_at, updated_at, given_name, family_name, phone_number, job) - VALUES - (1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'i', 'primarque'), - (2, 'perturabo@ironwarriors.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'iv', 'primarque') - ; - `; +test("should find a user by email", async () => { + await pg.sql` + INSERT INTO users + (id, email, created_at, updated_at, given_name, family_name, phone_number, job) + VALUES + (1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'i', 'primarque'), + (2, 'perturabo@ironwarriors.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'iv', 'primarque') + ; + `; - const user = await findByEmail("lion.eljonson@darkangels.world"); + const user = await findByEmail("lion.eljonson@darkangels.world"); - expect(user?.email).to.equal("lion.eljonson@darkangels.world"); - }); + expect(user?.email).toBe("lion.eljonson@darkangels.world"); +}); - it("❎ fail to find the God-Emperor of Mankind", async () => { - const user = await findByEmail("the God-Emperor of Mankind"); +test("❎ fail to find the God-Emperor of Mankind", async () => { + const user = await findByEmail("the God-Emperor of Mankind"); - expect(user).to.be.undefined; - }); + expect(user).toBeUndefined(); }); diff --git a/packages/identite/src/repositories/user/find-by-id.test.ts b/packages/identite/src/repositories/user/find-by-id.test.ts index f37cbb058..ae1d3ca5d 100644 --- a/packages/identite/src/repositories/user/find-by-id.test.ts +++ b/packages/identite/src/repositories/user/find-by-id.test.ts @@ -1,36 +1,33 @@ // import { emptyDatabase, migrate, pg } from "#testing"; -import { expect } from "chai"; -import { before, describe, it } from "mocha"; +import { beforeAll, beforeEach, expect, test } from "vitest"; import { findByIdFactory } from "./find-by-id.js"; // const findById = findByIdFactory({ pg: pg as any }); -describe(findByIdFactory.name, () => { - before(migrate); - beforeEach(emptyDatabase); +beforeAll(migrate); +beforeEach(emptyDatabase); - it("should find a user by id", async () => { - await pg.sql` - INSERT INTO users - (id, email, created_at, updated_at, given_name, family_name, phone_number, job) - VALUES - (1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'i', 'primarque'), - (2, 'perturabo@ironwarriors.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'iv', 'primarque') - ; - `; +test("should find a user by id", async () => { + await pg.sql` + INSERT INTO users + (id, email, created_at, updated_at, given_name, family_name, phone_number, job) + VALUES + (1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'i', 'primarque'), + (2, 'perturabo@ironwarriors.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'iv', 'primarque') + ; + `; - const user = await findById(1); + const user = await findById(1); - expect(user?.email).to.equal("lion.eljonson@darkangels.world"); - }); + expect(user?.email).toEqual("lion.eljonson@darkangels.world"); +}); - it("❎ fail to find the God-Emperor of Mankind", async () => { - const user = await findById(42); +test("❎ fail to find the God-Emperor of Mankind", async () => { + const user = await findById(42); - expect(user).to.be.undefined; - }); + expect(user).toBeUndefined(); }); diff --git a/packages/identite/src/repositories/user/update-user-organization-link.test.ts b/packages/identite/src/repositories/user/update-user-organization-link.test.ts index 660899613..e42c56034 100644 --- a/packages/identite/src/repositories/user/update-user-organization-link.test.ts +++ b/packages/identite/src/repositories/user/update-user-organization-link.test.ts @@ -1,8 +1,7 @@ // import { emptyDatabase, migrate, pg } from "#testing"; -import { expect } from "chai"; -import { before, describe, it } from "mocha"; +import { beforeAll, beforeEach, expect, test } from "vitest"; import { updateUserOrganizationLinkFactory } from "./update-user-organization-link.js"; // @@ -11,36 +10,35 @@ const updateUserOrganizationLink = updateUserOrganizationLinkFactory({ pg: pg as any, }); -describe(updateUserOrganizationLink.name, () => { - before(migrate); - beforeEach(emptyDatabase); +beforeAll(migrate); +beforeEach(emptyDatabase); - it("should update the user organization link", async () => { - await pg.sql` - INSERT INTO organizations - (cached_libelle, cached_nom_complet, id, siret, created_at, updated_at) - VALUES - ('Necron', 'Necrontyr', 1, '⚰️', '1967-12-19', '1967-12-19') - ; - `; - await pg.sql` - INSERT INTO users - (id, email, created_at, updated_at, given_name, family_name, phone_number, job) - VALUES - (1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'Lion', 'El''Jonson', 'I', 'Primarque') - ; - `; - await pg.sql` - INSERT INTO users_organizations - (user_id, organization_id, created_at, updated_at, is_external, verification_type, needs_official_contact_email_verification, official_contact_email_verification_token, official_contact_email_verification_sent_at) - VALUES - (1, 1, '4444-04-04', '4444-04-04', false, 'no_verification_means_available', false, null, null) - ; - `; +test("should update the user organization link", async () => { + await pg.sql` + INSERT INTO organizations + (cached_libelle, cached_nom_complet, id, siret, created_at, updated_at) + VALUES + ('Necron', 'Necrontyr', 1, '⚰️', '1967-12-19', '1967-12-19') + ; + `; + await pg.sql` + INSERT INTO users + (id, email, created_at, updated_at, given_name, family_name, phone_number, job) + VALUES + (1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'Lion', 'El''Jonson', 'I', 'Primarque') + ; + `; + await pg.sql` + INSERT INTO users_organizations + (user_id, organization_id, created_at, updated_at, is_external, verification_type, needs_official_contact_email_verification, official_contact_email_verification_token, official_contact_email_verification_sent_at) + VALUES + (1, 1, '4444-04-04', '4444-04-04', false, 'no_verification_means_available', false, null, null) + ; + `; - const user = await updateUserOrganizationLink(1, 1, { - is_external: true, - }); - expect(user.is_external).to.equal(true); + const user = await updateUserOrganizationLink(1, 1, { + is_external: true, }); + + expect(user.is_external).toBeTruthy(); }); diff --git a/packages/identite/src/repositories/user/update.test.ts b/packages/identite/src/repositories/user/update.test.ts index 0a0da0ccc..ea9c835f1 100644 --- a/packages/identite/src/repositories/user/update.test.ts +++ b/packages/identite/src/repositories/user/update.test.ts @@ -1,26 +1,25 @@ // import { emptyDatabase, migrate, pg } from "#testing"; -import { expect } from "chai"; -import { before, describe, it } from "mocha"; +import { beforeAll, beforeEach, expect, test } from "vitest"; import { updateUserFactory } from "./update.js"; // const updateUser = updateUserFactory({ pg: pg as any }); -describe(updateUserFactory.name, () => { - before(migrate); - beforeEach(emptyDatabase); +beforeAll(migrate); +beforeEach(emptyDatabase); - it("should update the user job", async () => { - await pg.sql` - INSERT INTO users - (id, email, created_at, updated_at, given_name, family_name, phone_number, job) - VALUES - (1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'Lion', 'El''Jonson', 'I', 'Primarque'); - `; - const user = await updateUser(1, { job: "Chevalier de l'Ordre" }); - expect(user.job).to.equal("Chevalier de l'Ordre"); - }); +test("should update the user job", async () => { + await pg.sql` + INSERT INTO users + (id, email, created_at, updated_at, given_name, family_name, phone_number, job) + VALUES + (1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'Lion', 'El''Jonson', 'I', 'Primarque'); + `; + + const user = await updateUser(1, { job: "Chevalier de l'Ordre" }); + + expect(user).toMatchInlineSnapshot(); }); diff --git a/test/acr-checks.test.ts b/test/acr-checks.test.ts index 7055f1c66..4c173df06 100644 --- a/test/acr-checks.test.ts +++ b/test/acr-checks.test.ts @@ -1,4 +1,4 @@ -import { assert } from "chai"; +import { describe, expect, it } from "vitest"; import { certificationDirigeantRequested, isAcrSatisfied, @@ -14,13 +14,13 @@ describe("twoFactorsAuthRequested", () => { details: { random: "random" }, }; - assert.equal(twoFactorsAuthRequested(prompt), false); + expect(twoFactorsAuthRequested(prompt)).toBeFalsy(); }); it("should return false for prompt with no acr required", () => { const prompt = { name: "login", reasons: ["no_session"], details: {} }; - assert.equal(twoFactorsAuthRequested(prompt), false); + expect(twoFactorsAuthRequested(prompt)).toBeFalsy(); }); it("should return true for new session", () => { @@ -35,7 +35,7 @@ describe("twoFactorsAuthRequested", () => { }, }; - assert.equal(twoFactorsAuthRequested(prompt), true); + expect(twoFactorsAuthRequested(prompt)).toBeTruthy(); }); it("should return true for self asserted identity", () => { @@ -50,7 +50,7 @@ describe("twoFactorsAuthRequested", () => { }, }; - assert.equal(twoFactorsAuthRequested(prompt), true); + expect(twoFactorsAuthRequested(prompt)).toBeTruthy(); }); it("should return true for existing session", () => { @@ -68,7 +68,7 @@ describe("twoFactorsAuthRequested", () => { }, }; - assert.equal(twoFactorsAuthRequested(prompt), true); + expect(twoFactorsAuthRequested(prompt)).toBeTruthy(); }); it("should return false if non 2fa acr are requested", () => { @@ -86,7 +86,7 @@ describe("twoFactorsAuthRequested", () => { }, }; - assert.equal(twoFactorsAuthRequested(prompt), false); + expect(twoFactorsAuthRequested(prompt)).toBeFalsy(); }); it("should return false for unknown acr", () => { @@ -101,7 +101,7 @@ describe("twoFactorsAuthRequested", () => { }, }; - assert.equal(twoFactorsAuthRequested(prompt), false); + expect(twoFactorsAuthRequested(prompt)).toBeFalsy(); }); }); @@ -113,25 +113,23 @@ describe("isAcrSatisfied", () => { details: { random: "random" }, }; - assert.equal( + expect( isAcrSatisfied( prompt, "https://proconnect.gouv.fr/assurance/self-asserted", ), - true, - ); + ).toBeTruthy(); }); it("should return true for prompt with no acr required", () => { const prompt = { name: "login", reasons: ["no_session"], details: {} }; - assert.equal( + expect( isAcrSatisfied( prompt, "https://proconnect.gouv.fr/assurance/self-asserted", ), - true, - ); + ).toBeTruthy(); }); it("should return true for consistency checked identity", () => { @@ -146,13 +144,12 @@ describe("isAcrSatisfied", () => { }, }; - assert.equal( + expect( isAcrSatisfied( prompt, "https://proconnect.gouv.fr/assurance/consistency-checked", ), - true, - ); + ).toBeTruthy(); }); it("should return false for self-asserted identity", () => { const prompt = { @@ -166,13 +163,12 @@ describe("isAcrSatisfied", () => { }, }; - assert.equal( + expect( isAcrSatisfied( prompt, "https://proconnect.gouv.fr/assurance/self-asserted", ), - false, - ); + ).toBeFalsy(); }); }); @@ -184,13 +180,13 @@ describe("isThereAnyRequestedAcr", () => { details: { random: "random" }, }; - assert.equal(isThereAnyRequestedAcr(prompt), false); + expect(isThereAnyRequestedAcr(prompt)).toBeFalsy(); }); it("should return true for prompt with no acr required", () => { const prompt = { name: "login", reasons: ["no_session"], details: {} }; - assert.equal(isThereAnyRequestedAcr(prompt), false); + expect(isThereAnyRequestedAcr(prompt)).toBeFalsy(); }); it("should return false for legacy acr", () => { @@ -205,7 +201,7 @@ describe("isThereAnyRequestedAcr", () => { }, }; - assert.equal(isThereAnyRequestedAcr(prompt), false); + expect(isThereAnyRequestedAcr(prompt)).toBeFalsy(); }); it("should return true for non legacy acr", () => { @@ -223,7 +219,7 @@ describe("isThereAnyRequestedAcr", () => { }, }; - assert.equal(isThereAnyRequestedAcr(prompt), true); + expect(isThereAnyRequestedAcr(prompt)).toBeTruthy(); }); it("should return true for mfa requested identity", () => { @@ -241,7 +237,7 @@ describe("isThereAnyRequestedAcr", () => { }, }; - assert.equal(isThereAnyRequestedAcr(prompt), true); + expect(isThereAnyRequestedAcr(prompt)).toBeTruthy(); }); }); @@ -260,7 +256,7 @@ describe("certificationDirigeantRequested", () => { reasons: ["essential_acrs"], }; - assert.equal(certificationDirigeantRequested(prompt), true); + expect(certificationDirigeantRequested(prompt)).toBeTruthy(); }); it("should return false if non certification dirigeant acr are requested", () => { @@ -281,6 +277,6 @@ describe("certificationDirigeantRequested", () => { reasons: ["essential_acrs"], }; - assert.equal(certificationDirigeantRequested(prompt), false); + expect(certificationDirigeantRequested(prompt)).toBeFalsy(); }); }); diff --git a/test/api-annuaire-education-nationale.test.ts b/test/api-annuaire-education-nationale.test.ts index 201afe475..cde2478c6 100644 --- a/test/api-annuaire-education-nationale.test.ts +++ b/test/api-annuaire-education-nationale.test.ts @@ -1,5 +1,5 @@ -import { assert } from "chai"; import nock from "nock"; +import { describe, expect, it } from "vitest"; import { ApiAnnuaireNotFoundError } from "../src/config/errors"; import { getAnnuaireEducationNationaleContactEmail } from "../src/connectors/api-annuaire-education-nationale"; import noResult from "./api-annuaire-education-nationale-data/no-result.json"; @@ -12,10 +12,9 @@ describe("getAnnuaireEducationNationaleContactEmail", () => { "/api/v2/catalog/datasets/fr-en-annuaire-education/records?where=siren_siret%3D77672253000024", ) .reply(200, noResult); - await assert.isRejected( + await expect( getAnnuaireEducationNationaleContactEmail("77672253000024"), - ApiAnnuaireNotFoundError, - ); + ).rejects.toThrow(ApiAnnuaireNotFoundError); }); it("should return valid email for a college and a lycee sharing the same SIRET", async () => { nock("https://data.education.gouv.fr") @@ -23,9 +22,8 @@ describe("getAnnuaireEducationNationaleContactEmail", () => { "/api/v2/catalog/datasets/fr-en-annuaire-education/records?where=siren_siret%3D77672253000040", ) .reply(200, twoEtablissementsData); - await assert.eventually.equal( + await expect( getAnnuaireEducationNationaleContactEmail("77672253000040"), - "jeannedarc.millau@gmail.com", - ); + ).resolves.toBe("jeannedarc.millau@gmail.com"); }); }); diff --git a/test/api-annuaire-service-public.test.ts b/test/api-annuaire-service-public.test.ts index c435b1fd8..784ab9bf9 100644 --- a/test/api-annuaire-service-public.test.ts +++ b/test/api-annuaire-service-public.test.ts @@ -1,5 +1,5 @@ -import { assert } from "chai"; import nock from "nock"; +import { describe, expect, it } from "vitest"; import { ApiAnnuaireNotFoundError } from "../src/config/errors"; import { getAnnuaireServicePublicContactEmail } from "../src/connectors/api-annuaire-service-public"; import invalidCogData from "./api-annuaire-service-public-data/invalid-cog.json"; @@ -13,10 +13,9 @@ describe("getAnnuaireServicePublicContactEmail", () => { `/api/explore/v2.1/catalog/datasets/api-lannuaire-administration/records?where=code_insee_commune LIKE "00000" and pivot LIKE "mairie"`, ) .reply(200, invalidCogData); - await assert.isRejected( + await expect( getAnnuaireServicePublicContactEmail("00000", "00000"), - ApiAnnuaireNotFoundError, - ); + ).rejects.toThrow(ApiAnnuaireNotFoundError); }); it("should return a valid email", async () => { nock("https://api-lannuaire.service-public.fr") @@ -24,10 +23,9 @@ describe("getAnnuaireServicePublicContactEmail", () => { `/api/explore/v2.1/catalog/datasets/api-lannuaire-administration/records?where=code_insee_commune LIKE "15014" and pivot LIKE "mairie"`, ) .reply(200, oneMairieData); - await assert.eventually.equal( + await expect( getAnnuaireServicePublicContactEmail("15014", "15000"), - "administration@aurillac.fr", - ); + ).resolves.toBe("administration@aurillac.fr"); }); it("should return valid email for two mairies with the same Code Officiel Geographique", async () => { nock("https://api-lannuaire.service-public.fr") @@ -35,9 +33,8 @@ describe("getAnnuaireServicePublicContactEmail", () => { `/api/explore/v2.1/catalog/datasets/api-lannuaire-administration/records?where=code_insee_commune LIKE "38253" and pivot LIKE "mairie"`, ) .reply(200, twoMairiesData); - await assert.eventually.equal( + await expect( getAnnuaireServicePublicContactEmail("38253", "38860"), - "accueil@mairie2alpes.fr", - ); + ).resolves.toBe("accueil@mairie2alpes.fr"); }); }); diff --git a/test/base64.test.ts b/test/base64.test.ts index ee852ee30..f0dad7622 100644 --- a/test/base64.test.ts +++ b/test/base64.test.ts @@ -1,23 +1,23 @@ -import { expect } from "chai"; +import { describe, expect, it } from "vitest"; import { decodeBase64URL, encodeBase64URL } from "../src/services/base64"; // Replace with the actual path of your module describe("Base64URL Encoding and Decoding", () => { it("should encode a Uint8Array to a base64 URL string", () => { const input = new Uint8Array([72, 101, 108, 108, 111]); // "Hello" in ASCII const encoded = encodeBase64URL(input); - expect(encoded).to.equal("SGVsbG8"); + expect(encoded).toEqual("SGVsbG8"); }); it("should decode a base64 URL string to a Uint8Array", () => { const input = "SGVsbG8"; // Base64 URL for "Hello" const decoded = decodeBase64URL(input); - expect(decoded).to.eql(new Uint8Array([72, 101, 108, 108, 111])); // "Hello" in ASCII + expect(decoded).toEqual(new Uint8Array([72, 101, 108, 108, 111])); // "Hello" in ASCII }); it("should encode and then decode to the original Uint8Array", () => { const original = new Uint8Array([1, 2, 3, 4, 5]); const encoded = encodeBase64URL(original); const decoded = decodeBase64URL(encoded); - expect(decoded).to.eql(original); + expect(decoded).toEqual(original); }); }); diff --git a/test/email.test.ts b/test/email.test.ts index 49abcfd3e..56cf66597 100644 --- a/test/email.test.ts +++ b/test/email.test.ts @@ -1,4 +1,4 @@ -import { assert } from "chai"; +import { describe, expect, it } from "vitest"; import { usesAFreeEmailProvider } from "../src/services/email"; describe("usesAFreeEmailProvider", () => { @@ -11,7 +11,7 @@ describe("usesAFreeEmailProvider", () => { emailAddressesThatUsesFreeEmailProviders.forEach((email) => { it("should return true for free email provider address", () => { - assert.equal(usesAFreeEmailProvider(email), true); + expect(usesAFreeEmailProvider(email)).toBeTruthy(); }); }); @@ -23,7 +23,7 @@ describe("usesAFreeEmailProvider", () => { professionalEmailAddresses.forEach((professionalEmailAddress) => { it("should return false for non free provider email address", () => { - assert.equal(usesAFreeEmailProvider(professionalEmailAddress), false); + expect(usesAFreeEmailProvider(professionalEmailAddress)).toBeFalsy(); }); }); }); diff --git a/test/env.zod.test.ts b/test/env.zod.test.ts index ec4a49b47..c943267a1 100644 --- a/test/env.zod.test.ts +++ b/test/env.zod.test.ts @@ -1,8 +1,6 @@ // -import { expect } from "chai"; -import { test } from "mocha"; -import { defaultJWKS } from "../src/config/default-jwks"; +import { expect, test } from "vitest"; import { envSchema } from "../src/config/env.zod"; // @@ -17,69 +15,124 @@ test("default sample env with configured INSEE secrets", () => { const env = envSchema.parse(sample_env); - expect(env).to.deep.equal({ - ACR_VALUE_FOR_IAL1_AAL1: - "https://proconnect.gouv.fr/assurance/self-asserted", - ACR_VALUE_FOR_IAL1_AAL2: - "https://proconnect.gouv.fr/assurance/self-asserted-2fa", - ACR_VALUE_FOR_IAL2_AAL1: - "https://proconnect.gouv.fr/assurance/consistency-checked", - ACR_VALUE_FOR_IAL2_AAL2: - "https://proconnect.gouv.fr/assurance/consistency-checked-2fa", - ACR_VALUE_FOR_CERTIFICATION_DIRIGEANT: - "https://proconnect.gouv.fr/assurance/certification-dirigeant", - API_AUTH_PASSWORD: "admin", - API_AUTH_USERNAME: "admin", - CRISP_BASE_URL: "https://api.crisp.chat", - CRISP_IDENTIFIER: "", - CRISP_KEY: "", - CRISP_MODERATION_TAG: ["identite", "moderation"], - CRISP_PLUGIN_URN: "", - CRISP_RESOLVE_DELAY: 1000, - CRISP_USER_NICKNAME: "ProConnect", - CRISP_WEBSITE_ID: "", - DATABASE_URL: - "postgres://moncomptepro:moncomptepro@127.0.0.1:5432/moncomptepro", - DEBOUNCE_API_KEY: "", - DEPLOY_ENV: "localhost", - DIRTY_DS_REDIRECTION_URL: - "https://www.demarches-simplifiees.fr/agent_connect/logout_from_mcp", - EMAIL_DELIVERABILITY_WHITELIST: [], - FEATURE_ALWAYS_RETURN_EIDAS1_FOR_ACR: false, - FEATURE_AUTHENTICATE_BROWSER: false, - FEATURE_CHECK_EMAIL_DELIVERABILITY: false, - FEATURE_CONSIDER_ALL_EMAIL_DOMAINS_AS_FREE: false, - FEATURE_CONSIDER_ALL_EMAIL_DOMAINS_AS_NON_FREE: true, - FEATURE_DISPLAY_TEST_ENV_WARNING: false, - FEATURE_BYPASS_MODERATION: false, - FEATURE_RATE_LIMIT: false, - FEATURE_SEND_MAIL: false, - FEATURE_USE_ANNUAIRE_EMAILS: false, - FEATURE_USE_SECURE_COOKIES: false, - FEATURE_USE_SECURITY_RESPONSE_HEADERS: false, - HTTP_CLIENT_TIMEOUT: 55000, - INSEE_CONSUMER_KEY: "fakesecret", - INSEE_CONSUMER_SECRET: "fakesecret", - JWKS: defaultJWKS, - LOG_LEVEL: "info", - MAGIC_LINK_TOKEN_EXPIRATION_DURATION_IN_MINUTES: 60, - MAX_DURATION_BETWEEN_TWO_EMAIL_ADDRESS_VERIFICATION_IN_MINUTES: 129600, - MAX_SUGGESTED_ORGANIZATIONS: 3, - MIN_DURATION_BETWEEN_TWO_VERIFICATION_CODE_SENDING_IN_SECONDS: 1200, - HOST: "http://localhost:3000", - APPLICATION_NAME: "ProConnect", - NODE_ENV: "development", - PORT: 3000, - RECENT_LOGIN_INTERVAL_IN_SECONDS: 900, - REDIS_URL: "redis://:@127.0.0.1:6379", - RESET_PASSWORD_TOKEN_EXPIRATION_DURATION_IN_MINUTES: 60, - SENTRY_DSN: "", - SESSION_COOKIE_SECRET: ["proconnectsecret"], - SESSION_MAX_AGE_IN_SECONDS: 86400, - SMTP_URL: "smtp://localhost:1025", - SYMMETRIC_ENCRYPTION_KEY: "aTrueRandom32BytesLongBase64EncodedStringAA=", - TEST_CONTACT_EMAIL: "mairie@yopmail.com", - TRUSTED_BROWSER_COOKIE_MAX_AGE_IN_SECONDS: 7776000, - VERIFY_EMAIL_TOKEN_EXPIRATION_DURATION_IN_MINUTES: 60, - }); + expect(env).toMatchInlineSnapshot(` + { + "ACR_VALUE_FOR_CERTIFICATION_DIRIGEANT": "https://proconnect.gouv.fr/assurance/certification-dirigeant", + "ACR_VALUE_FOR_IAL1_AAL1": "https://proconnect.gouv.fr/assurance/self-asserted", + "ACR_VALUE_FOR_IAL1_AAL2": "https://proconnect.gouv.fr/assurance/self-asserted-2fa", + "ACR_VALUE_FOR_IAL2_AAL1": "https://proconnect.gouv.fr/assurance/consistency-checked", + "ACR_VALUE_FOR_IAL2_AAL2": "https://proconnect.gouv.fr/assurance/consistency-checked-2fa", + "API_AUTH_PASSWORD": "admin", + "API_AUTH_USERNAME": "admin", + "APPLICATION_NAME": "ProConnect", + "CRISP_BASE_URL": "https://api.crisp.chat", + "CRISP_IDENTIFIER": "", + "CRISP_KEY": "", + "CRISP_MODERATION_TAG": [ + "identite", + "moderation", + ], + "CRISP_PLUGIN_URN": "", + "CRISP_RESOLVE_DELAY": 1000, + "CRISP_USER_NICKNAME": "ProConnect", + "CRISP_WEBSITE_ID": "", + "DATABASE_URL": "postgres://moncomptepro:moncomptepro@127.0.0.1:5432/moncomptepro", + "DEBOUNCE_API_KEY": "", + "DEPLOY_ENV": "localhost", + "DIRTY_DS_REDIRECTION_URL": "https://www.demarches-simplifiees.fr/agent_connect/logout_from_mcp", + "EMAIL_DELIVERABILITY_WHITELIST": [], + "FEATURE_ALWAYS_RETURN_EIDAS1_FOR_ACR": false, + "FEATURE_AUTHENTICATE_BROWSER": false, + "FEATURE_BYPASS_MODERATION": false, + "FEATURE_CHECK_EMAIL_DELIVERABILITY": false, + "FEATURE_CONSIDER_ALL_EMAIL_DOMAINS_AS_FREE": false, + "FEATURE_CONSIDER_ALL_EMAIL_DOMAINS_AS_NON_FREE": true, + "FEATURE_DISPLAY_TEST_ENV_WARNING": false, + "FEATURE_RATE_LIMIT": false, + "FEATURE_SEND_MAIL": false, + "FEATURE_USE_ANNUAIRE_EMAILS": false, + "FEATURE_USE_SECURE_COOKIES": false, + "FEATURE_USE_SECURITY_RESPONSE_HEADERS": false, + "HOST": "http://localhost:3000", + "HTTP_CLIENT_TIMEOUT": 55000, + "INSEE_CONSUMER_KEY": "fakesecret", + "INSEE_CONSUMER_SECRET": "fakesecret", + "JWKS": { + "keys": [ + { + "crv": "P-256", + "d": "taURynSwshCfxEWs6z2_Xz-ocheg-6ePaU87cjy572Y", + "kid": "GCirOyeBc0rlWhcbMnwe9FUadPk6ToJlOq3yvxvkKlE", + "kty": "EC", + "use": "enc", + "x": "UtmbpHb1aHibmvEQJ2KlIzNro4tGfyMiBIVmO92YX7Q", + "y": "YsRG_NMtLOqvA6S9zq5r7M9Y-Cgo4YwKvH3xXyvFE2E", + }, + { + "crv": "P-256", + "d": "TLeCkidQUJG9s6hvHx8QSHNKfqyhcbIXCN7rJ67AjH4", + "kid": "TeXJ6Hx4sG9A13LCFlU46-PYGopwwFOsmCTEJcwZvZ8", + "kty": "EC", + "use": "sig", + "x": "2SSoeci15SnMM6wwxvNwzp_xjVTwgEALOY1NvTBbdqs", + "y": "Gplus4XyX4dQ6Z0Pwb0UhsmJfx7S5_DCFxpK6yt396Q", + }, + { + "crv": "Ed25519", + "d": "WxFz4Ulx6rLBO5HHHhg86BMc_CtRoCmFn8Gwy-kbaL4", + "kid": "onHSTAw1rfQOz_qWnPTh2SZzrseoqbOOrD1tcxFOaIU", + "kty": "OKP", + "use": "sig", + "x": "NQNM3isoJAeK6HWKEgHifRqFrC-R6ufusnv47BnlWn4", + }, + { + "d": "qClmBFjTiJgj2cMXmtvtLSnuVtMr-sFqVzZiEYiXAv7yXT3B0CEqdXf0unvVH2x3JTuhcies2Zf_0gQdhglpPro8YRx1v3l6N2HE1nmTj6reakWSlXNOdMthQ6KOzZxTHUA3J53aW1U0-nhW2TrQAYaTHgNSr-yOWMBFGWrxxomc8h_1OnnXS9wRxoicPshjx7S8huy3YLbWzQphBqzBx5vsPOClfbs0dtxhAY63vXbNDS_sAIVfn1U__f6ilFmzE9odgOydsSwBUtRm2Ir4wY5HhqYGRPOKAUNHLqEsDqwmp_o3RtBQwg937ymbOJvgoa6qkqg_uxtaVSP7RX4EKQ", + "dp": "g0dYT3wQ4VRY8NFbwHci_2jBQzpOXgvLooEcMuJzP3TeITqoNQp8-qOuguiWs3caPAMk4g-wGH8zw5qhEStJtjBPzfw3MwKFAJ-tjgZvcUkhzaIUNmG9RZTUl3zcRurKYR7pdcETdfRT4nmHfkbgZV4uE0KZlP96ekoI7LUxqgk", + "dq": "1Gpl81t_KVDgTu2OIoySo2nNBpUjzc7feKnzgsjaItALyrSkXD4COSElPPzY-vGa0fwWd483CRcyQeoSPKyGuf7wNVJ9XBV4kObqfh46cSgLp33axo3erPVpxwYubxO5olq00FW6Lr5D4kSclTX1pJ29LtoZDV7v1xJ_11vxydU", + "e": "AQAB", + "kid": "kddKa_IDmU8a5RhJaIzwzpJcFe4qT-GtNFcG2AWclZ4", + "kty": "RSA", + "n": "5yuakCQKnkzP4tNXYI6qRYX-0pyeuGKS8VKl7S1QNj7bAMjeV2o3xjDgg4qtrUrFrqxSFOfBX5kJR3NEBoYiQpUwl9zPmKNLR0zX0w6VpwDREDS8bpBL_naeiGRdLX_AYxR7jCsDETEXqFm0S1CmfLjgAoazLPDxzGvFaezLEo0rafcLR3MpKIa-INqwCoTiLWUAtXKv-ZcmO7QuzRcVJecFs7WaMQZNMrfSAdj-agdnVOkP2cXnd6xpT2Pcph7I6z2slRkEZ_Oz1BkG-FV_21IlY1U4tE3GigKdSNRSJmuyvdgI4wDb2noZdEStFr8nsOsG63kIYM_Gve-HWiTxmQ", + "p": "-X7pv_NpfJvqTTlQwQnaz6eiA_I7v7Jj0l1KtmBRBZz6q6R9qq1BVlP8XeOBO5TX9vQKIooY8fL3QsWf73ZqQmmy9W3C4dAhwbwalvBzZHZT2Wznrurp_bML_8Xx1XhNxTawAb263O3AUz7Rw3g5lI2cafTe4x1dSO8_CHL3eMs", + "q": "7TJj6aNzkVjyPeCZVHwBXGDWDIT2DxqWRjKrKgqlpWdzEftNce855Wg3Ve4JnNtFkg7Qow4imZVkbK69ChIStv9s1KDX_sGRCyfN17d0jlkyGUnFB2RSBB42t7SmcC4ZhHjxdAdopOG_o1r5vEwDo-0hKWikP9uyYmWyhfY3hqs", + "qi": "4RyTKy-QINtOUezaLEymzNBIG3uZv_IKvGPhEYi4wRNP_XxIK9NwfgUFRAhxhpxSpEjco_eNuN3I6XBF7bXb4-Bnnye1mBm3sBTXx2_09r8zt9Uvg3cdh0pYem3hU1ANMRmr3rfjtain4DTskIJ2CxjvGIMyh3VXLyRyfzIGJig", + "use": "enc", + }, + { + "d": "L0a7DDdP9LsAjeu_C6fkh4GXMqtRo3yPHK077SVFTPGGAFGq8Lk3C-wWTQxTwO9eZ_xx9wCzFTyIyqrksTuvQxzfY0MmzEk3mXNSrKxpK_vbgtC47qV6UwuGGiRfJ1z7MGXGmu5OmpaZqZJ-CPTGVtsM0rF4V665dIe-15o9GHzLX80mhw8ySd0qqBIbdIWlK2zaSRPGL08mP02t_XnHdCCaWfRE_erO6zsEhR8ePvbmQqI7GRBull59seXefo1VDP30lEwHwH05Ju24_ZddhfuP2Y9jkZnNKqpSHF3EZzT6Vh3ggAaLjQzRWJvd1_0Zit7CD06o6L1aLV7nDnTYAQ", + "dp": "Cyf-4iwZZIrve5WsqKy8UVWpMBDCyBpCpHRNw2PAVGAP4aNXe2dG41sxV3mvdsOHWzqApsLT90EVHDa2KySS5CNcxOQ47Yr1mVVFoHb3izIcLe2dIpVUmgyc62WDcaShl47ahnWyDO8rLJzeH75AZlCaJR3s2nnth7Xy_cU4GQE", + "dq": "SvJe21HfQe2JsqGwrBPg0ShcfKMnkQI3uaaDOJDkEyHJz4eILlETfiFEBgNRo4xYjPU4Aa2w81poYms4RhYdNwpB4DT5OXT8kL_KRykmhBLWaxafezyIRxdNs97h7eU1Vk_05C3vbG7fqASO6vv7HdHnB_ityGRDUnLbwKfDasU", + "e": "AQAB", + "kid": "lFWqEBQbScnjO5OzUbvkPp0rmjGy17bmzZOqUbWkQMo", + "kty": "RSA", + "n": "6btLS-c06m18O5BlLvJA4HJNVI7WauBg5JVoy1cHTdfjTJ-oSts5uetXKF_NlNcLuq-zIKZuu9wea5m2E3lJ-vtCSAtRaJgZY41KAOjIsrHQstVuc9di4zjgcA6zwEXhqwu48gklGKpWNk7wnfMCO6mNoRs_-8-CnK6lTFeJFzfoCDmS6dYbefmPeFW4qziEZzEv5DPGAcUsXXZhbOku_E8gILRVMkBwHpvY_G3jngE1EWXctiM9tYqhgvxyJC9QyPCVpgfAvDlslMpuQTxBviC9PsrcBaQ5PyAP_xNN3X8LB-STpz7jNpNquKL5Ls0Hv9R3fDCeHvcYoVsgDirwfQ", + "p": "_u6v29kLICnGvbF44-sF5cFisrIPyXcj8laaNx6uP5ax9ZOPD_THdxTFU3YWLUErzi4MQJQPLoJacphQJKnG78b0PX_733--r-vpqUqfbzAlIssS8N4CFj6_YEMFR8W70laXJYJdx7IsnGOAlxAUZur5ugaaR0zDzlMTQVuR30E", + "q": "6rXguomnHNGFslAeHWPxPDaHxihx3eRJ-8t1KyvvwT43YfdPn2xxdq5-TyO0MMKznvDIHk9HDMBMr8JH32Q9qx75Ec81NOLGkBWqO9x-8dBlKn95jr8-qkD3iXHmJiHHNWNurHJM4G4lo73IL_0jgo0CCpcZWP7iH5y-b_mXPj0", + "qi": "QomRmnqrW3k8cV8MIefgmKZMGDGHRC44bFk9B20YR15_XHcMimi7o9rjUE7BY-RO30RsPUiQqB_vkpKvQZILOuPmIQhElcgmguKqPNwprVMgx-krUQ1Khuh3tgzxhBgazXzPcKmx8JBbCopP_UwNiCpPcdm74VFcZ-OswmqQU08", + "use": "sig", + }, + ], + }, + "LOG_LEVEL": "info", + "MAGIC_LINK_TOKEN_EXPIRATION_DURATION_IN_MINUTES": 60, + "MAX_DURATION_BETWEEN_TWO_EMAIL_ADDRESS_VERIFICATION_IN_MINUTES": 129600, + "MAX_SUGGESTED_ORGANIZATIONS": 3, + "MIN_DURATION_BETWEEN_TWO_VERIFICATION_CODE_SENDING_IN_SECONDS": 1200, + "NODE_ENV": "development", + "PORT": 3000, + "RECENT_LOGIN_INTERVAL_IN_SECONDS": 900, + "REDIS_URL": "redis://:@127.0.0.1:6379", + "RESET_PASSWORD_TOKEN_EXPIRATION_DURATION_IN_MINUTES": 60, + "SENTRY_DSN": "", + "SESSION_COOKIE_SECRET": [ + "proconnectsecret", + ], + "SESSION_MAX_AGE_IN_SECONDS": 86400, + "SMTP_URL": "smtp://localhost:1025", + "SYMMETRIC_ENCRYPTION_KEY": "aTrueRandom32BytesLongBase64EncodedStringAA=", + "TEST_CONTACT_EMAIL": "mairie@yopmail.com", + "TRUSTED_BROWSER_COOKIE_MAX_AGE_IN_SECONDS": 7776000, + "VERIFY_EMAIL_TOKEN_EXPIRATION_DURATION_IN_MINUTES": 60, + } + `); }); diff --git a/test/epoch-time.test.ts b/test/epoch-time.test.ts index 5de28f8e4..9f63e9320 100644 --- a/test/epoch-time.test.ts +++ b/test/epoch-time.test.ts @@ -1,25 +1,17 @@ -import FakeTimers, { type InstalledClock } from "@sinonjs/fake-timers"; -import { assert } from "chai"; +import { afterEach, describe, expect, it, vi } from "vitest"; import epochTime from "../src/services/epoch-time"; describe("epochTime", () => { - let clock: InstalledClock; - - beforeEach(() => { - clock = FakeTimers.install({ now: new Date("2023-12-01T00:00:00.000Z") }); - }); - - afterEach(() => { - clock.uninstall(); - }); + afterEach(vi.useRealTimers); it("should return current date in epoch format", () => { - assert.strictEqual(epochTime(), 1701388800); + vi.setSystemTime(new Date("2023-12-01T00:00:00.000Z")); + expect(epochTime()).toBe(1701388800); }); it("should return a date in epoch format", () => { const emittedDate = new Date("2023-12-01T00:01:00.000Z"); - assert.strictEqual(epochTime(emittedDate), 1701388860); + expect(epochTime(emittedDate)).toBe(1701388860); }); }); diff --git a/test/github-passkey-authenticator-aaguids.test.ts b/test/github-passkey-authenticator-aaguids.test.ts index 7a7342b5f..0de8c5d7e 100644 --- a/test/github-passkey-authenticator-aaguids.test.ts +++ b/test/github-passkey-authenticator-aaguids.test.ts @@ -1,11 +1,7 @@ -import * as chai from "chai"; -import chaiAsPromised from "chai-as-promised"; import nock from "nock"; +import { beforeEach, describe, expect, it } from "vitest"; import { getAuthenticatorFriendlyName } from "../src/connectors/github-passkey-authenticator-aaguids"; -chai.use(chaiAsPromised); -const assert = chai.assert; - describe("getOrganizationInfo", () => { beforeEach(() => { nock("https://raw.githubusercontent.com") @@ -32,15 +28,13 @@ describe("getOrganizationInfo", () => { }); it("should return friendly name", async () => { - await assert.eventually.equal( + await expect( getAuthenticatorFriendlyName("ea9b8d66-4d01-1d21-3ce4-b6b48cb575d4"), - "Google Password Manager", - ); + ).resolves.toBe("Google Password Manager"); }); it("should return null", async () => { - await assert.eventually.equal( - getAuthenticatorFriendlyName("unknown_aaguid"), + await expect(getAuthenticatorFriendlyName("unknown_aaguid")).resolves.toBe( null, ); }); @@ -48,9 +42,8 @@ describe("getOrganizationInfo", () => { it("should call github once", async () => { await getAuthenticatorFriendlyName("ea9b8d66-4d01-1d21-3ce4-b6b48cb575d4"); - await assert.eventually.equal( + await expect( getAuthenticatorFriendlyName("ea9b8d66-4d01-1d21-3ce4-b6b48cb575d4"), - "Google Password Manager", - ); + ).resolves.toBe("Google Password Manager"); }); }); diff --git a/test/hash-to-postgres-params.test.ts b/test/hash-to-postgres-params.test.ts index 99d670684..fc64e8e8e 100644 --- a/test/hash-to-postgres-params.test.ts +++ b/test/hash-to-postgres-params.test.ts @@ -1,10 +1,10 @@ -import { assert } from "chai"; +import { describe, expect, it } from "vitest"; import { hashToPostgresParams } from "../src/services/hash-to-postgres-params"; describe("hashToPostgresParams", () => { it("should return update params for user", () => { const hash = { email: "email@xy.z", encrypted_password: "hash" }; - assert.deepEqual(hashToPostgresParams(hash), { + expect(hashToPostgresParams(hash)).toEqual({ paramsString: "(email, encrypted_password)", valuesString: "($1, $2)", values: ["email@xy.z", "hash"], diff --git a/test/is-expired.test.ts b/test/is-expired.test.ts index 91af357a0..f60e7c0c0 100644 --- a/test/is-expired.test.ts +++ b/test/is-expired.test.ts @@ -1,39 +1,26 @@ -import FakeTimers, { type InstalledClock } from "@sinonjs/fake-timers"; -import { assert } from "chai"; +import { beforeEach, describe, expect, it, vi } from "vitest"; import { isExpired } from "../src/services/is-expired"; describe("isExpired", () => { - let clock: InstalledClock; - beforeEach(() => { - clock = FakeTimers.install({ now: new Date(2022, 11, 20) }); - }); - - afterEach(() => { - clock.uninstall(); + vi.setSystemTime(new Date(2022, 11, 20)); }); const expirationDurationInMinutes = 24 * 60; it("should return true when Date is undefined", () => { - assert.strictEqual(isExpired(null, expirationDurationInMinutes), true); + expect(isExpired(null, expirationDurationInMinutes)).toBeTruthy(); }); it("should return false when Date is about to expire", () => { const emittedDate = new Date(2022, 11, 19, 0, 1); - assert.strictEqual( - isExpired(emittedDate, expirationDurationInMinutes), - false, - ); + expect(isExpired(emittedDate, expirationDurationInMinutes)).toBeFalsy(); }); it("should return true when Date is expired", () => { const emittedDate = new Date(2022, 11, 18, 23, 59); - assert.strictEqual( - isExpired(emittedDate, expirationDurationInMinutes), - true, - ); + expect(isExpired(emittedDate, expirationDurationInMinutes)).toBeTruthy(); }); }); diff --git a/test/json-parse-with-date.test.ts b/test/json-parse-with-date.test.ts index 6c8891a73..5d32c7012 100644 --- a/test/json-parse-with-date.test.ts +++ b/test/json-parse-with-date.test.ts @@ -1,11 +1,11 @@ -import { assert } from "chai"; +import { describe, expect, it } from "vitest"; import { jsonParseWithDate } from "../src/services/json-parse-with-date"; describe("jsonParseWithDate", () => { it("should parse Date from json iso string", () => { const string = '{"a":"2023-12-01T00:00:00.000Z"}'; - assert.deepEqual(jsonParseWithDate(string), { + expect(jsonParseWithDate(string)).toEqual({ a: new Date("2023-12-01"), }); }); @@ -13,7 +13,7 @@ describe("jsonParseWithDate", () => { it("should not infer on other types", () => { const string = '{"a":"a", "b": 2, "c": null}'; - assert.deepEqual(jsonParseWithDate(string), { + expect(jsonParseWithDate(string)).toEqual({ a: "a", b: 2, c: null, diff --git a/test/must-return-one-organization-in-payload.test.ts b/test/must-return-one-organization-in-payload.test.ts index 05fee71b8..79681d55c 100644 --- a/test/must-return-one-organization-in-payload.test.ts +++ b/test/must-return-one-organization-in-payload.test.ts @@ -1,36 +1,32 @@ -import { assert } from "chai"; +import { describe, expect, it } from "vitest"; import { mustReturnOneOrganizationInPayload } from "../src/services/must-return-one-organization-in-payload"; describe("mustReturnOneOrganizationInPayload", () => { it("should return true if organization is amongst the scopes", () => { - assert.equal( + expect( mustReturnOneOrganizationInPayload("openid organization"), - true, - ); + ).toBeTruthy(); }); it("should return true even if organizationS id amongst the scopes", () => { - assert.equal( + expect( mustReturnOneOrganizationInPayload("openid organizations organization"), - true, - ); + ).toBeTruthy(); }); it("should return true for ProConnect Federation required scopes", () => { - assert.equal( + expect( mustReturnOneOrganizationInPayload( "openid uid given_name usual_name email siren siret organizational_unit belonging_population phone chorusdt idp_id idp_acr", ), - true, - ); + ).toBeTruthy(); }); it("should return false for DataPass required scopes", () => { - assert.equal( + expect( mustReturnOneOrganizationInPayload( "openid email profile phone organizations", ), - false, - ); + ).toBeFalsy(); }); }); diff --git a/test/normalize-official-contact-email-verification-token.test.ts b/test/normalize-official-contact-email-verification-token.test.ts index 8d96d717e..9101c5c50 100644 --- a/test/normalize-official-contact-email-verification-token.test.ts +++ b/test/normalize-official-contact-email-verification-token.test.ts @@ -1,19 +1,12 @@ -import { assert } from "chai"; +import { expect, test } from "vitest"; import { normalizeOfficialContactEmailVerificationToken } from "../src/services/normalize-official-contact-email-verification-token"; -describe("normalizeOfficialContactEmailVerificationToken", () => { - const rawTokens = [ - "crème brûlée façon grand-mère", - "Crème Brûlée fAçon Grand-Mère", - " crème brûlée façon grand-mère ", - ]; - - rawTokens.forEach((rawToken) => { - it("should return normalized token", () => { - assert.equal( - normalizeOfficialContactEmailVerificationToken(rawToken), - "creme-brulee-facon-grand-mere", - ); - }); - }); +test.each([ + "crème brûlée façon grand-mère", + "Crème Brûlée fAçon Grand-Mère", + " crème brûlée façon grand-mère ", +])("should return normalized token : %s", (rawToken) => { + expect(normalizeOfficialContactEmailVerificationToken(rawToken)).toBe( + "creme-brulee-facon-grand-mere", + ); }); diff --git a/test/organization.test.ts b/test/organization.test.ts index ecb9b8d66..c8a9861ac 100644 --- a/test/organization.test.ts +++ b/test/organization.test.ts @@ -1,5 +1,5 @@ import type { Organization } from "@gouvfr-lasuite/proconnect.identite/types"; -import { assert } from "chai"; +import { describe, expect, it } from "vitest"; import { isCommune, isEducationNationaleDomain, @@ -48,40 +48,39 @@ const entreprise_unipersonnelle_org_info = { describe("isEntrepriseUnipersonnelle", () => { it("should return false for bad call", () => { - assert.equal(isEntrepriseUnipersonnelle({} as Organization), false); + expect(isEntrepriseUnipersonnelle({} as Organization)).toBeFalsy(); }); it("should return true for unipersonnelle organization", () => { - assert.equal( + expect( isEntrepriseUnipersonnelle(entreprise_unipersonnelle_org_info), - true, - ); + ).toBeTruthy(); }); it("should return false for association", () => { - assert.equal(isEntrepriseUnipersonnelle(association_org_info), false); + expect(isEntrepriseUnipersonnelle(association_org_info)).toBeFalsy(); }); it("should return false for small association", () => { - assert.equal(isEntrepriseUnipersonnelle(small_association_org_info), false); + expect(isEntrepriseUnipersonnelle(small_association_org_info)).toBeFalsy(); }); }); describe("isSmallAssociation", () => { it("should return false for bad call", () => { - assert.equal(isSmallAssociation({} as Organization), false); + expect(isSmallAssociation({} as Organization)).toBeFalsy(); }); it("should return false for unipersonnelle organization", () => { - assert.equal(isSmallAssociation(entreprise_unipersonnelle_org_info), false); + expect(isSmallAssociation(entreprise_unipersonnelle_org_info)).toBeFalsy(); }); it("should return true for association", () => { - assert.equal(isSmallAssociation(association_org_info), true); + expect(isSmallAssociation(association_org_info)).toBeTruthy(); }); it("should return true for small association", () => { - assert.equal(isSmallAssociation(small_association_org_info), true); + expect(isSmallAssociation(small_association_org_info)).toBeTruthy(); }); }); @@ -135,15 +134,15 @@ const whitelisted_org_info = { describe("isCommune", () => { it("should return false for bad call", () => { - assert.equal(isCommune({} as Organization), false); + expect(isCommune({} as Organization)).toBeFalsy(); }); it("should return true for collectivite territoriale", () => { - assert.equal(isCommune(lamalou_org_info), true); + expect(isCommune(lamalou_org_info)).toBeTruthy(); }); it("should return false for administration centrale", () => { - assert.equal(isCommune(dinum_org_info), false); + expect(isCommune(dinum_org_info)).toBeFalsy(); }); }); @@ -162,48 +161,47 @@ const trackdechets_public_org_info = { describe("isPublicService", () => { it("should return false for bad call", () => { - assert.equal(isPublicService({} as Organization), false); + expect(isPublicService({} as Organization)).toBeFalsy(); }); it("should return true for collectivite territoriale", () => { - assert.equal(isPublicService(lamalou_org_info), true); + expect(isPublicService(lamalou_org_info)).toBeTruthy(); }); it("should return true for administration centrale", () => { - assert.equal(isPublicService(dinum_org_info), true); + expect(isPublicService(dinum_org_info)).toBeTruthy(); }); it("should return false for unipersonnelle organization", () => { - assert.equal(isPublicService(entreprise_unipersonnelle_org_info), false); + expect(isPublicService(entreprise_unipersonnelle_org_info)).toBeFalsy(); }); it("should return false for association", () => { - assert.equal(isPublicService(association_org_info), false); + expect(isPublicService(association_org_info)).toBeFalsy(); }); it("should return true for établissement public à caractère industriel et commercial", () => { - assert.equal(isPublicService(onf_org_info), true); + expect(isPublicService(onf_org_info)).toBeTruthy(); }); it("should return true for whitelisted établissement", () => { - assert.equal(isPublicService(whitelisted_org_info), true); + expect(isPublicService(whitelisted_org_info)).toBeTruthy(); }); it("should return true for public etablissement", () => { - assert.equal(isPublicService(trackdechets_public_org_info), true); + expect(isPublicService(trackdechets_public_org_info)).toBeTruthy(); }); }); describe("isWasteManagementOrganization", () => { it("should return false for collectivité territoriale", () => { - assert.equal(isWasteManagementOrganization(lamalou_org_info), false); + expect(isWasteManagementOrganization(lamalou_org_info)).toBeFalsy(); }); it("should return true for waste management organization", () => { - assert.equal( + expect( isWasteManagementOrganization(trackdechets_public_org_info), - true, - ); + ).toBeTruthy(); }); }); @@ -220,10 +218,9 @@ describe("isEtablissementScolaireDuPremierEtSecondDegre", () => { cached_categorie_juridique: "1000 ", cached_libelle_categorie_juridique: "Entrepreneur individuel", } as Organization; - assert.equal( + expect( isEtablissementScolaireDuPremierEtSecondDegre(indep_org_info), - false, - ); + ).toBeFalsy(); }); it("should return true for lycee public", () => { const lycee_public_org_info = { @@ -248,10 +245,9 @@ describe("isEtablissementScolaireDuPremierEtSecondDegre", () => { cached_libelle_categorie_juridique: "Établissement public local d'enseignement", } as Organization; - assert.equal( + expect( isEtablissementScolaireDuPremierEtSecondDegre(lycee_public_org_info), - true, - ); + ).toBeTruthy(); }); it("should return true for college public", () => { const college_public_org_info = { @@ -276,10 +272,9 @@ describe("isEtablissementScolaireDuPremierEtSecondDegre", () => { cached_libelle_categorie_juridique: "Établissement public local d'enseignement", } as Organization; - assert.equal( + expect( isEtablissementScolaireDuPremierEtSecondDegre(college_public_org_info), - true, - ); + ).toBeTruthy(); }); it("should return false for lycee prive", () => { const lycee_prive_org_info = { @@ -303,10 +298,9 @@ describe("isEtablissementScolaireDuPremierEtSecondDegre", () => { cached_categorie_juridique: "9220", cached_libelle_categorie_juridique: "Association déclarée", } as Organization; - assert.equal( + expect( isEtablissementScolaireDuPremierEtSecondDegre(lycee_prive_org_info), - false, - ); + ).toBeFalsy(); }); it("should return true for ecole primaire publique", () => { const ecole_primaire_publique_org_info: Organization = { @@ -330,12 +324,11 @@ describe("isEtablissementScolaireDuPremierEtSecondDegre", () => { cached_categorie_juridique: "7210", cached_libelle_categorie_juridique: "Commune et commune nouvelle", } as Organization; - assert.equal( + expect( isEtablissementScolaireDuPremierEtSecondDegre( ecole_primaire_publique_org_info, ), - true, - ); + ).toBeTruthy(); }); it("should return false for ecole primaire privee", () => { const ecole_primaire_privee_org_info = { @@ -359,12 +352,11 @@ describe("isEtablissementScolaireDuPremierEtSecondDegre", () => { cached_categorie_juridique: "9220", cached_libelle_categorie_juridique: "Association déclarée", } as Organization; - assert.equal( + expect( isEtablissementScolaireDuPremierEtSecondDegre( ecole_primaire_privee_org_info, ), - false, - ); + ).toBeFalsy(); }); }); @@ -372,13 +364,13 @@ describe("isEducationNationaleDomain", () => { ["zac-orleans.fr", "ac-bordeaux.fr.net", "ac-bordeaux.gouv.fr"].forEach( (domain) => { it("should return false for non educ nat domain", () => { - assert.equal(isEducationNationaleDomain(domain), false); + expect(isEducationNationaleDomain(domain)).toBeFalsy(); }); }, ); ["ac-orleans-tours.fr", "ac-bordeaux.fr"].forEach((domain) => { it("should return true for educ nat domain", () => { - assert.equal(isEducationNationaleDomain(domain), true); + expect(isEducationNationaleDomain(domain)).toBeTruthy(); }); }); }); diff --git a/test/symmetric-encryption.test.ts b/test/symmetric-encryption.test.ts index 5cb677520..fee2e1310 100644 --- a/test/symmetric-encryption.test.ts +++ b/test/symmetric-encryption.test.ts @@ -1,4 +1,4 @@ -import { expect } from "chai"; +import { describe, expect, it } from "vitest"; import { decryptSymmetric, encryptSymmetric, @@ -10,17 +10,15 @@ describe("Symmetric encryption with aes-128-ccm", () => { it("should encrypt and decrypt string", () => { const plain = "Bonjour monde !"; const encoded = encryptSymmetric(key, plain); - expect(decryptSymmetric(key, encoded)).to.eql(plain); + expect(decryptSymmetric(key, encoded)).toEqual(plain); }); it("should throw when encrypted string is null", () => { - expect(() => decryptSymmetric(key, null)).to.throw( - "Invalid encrypted text", - ); + expect(() => decryptSymmetric(key, null)).toThrow("Invalid encrypted text"); }); it("should throw when encrypted string is invalid", () => { - expect(() => decryptSymmetric(key, "null")).to.throw( + expect(() => decryptSymmetric(key, "null")).toThrow( "Invalid encrypted text", ); });