From 965583406704696740fb6733aefa664c24e2958b Mon Sep 17 00:00:00 2001 From: angelalvaigle Date: Mon, 2 Dec 2024 02:30:36 +0100 Subject: [PATCH] stat-service test fix (2) --- .github/workflows/build.yml | 2 +- statservice/stat-service.test.js | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8740687..5834b12 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,7 +22,7 @@ jobs: - run: cp -R utils/ questionservice/ - run: cp -R errors/ statservice/ - run: cp -R middleware/ statservice/ - - run: cp -R utils/ statservice/ + #- run: cp -R utils/ statservice/ # Instalar dependencias - run: npm --prefix users/authservice ci - run: npm --prefix users/userservice ci diff --git a/statservice/stat-service.test.js b/statservice/stat-service.test.js index 526139c..f8f8f58 100644 --- a/statservice/stat-service.test.js +++ b/statservice/stat-service.test.js @@ -2,16 +2,17 @@ import request from 'supertest'; import { MongoMemoryServer } from 'mongodb-memory-server'; import { jest } from '@jest/globals'; // Importa jest desde @jest/globals -let mongoServer; -let app; - -jest.mock('./middleware/auth-middleware', () => ({ - authenticateUser: (req, res, next) => { - req.user = { userId: '507f1f77bcf86cd799439011', role: 'user' }; // Simula un usuario autenticado +// Sobrescribe `authenticateUser` antes de importar el servicio +jest.unstable_mockModule('./middleware/auth-middleware', () => ({ + authenticateUser: jest.fn((req, res, next) => { + req.user = { userId: '507f1f77bcf86cd799439011', role: 'user' }; next(); - }, + }), })); +let mongoServer; +let app; + beforeAll(async () => { mongoServer = await MongoMemoryServer.create(); const mongoUri = mongoServer.getUri(); @@ -27,7 +28,6 @@ afterAll(async () => { describe('Stat Service', () => { it('should add a new stat on POST /addstat', async () => { const newStat = { - userId: '507f1f77bcf86cd799439011', gameId: 'testGameId', questionId: 'testQuestionId', right: false,