Skip to content

Commit

Permalink
gatewayservice tests updated
Browse files Browse the repository at this point in the history
  • Loading branch information
UO287687 committed Apr 7, 2024
1 parent 5fa0a89 commit a7566a0
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions gatewayservice/gateway-service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,28 @@ describe('Gateway Service', () => {
expect(response.statusCode).toBe(401);
expect(response.body).toEqual({ error: "Unauthorized" });
});
// Test /verify endpoint when auth service is down
it('should return an error when the auth service is down', async () => {
const mockedToken = 'mockedToken';
axios.get.mockRejectedValueOnce({ response: { status: 500, data: { error: 'Service down' } } });
const response = await request(app)
.get('/verify')
.set('Authorization', `Bearer ${mockedToken}`);
expect(response.statusCode).toBe(500);
expect(response.body).toEqual({ error: 'Service down' });
});

// Test /verify endpoint when auth service returns an error
it('should return an error when the auth service returns an error', async () => {
const mockedToken = 'mockedToken';
const mockedError = { error: 'Unauthorized' };
axios.get.mockRejectedValueOnce({ response: { status: 401, data: mockedError } });
const response = await request(app)
.get('/verify')
.set('Authorization', `Bearer ${mockedToken}`);
expect(response.statusCode).toBe(401);
expect(response.body).toEqual(mockedError);
});



Expand Down

0 comments on commit a7566a0

Please sign in to comment.