Skip to content

Commit

Permalink
Merge branch 'develop' into develop-deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
uo288543 committed Apr 26, 2024
2 parents b5759bc + 0f080d7 commit 2f829c0
Show file tree
Hide file tree
Showing 58 changed files with 914 additions and 520 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Build
on:
push:
branches: [master, develop, develop-deploy, develop-teresa]
branches: [master, develop, develop-deploy, develop-teresa, develop_samuel]

pull_request:
types: [opened, synchronize, reopened]
Expand Down
9 changes: 9 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ services:
- "27017:27017"
networks:
- mynetwork
restart: always

mariadb:
container_name: mariadb
Expand All @@ -24,6 +25,7 @@ services:
- "3306:3306"
networks:
- mynetwork
restart: always

users:
container_name: users
Expand All @@ -38,6 +40,7 @@ services:
- mynetwork
environment:
DATABASE_URL: mariadb:3306/userdb
restart: always

questions:
container_name: questions
Expand All @@ -53,6 +56,7 @@ services:
environment:
DATABASE_URI: mongodb://mongodb:27017/questionDB
TEST_DATABASE_URI: mongodb://mongodb:27017/test
restart: always

gatewayservice:
container_name: gatewayservice
Expand All @@ -69,6 +73,7 @@ services:
environment:
USER_SERVICE_URL: http://users:8001
QUESTION_SERVICE_URL: http://questions:8010
restart: always

webapp:
container_name: webapp
Expand All @@ -85,6 +90,7 @@ services:
environment:
REACT_APP_API_ENDPOINT: http://gatewayservice:8000
REACT_APP_MULTIPLAYER_ENDPOINT: http://multiplayer:5010
restart: always

multiplayer:
container_name: multiplayer
Expand All @@ -100,6 +106,7 @@ services:
environment:
WEBAPP_ENDPOINT: http://webapp:3000
GATEWAY_SERVICE_ENDPOINT: http://gatewayservice:8000
restart: always

prometheus:
image: prom/prometheus
Expand All @@ -114,6 +121,7 @@ services:
- "9090:9090"
depends_on:
- gatewayservice
restart: always

grafana:
image: grafana/grafana
Expand All @@ -133,6 +141,7 @@ services:
- "9091:9091"
depends_on:
- prometheus
restart: always

volumes:
mariadb_data:
Expand Down
58 changes: 29 additions & 29 deletions gatewayservice/__tests/gateway-service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ describe('Routes Tests', () => {
process.exit(0);
}, 5000);

