Skip to content

Commit

Permalink
unit-tests fix (manual mock)
Browse files Browse the repository at this point in the history
  • Loading branch information
angelalvaigle committed Nov 28, 2024
1 parent c23f706 commit 1eaa00f
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 1,522 deletions.
25 changes: 13 additions & 12 deletions gatewayservice/gateway-service.test.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
import request from 'supertest';
import axios from 'axios';
const app = (await import('./gateway-service.js')).default;
import { jest } from '@jest/globals'; // Importa jest desde @jest/globals

jest.mock('axios');
// Crea el mock manualmente para asegurarte de que `post` es una función mock
axios.post = jest.fn((url, data) => {
if (url.endsWith('/login')) {
return Promise.resolve({ data: { token: 'mockedToken' } });
} else if (url.endsWith('/adduser')) {
return Promise.resolve({ data: { userId: 'mockedUserId' } });
}
});

let app = (await import('./gateway-service.js')).default;

afterAll(async () => {
app.close();
});

jest.mock('axios');

describe('Gateway Service', () => {
// Mock responses from external services
axios.post.mockImplementation((url, data) => {
if (url.endsWith('/login')) {
return Promise.resolve({ data: { token: 'mockedToken' } });
} else if (url.endsWith('/adduser')) {
return Promise.resolve({ data: { userId: 'mockedUserId' } });
}
});

// Test /login endpoint
it('should forward login request to auth service', async () => {
const response = await request(app)
Expand Down
Loading

0 comments on commit 1eaa00f

Please sign in to comment.