Skip to content

Commit

Permalink
Agregado algunos tests en el gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
Verzidee committed Apr 8, 2024
1 parent 78dcf2b commit 7769d96
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 23 deletions.
41 changes: 37 additions & 4 deletions gatewayservice/gateway-service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,49 @@ describe('Gateway Service', () => {
expect(response.statusCode).toBe(200);
expect(response.body.token).toBe('mockedToken');
});

// Test /adduser endpoint
// Test /adduser endpoint
it('should forward add user request to user service', async () => {
const response = await request(app)
.post('/adduser')
.send({ username: 'newuser', password: 'newpassword' });
.post('/adduser')
.send({ username: 'newuser', password: 'newpassword' });

expect(response.statusCode).toBe(200);
expect(response.body.userId).toBe('mockedUserId');
});

it('should handle errors from the auth service on login', async () => {
// Simula una respuesta de error del servicio de autenticación
axios.post.mockRejectedValue({ response: { status: 401, data: { error: 'Unauthorized' } } });

const response = await request(app)
.post('/login')
.send({ username: 'testuser', password: 'wrongpassword' });

expect(response.statusCode).toBe(401);
expect(response.body.error).toBe('Unauthorized');
});

it('should validate a token successfully', async () => {
// Simula una respuesta exitosa del servicio de autenticación
axios.get.mockResolvedValue({ data: { valid: true } });

const response = await request(app)
.get('/validate/mockedToken');

expect(response.statusCode).toBe(200);
expect(response.body.valid).toBe(true);
});
it('should handle validation error', async () => {
// Simula una respuesta de error del servicio de autenticación
axios.get.mockRejectedValue({ response: { status: 401, data: { error: 'Invalid token' } } });

const response = await request(app)
.get('/validate/invalidToken');

expect(response.statusCode).toBe(401);
expect(response.body.error).toBe('Invalid token');
});

// Test for /getquestions endpoint
it('should forward get questions request to generate service', async () => {
axios.get.mockResolvedValue({ data: [{ question: 'What is 2+2?' }] });
Expand Down
38 changes: 19 additions & 19 deletions gatewayservice/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7769d96

Please sign in to comment.