it('should respond with status 200 for /user/questionsRecord/:username/:gameMode endpoint', async () => {
it('should respond with status 200 for /questionsRecord/:username/:gameMode endpoint', async () => {
const mockUsername = 'testuser';
const mockGameMode = 'testMode';
const mockUserData = { username: mockUsername, gameMode: mockGameMode, questions: ['question1', 'question2'] };

axios.get.mockResolvedValueOnce({ data: mockUserData });

const response = await request(app)
.get(`/user/questionsRecord/${mockUsername}/${mockGameMode}`);
.get(`/questionsRecord/${mockUsername}/${mockGameMode}`);

expect(axios.get).toHaveBeenCalledWith(
expect.stringContaining(`/user/questionsRecord/${mockUsername}/${mockGameMode}`), {}
Expand All @@ -32,14 +32,14 @@ describe('Routes Tests', () => {
expect(response.body).toEqual(mockUserData);
});

it('should respond with status 200 for /user/questionsRecord endpoint', async () => {
it('should respond with status 200 for /questionsRecord endpoint', async () => {
const mockRequestData = { userId: 'testuser', questions: ['question1', 'question2'] };
const mockResponseData = { success: true };

axios.post.mockResolvedValueOnce({ data: mockResponseData });

const response = await request(app)
.post('/user/questionsRecord')
.put('/questionsRecord')
.send(mockRequestData);

expect(axios.post).toHaveBeenCalledWith(
Expand All @@ -50,13 +50,13 @@ describe('Routes Tests', () => {
expect(response.body).toEqual(mockResponseData);
});

it('should handle /user/questionsRecord errors and respond with appropriate status and message', async () => {
it('should handle /questionsRecord errors and respond with appropriate status and message', async () => {
const mockRequestData = { userId: 'testuser', questions: ['question1', 'question2'] };
const errorMessage = 'Error updating questions record';
axios.post.mockRejectedValueOnce(new Error(errorMessage));

const response = await request(app)
.post('/user/questionsRecord')
.put('/questionsRecord')
.send(mockRequestData);

expect(axios.post).toHaveBeenCalledWith(
Expand Down Expand Up @@ -117,22 +117,22 @@ describe('Routes Tests', () => {
expect(response.body.error).toBe('Error al obtener la sesión del usuario');
});

it('should respond with status 200 for /user/ranking endpoint', async () => {
it('should respond with status 200 for /ranking endpoint', async () => {
const mockRankingData = [{ username: 'user1', score: 100 }, { username: 'user2', score: 90 }];
axios.get.mockResolvedValueOnce({ data: mockRankingData });

const response = await request(app).get('/user/ranking');
const response = await request(app).get('/ranking');

expect(axios.get).toHaveBeenCalledWith(expect.stringContaining('/user/ranking'));
expect(response.status).toBe(200);
expect(response.body).toEqual(mockRankingData);
});

it('should handle /user/ranking errors and respond with appropriate status and message', async () => {
it('should handle /ranking errors and respond with appropriate status and message', async () => {
const errorMessage = 'Error fetching ranking data';
axios.get.mockRejectedValueOnce(new Error(errorMessage));

const response = await request(app).get('/user/ranking');
const response = await request(app).get('/ranking');

expect(axios.get).toHaveBeenCalledWith(expect.stringContaining('/user/ranking'));
expect(response.status).toBe(500);
Expand All @@ -146,7 +146,7 @@ describe('Routes Tests', () => {

const response = await request(app).get(`/user/${username}`);

expect(axios.get).toHaveBeenCalledWith(expect.stringContaining(`/user/${username}`), {});
expect(axios.get).toHaveBeenCalledWith(expect.stringContaining(`/user/${username}`));
expect(response.status).toBe(200);
expect(response.body).toEqual(mockUserData);
});
Expand All @@ -158,7 +158,7 @@ describe('Routes Tests', () => {

const response = await request(app).get(`/user/${username}`);

expect(axios.get).toHaveBeenCalledWith(`http://localhost:8001/user/${username}`, {});
expect(axios.get).toHaveBeenCalledWith(`http://localhost:8001/user/${username}`);
expect(response.status).toBe(500);
expect(response.body.error).toBe('Error fetching user data');
});
Expand Down Expand Up @@ -214,7 +214,7 @@ describe('Routes Tests', () => {
axios.post.mockResolvedValueOnce({ data: mockUserData });

const requestBody = { username: 'testuser', statistics: { points: 100 } };
const response = await request(app).post('/statistics').send(requestBody);
const response = await request(app).put('/statistics').send(requestBody);

expect(axios.post).toHaveBeenCalledWith(expect.stringContaining('/statistics'), requestBody);
expect(response.status).toBe(200);
Expand All @@ -226,18 +226,18 @@ describe('Routes Tests', () => {
axios.post.mockRejectedValueOnce(new Error(errorMessage));

const requestBody = { username: 'testuser', statistics: { points: 100 } };
const response = await request(app).post('/statistics').send(requestBody);
const response = await request(app).put('/statistics').send(requestBody);

expect(axios.post).toHaveBeenCalledWith(expect.stringContaining('/statistics'), requestBody);
expect(response.status).toBe(500);
expect(response.body.error).toBe(errorMessage);
});

it('should respond with status 200 for /user/statistics/:username endpoint', async () => {
it('should respond with status 200 for /statistics/:username endpoint', async () => {
const mockUserData = { username: 'testuser', statistics: { points: 100 } };
axios.get.mockResolvedValueOnce({ data: mockUserData });

const response = await request(app).get('/user/statistics/testuser').query({ loggedUser: 'testuser' });
const response = await request(app).get('/statistics/testuser').query({ loggedUser: 'testuser' });

expect(axios.get).toHaveBeenCalledWith(expect.stringContaining('/user/statistics/testuser'), {
params: { loggedUser: 'testuser' }
Expand All @@ -246,11 +246,11 @@ describe('Routes Tests', () => {
expect(response.body).toEqual(mockUserData);
});

it('should handle errors for /user/statistics/:username endpoint and respond with appropriate status and message', async () => {
it('should handle errors for /statistics/:username endpoint and respond with appropriate status and message', async () => {
const errorMessage = 'Error retrieving user statistics';
axios.get.mockRejectedValueOnce(new Error(errorMessage));

const response = await request(app).get('/user/statistics/testuser').query({ loggedUser: 'testuser' });
const response = await request(app).get('/statistics/testuser').query({ loggedUser: 'testuser' });

expect(axios.get).toHaveBeenCalledWith(expect.stringContaining('/user/statistics/testuser'), {
params: { loggedUser: 'testuser' }
Expand Down Expand Up @@ -307,33 +307,33 @@ describe('Routes Tests', () => {
});

it('should respond with status 200 for /group/:name endpoint', async () => {
const groupName = 'Test Group';
const groupName = 'TestGroup';
const mockUserData = { username: 'testuser', groupName: groupName };
axios.post.mockResolvedValueOnce({ data: mockUserData });

const requestBody = { username: 'testuser' };
const response = await request(app).post(`/group/${groupName}`).send(requestBody);
const response = await request(app).put(`/group/${groupName}`).send(requestBody);

expect(axios.post).toHaveBeenCalledWith(expect.stringContaining(`/group/${groupName}`), requestBody);
expect(response.status).toBe(200);
expect(response.body).toEqual(mockUserData);
});

it('should handle errors for /group/:name endpoint and respond with appropriate status and message', async () => {
const groupName = 'Test Group';
const groupName = 'TestGroup';
const errorMessage = 'Error joining group';
axios.post.mockRejectedValueOnce({ response: { status: 400, data: { error: errorMessage } } });

const requestBody = { username: 'testuser' };
const response = await request(app).post(`/group/${groupName}`).send(requestBody);
const response = await request(app).put(`/group/${groupName}`).send(requestBody);

expect(axios.post).toHaveBeenCalledWith(expect.stringContaining(`/group/${groupName}`), requestBody);
expect(response.status).toBe(400);
expect(response.body.error).toBe(errorMessage);
});

it('should respond with status 200 for /group/:name endpoint', async () => {
const groupName = 'Test Group';
const groupName = 'TestGroup';
const username = 'user1';
const mockGroupData = { name: groupName, members: ['user1', 'user2'] };
axios.get.mockResolvedValueOnce({ data: mockGroupData });
Expand All @@ -346,7 +346,7 @@ describe('Routes Tests', () => {
});

it('should handle errors for /group/:name endpoint and respond with appropriate status and message', async () => {
const groupName = 'Test Group';
const groupName = 'TestGroup';
const username = 'user1';
const errorMessage = 'Error retrieving group data';
axios.get.mockRejectedValueOnce(new Error(errorMessage));
Expand All @@ -370,7 +370,7 @@ describe('Routes Tests', () => {

axios.get.mockResolvedValue({ data: mockUserData });

const response = await request(app).get('/user/profile').query({ username });
const response = await request(app).get('/profile').query({ username });

expect(axios.get).toHaveBeenCalledWith(
expect.stringContaining(`/user/profile`),
Expand Down Expand Up @@ -399,7 +399,7 @@ describe('Routes Tests', () => {

axios.post.mockResolvedValue({ data: mockResponseData });

const response = await request(app).post(`/user/profile/${username}`).send(mockUpdateData);
const response = await request(app).put(`/profile/${username}`).send(mockUpdateData);

expect(axios.post).toHaveBeenCalledWith(
expect.stringContaining(`/user/profile/${username}`),
Expand All @@ -420,9 +420,9 @@ describe('Routes Tests', () => {

axios.get.mockResolvedValue({ data: mockRankingData });

const response = await request(app).get('/user/group/ranking');
const response = await request(app).get('/group/ranking');

expect(axios.get).toHaveBeenCalledWith(expect.stringContaining(`/user/group/ranking`));
expect(axios.get).toHaveBeenCalledWith(expect.stringContaining(`/group/ranking`));

expect(response.status).toBe(200);
expect(response.body).toEqual(mockRankingData);
Expand All @@ -435,7 +435,7 @@ describe('Routes Tests', () => {

axios.post.mockResolvedValue({ data: mockResponseData });

const response = await request(app).post(`/group/${groupName}/exit`).send(mockRequestBody);
const response = await request(app).put(`/group/${groupName}/exit`).send(mockRequestBody);

expect(axios.post).toHaveBeenCalledWith(
expect.stringContaining(`/user/group/${groupName}/exit`),
Expand Down
Loading

0 comments on commit 2f829c0

Please sign in to comment.