Skip to content

Commit

Permalink
stat-service test fix (2)
Browse files Browse the repository at this point in the history
  • Loading branch information
angelalvaigle committed Dec 2, 2024
1 parent 3cfa917 commit 9655834
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions statservice/stat-service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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,
Expand Down

0 comments on commit 9655834

Please sign in to comment.