Skip to content

Commit

Permalink
Gateway service tests extended, now including ranking and health endp…
Browse files Browse the repository at this point in the history
…oints
  • Loading branch information
ChristianFN2 committed Apr 25, 2024
1 parent 091722d commit 6b316d7
Showing 1 changed file with 41 additions and 2 deletions.
43 changes: 41 additions & 2 deletions gatewayservice/gateway-service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('Gateway Service', () => {
}
});

axios.get.mockImplementation((url) => {
axios.get.mockImplementation((url,data) => {
if (url.endsWith('/imgs/flags/question')) {
return generateMockResponse(url, [
{ item: 'Flag0', itemLabel: 'Country0', image: 'flag0.jpg' },
Expand Down Expand Up @@ -87,8 +87,16 @@ describe('Gateway Service', () => {
]);
} else if (url.endsWith('/rankings/category1')) {
return Promise.resolve({ data: mockUserData });
} else if (url.endsWith('/ranking/user')) {
return Promise.resolve({data:{
username: data.params.username,
category: data.params.category,
points: 5,
questions: 7,
correct: 5,
wrong: 2
}});
}

});

// Test /login endpoint
Expand Down Expand Up @@ -263,6 +271,37 @@ it('should forward get Foods request to question service', async () => {

});

// Test /health endpoint
it('should inform that the health is OK if the service is operative', async () => {

// Send POST request to gateway endpoint
const response = await request(app)
.get('/health')

// Verify response body
expect(response.body.status).toEqual('OK');
});

// Test /ranking/user
it('should inform that the health is OK if the service is operative', async () => {

// Send POST request to gateway endpoint
const response = await request(app)
.get('/ranking/user')
.query({
username: "username",
category: "category"
})

// Verify response body
expect(response.body).toEqual({
username: "username",
category: "category",
points: 5,
questions: 7,
correct: 5,
wrong: 2
});
});

});

0 comments on commit 6b316d7

Please sign in to comment.