diff --git a/gatewayservice/gateway-service.test.js b/gatewayservice/gateway-service.test.js index c0c58d00..c9604b25 100644 --- a/gatewayservice/gateway-service.test.js +++ b/gatewayservice/gateway-service.test.js @@ -15,8 +15,11 @@ describe('Gateway Service', () => { return Promise.resolve({ data: { token: 'mockedToken' } }); } else if (url.endsWith('/adduser')) { return Promise.resolve({ data: { userId: 'mockedUserId' } }); - } + } else if (url.endsWith('/addStatistic')) { + return Promise.resolve({ data: { statisticId: 'mockedStatisticId' } }); + } }); + axios.get.mockImplementation((url) => { if (url.endsWith('/generate-question')) { return Promise.resolve({ data: { question: 'mockedQuestion' } }); @@ -26,6 +29,8 @@ describe('Gateway Service', () => { return Promise.resolve({ data: { gamesPlayed: 'mockedGamesPlayed' , rigthAnswers: 'mockedRigthAnswers', wrongAnswers:'mockedWrongAnswers' }}); + } else if (url.endsWith('/users')) { + return Promise.resolve({ data: { users: ['mockedUser1', 'mockedUser2'] } }); } }); @@ -50,19 +55,19 @@ describe('Gateway Service', () => { expect(response.statusCode).toBe(200); expect(response.body.userId).toBe('mockedUserId'); }); -// Test /generate-question endpoint -it('should forward generate question request to question service', async () => { - const response = await request(app) - .get('/generate-question') - .set('Authorization', 'Bearer some-token'); - - if (response.statusCode !== 200) { - console.error(response.body.error); - } - - expect(response.statusCode).toBe(200); - expect(response.body.question).toBe('mockedQuestion'); -}); + // Test /generate-question endpoint + it('should forward generate question request to question service', async () => { + const response = await request(app) + .get('/generate-question') + .set('Authorization', 'Bearer some-token'); + + if (response.statusCode !== 200) { + console.error(response.body.error); + } + + expect(response.statusCode).toBe(200); + expect(response.body.question).toBe('mockedQuestion'); + }); // Test /questions endpoint it('should forward get questions request to question service', async () => { const response = await request(app) @@ -83,4 +88,23 @@ it('should forward generate question request to question service', async () => { expect(response.body.wrongAnswers).toBe('mockedWrongAnswers'); }); + // Test /addStatistic endpoint + it('should forward add statistic request to statistic service', async () => { + const response = await request(app) + .post('/addStatistic') + .send({ userId: 'testuser', gamesPlayed: 10, rightAnswers: 5, wrongAnswers: 5 }); + + expect(response.statusCode).toBe(200); + expect(response.body.statisticId).toBe('mockedStatisticId'); + }); + + // Test /users endpoint + it('should forward get users request to user service', async () => { + const response = await request(app) + .get('/users'); + + expect(response.statusCode).toBe(200); + expect(response.body.users).toEqual(['mockedUser1', 'mockedUser2']); + }); + }); \ No newline at end of file