From 6e1d9fdebf1bfb07baf0aca88d2a2980b3758421 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Tue, 31 Dec 2024 14:47:14 +0100 Subject: [PATCH] socketmock --- backend/package-lock.json | 20 +++++++++++++++++++ backend/package.json | 1 + .../src/controllers/tests/1-clients.test.ts | 4 +++- .../controllers/tests/2-consultants.test.ts | 2 ++ backend/src/models/technical.ts | 1 + backend/types/express/index.d.ts | 2 +- 6 files changed, 28 insertions(+), 2 deletions(-) diff --git a/backend/package-lock.json b/backend/package-lock.json index 10e61684..5b553fb0 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -84,6 +84,7 @@ "lint-staged": "^10.0.1", "mongodb-memory-server": "^8.12.1", "nodemon": "^1.11.0", + "socket.io-mock": "^1.3.2", "supertest": "^6.3.3", "ts-jest": "^29.0.5", "typescript": "4.3" @@ -16646,6 +16647,16 @@ "ws": "~8.17.1" } }, + "node_modules/socket.io-mock": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/socket.io-mock/-/socket.io-mock-1.3.2.tgz", + "integrity": "sha512-p4MQBue3NAR8bXIHynRJxK/C+J3I3NpnnpgjptgLFSWv4u9Bdkubf2t0GCmyLmUTi03up0Cx/hQwzQfOpD187g==", + "dev": true, + "license": "MIT", + "dependencies": { + "component-emitter": "^1.3.0" + } + }, "node_modules/socket.io-parser": { "version": "4.2.4", "resolved": "https://registry.npmjs.org/socket.io-parser/-/socket.io-parser-4.2.4.tgz", @@ -31827,6 +31838,15 @@ "ws": "~8.17.1" } }, + "socket.io-mock": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/socket.io-mock/-/socket.io-mock-1.3.2.tgz", + "integrity": "sha512-p4MQBue3NAR8bXIHynRJxK/C+J3I3NpnnpgjptgLFSWv4u9Bdkubf2t0GCmyLmUTi03up0Cx/hQwzQfOpD187g==", + "dev": true, + "requires": { + "component-emitter": "^1.3.0" + } + }, "socket.io-parser": { "version": "4.2.4", "resolved": "https://registry.npmjs.org/socket.io-parser/-/socket.io-parser-4.2.4.tgz", diff --git a/backend/package.json b/backend/package.json index 3d3b73ba..c9c7f0cf 100644 --- a/backend/package.json +++ b/backend/package.json @@ -102,6 +102,7 @@ "lint-staged": "^10.0.1", "mongodb-memory-server": "^8.12.1", "nodemon": "^1.11.0", + "socket.io-mock": "^1.3.2", "supertest": "^6.3.3", "ts-jest": "^29.0.5", "typescript": "4.3" diff --git a/backend/src/controllers/tests/1-clients.test.ts b/backend/src/controllers/tests/1-clients.test.ts index 7fccf11d..e7351ab9 100644 --- a/backend/src/controllers/tests/1-clients.test.ts +++ b/backend/src/controllers/tests/1-clients.test.ts @@ -8,7 +8,8 @@ import { IAudit } from '../../models/common'; import { ObjectID } from 'mongodb' import { IClient } from '../../models/clients' import { Jwt } from '../../models/technical' -import { saveClient } from '../clients' +import { saveClient } from '../clients'; +import MockedSocket from 'socket.io-mock'; const fakeUser: Jwt = { data: { @@ -44,6 +45,7 @@ describe('clients controller :: saveClient creation', () => { user: fakeUser, body: {...fakeClient, name: 'Company X'}, db: fakeDb, + io: new MockedSocket(), } as ConfacRequest; const res = { diff --git a/backend/src/controllers/tests/2-consultants.test.ts b/backend/src/controllers/tests/2-consultants.test.ts index 726cbe68..b3d9c35f 100644 --- a/backend/src/controllers/tests/2-consultants.test.ts +++ b/backend/src/controllers/tests/2-consultants.test.ts @@ -12,6 +12,7 @@ import { saveConsultant } from '../consultants'; import { IConsultant } from '../../models/consultants'; import { MongoMemoryServer } from 'mongodb-memory-server'; + const fakeUser: Jwt = { data: { _id: '_id', email: 'string', firstName: 'first', name: 'name', alias: 'alias', active: true }, iat: 0, exp: 0, @@ -29,6 +30,7 @@ const createFakeRequestAndResponse = (db: Db, consultant: Partial | user: fakeUser, body: {...fakeConsultant, ...(consultant || {})}, db, + io: new MockedSocket(), } as ConfacRequest; const res = { diff --git a/backend/src/models/technical.ts b/backend/src/models/technical.ts index 9c7c1346..28705981 100644 --- a/backend/src/models/technical.ts +++ b/backend/src/models/technical.ts @@ -1,4 +1,5 @@ import {Request} from 'express'; +import { Server } from 'socket.io'; export type Jwt = { data: { diff --git a/backend/types/express/index.d.ts b/backend/types/express/index.d.ts index 1a7a456b..a12eadbd 100644 --- a/backend/types/express/index.d.ts +++ b/backend/types/express/index.d.ts @@ -5,7 +5,7 @@ declare global { namespace Express { export interface Request { db: Db; - io: Server + io: Server; } } }