Skip to content

Commit

Permalink
Merge branch 'develop' into Fer-monitorizacion
Browse files Browse the repository at this point in the history
  • Loading branch information
uo289432 committed Apr 29, 2024
2 parents c6d8b59 + 34453cf commit 5cae804
Show file tree
Hide file tree
Showing 14 changed files with 186 additions and 231 deletions.
40 changes: 20 additions & 20 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,28 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
# e2e-tests:
# needs: [unit-tests]
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v4
# - uses: actions/setup-node@v4
# with:
# node-version: 20
# - run: npm --prefix userservice/authservice install
# - run: npm --prefix userservice/userservice install
# - run: npm --prefix gatewayservice install
# - run: npm --prefix questionservice install
# - run: npm --prefix webapp install
# - run: npm --prefix webapp run build
# - run: npm --prefix webapp run test:e2e
e2e-tests:
needs: [unit-tests]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm --prefix userservice/authservice install
- run: npm --prefix userservice/userservice install
- run: npm --prefix gatewayservice install
- run: npm --prefix questionservice install
- run: npm --prefix webapp install
- run: npm --prefix webapp run build
- run: npm --prefix webapp run test:e2e
docker-push-webapp:
name: Push webapp Docker Image to GitHub Packages
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
# needs: [e2e-tests]
needs: [e2e-tests]
steps:
- uses: actions/checkout@v4
- name: Publish to Registry
Expand All @@ -68,7 +68,7 @@ jobs:
permissions:
contents: read
packages: write
# needs: [e2e-tests]
needs: [e2e-tests]
steps:
- uses: actions/checkout@v4
- name: Publish to Registry
Expand All @@ -85,7 +85,7 @@ jobs:
permissions:
contents: read
packages: write
# needs: [e2e-tests]
needs: [e2e-tests]
steps:
- uses: actions/checkout@v4
- name: Publish to Registry
Expand All @@ -102,7 +102,7 @@ jobs:
permissions:
contents: read
packages: write
# needs: [e2e-tests]
needs: [e2e-tests]
steps:
- uses: actions/checkout@v4
- name: Update OpenAPI configuration
Expand All @@ -123,7 +123,7 @@ jobs:
permissions:
contents: read
packages: write
# needs: [e2e-tests]
needs: [e2e-tests]
steps:
- uses: actions/checkout@v4
- name: Publish to Registry
Expand Down
6 changes: 3 additions & 3 deletions gatewayservice/gateway-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ app.post('/login', async (req, res) => {

app.post('/adduser', async (req, res) => {
try {
const { username, password, valido, mensajeError } = req.body;
const { valido, mensajeError } = req.body;

if (!valido) {
// Si las credenciales son inválidas, devuelve un error 401
Expand Down Expand Up @@ -93,7 +93,7 @@ app.get('/getUserData', async (req, res) => {
const { username } = req.query;
try{
const getUserDataResponse = await axios.get(userServiceUrl+ `/getUserData?username=${username}`)
res.json(getUserDataResponse.data);
res.status(200).json(getUserDataResponse.data);
}catch(error){
res.status(error.response.status).json({error: error.response.data.error});
}
Expand All @@ -102,7 +102,7 @@ app.get('/getUserData', async (req, res) => {
app.get('/getUsernames', async (req, res) => {
try{
const getUserDataResponse = await axios.get(userServiceUrl+ `/getUsernames`)
res.json(getUserDataResponse.data);
res.status(200).json(getUserDataResponse.data);
}catch(error){
res.status(error.response.status).json({error: error.response.data.error});
}
Expand Down
24 changes: 7 additions & 17 deletions gatewayservice/gateway-service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,23 +194,7 @@ describe('Gateway Service', () => {
expect(response.status).toBe(401); // Esperamos un error de solicitud incorrecta
});

/*
it('debería manejar correctamente la carga excesiva', async () => {
// Realizar múltiples solicitudes simultáneas a endpoints diferentes
const promises = [];
for (let i = 0; i < 100; i++) {
promises.push(request(app).post('/login').send({ username: `user${i}`, password: 'password' }));
}
// Esperar a que se completen todas las solicitudes
const responses = await Promise.all(promises);
// Verificar que todas las respuestas tengan el código de estado esperado (200)
responses.forEach(response => {
expect(response.status).toBe(200);
});
});
*/


it('debería devolver un estado de salud "OK"', async () => {
const response = await request(app).get('/health');
Expand All @@ -219,4 +203,10 @@ describe('Gateway Service', () => {
expect(response.status).toBe(200);
expect(response.body).toEqual({ status: 'OK' });
});

it('Debería devolver una lista de nombres de usuario cuando hay usuarios en la base de datos', async () => {
const response = await request(app).get('/getUsernames');
expect(response.status).toBe(200);
});

});
125 changes: 35 additions & 90 deletions gatewayservice/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -183,21 +183,23 @@ paths:
type: string
description: Error information.
example: Internal Server Error
/updateCorrectAnswers:
/updateStats:
get:
summary: Updates the data of the user, increasing his number of correct answers.
operationId: updateCorrectAnswers
operationId: updateStats
parameters:
in: path
name: params
required: true
description: Parameters for the update (username and numAnswers)
description: Parameters for the update (username, numRespuestsasCorrectas, numRespuestasIncorrectas)
schema:
type: object
properties:
username:
type: string
numAnswers:
numRespuestsasCorrectas:
type: integer
numRespuestasIncorrectas:
type: integer
responses:
'200':
Expand All @@ -213,63 +215,16 @@ paths:
message:
type: string
example: Respuestas correctas actualizada con éxito
'404':
description: The user is not found.
content:
application/json:
schema:
type: object
properties:
success:
type: boolean
example: false
message:
type: string
example: Usuario no encontrado
'500':
description: Internal server error.
content:
application/json:
schema:
type: object
properties:
success:
type: boolean
example: false
message:
type: string
description: Error information.
example: Error al actualizar las respuestas correctas
/updateIncorrectAnswers:
get:
summary: Updates the data of the user, increasing his number of incorrect answers.
operationId: updateIncorrectAnswers
parameters:
in: path
name: params
required: true
description: Parameters for the update (username and numAnswers)
schema:
type: object
properties:
username:
type: string
numAnswers:
type: integer
responses:
'200':
description: Updates the data correctly.
'401':
description: Params needed for the get action.
content:
application/json:
schema:
type: object
properties:
success:
type: boolean
example: true
message:
error:
type: string
example: Respuestas incorrectas actualizada con éxito
example: Faltan parámetros en la solicitud.
'404':
description: The user is not found.
content:
Expand All @@ -296,16 +251,16 @@ paths:
message:
type: string
description: Error information.
example: Error al actualizar las respuestas incorrectas
/updateCompletedGames:
example: Error al actualizar las respuestas correctas
/getUserData:
get:
summary: Update the number of completed games by the user.
operationId: updateCompletedGames
summary: Gets the data of an user.
operationId: getUserData
parameters:
in: path
name: username
required: true
description: Username for the update of data
description: Username for the search of data
schema:
type: string
responses:
Expand All @@ -316,12 +271,22 @@ paths:
schema:
type: user
properties:
success:
type: boolean
example: true
message:
username:
type: string
example: Juegos completados actualizado con éxito
example: Pablo
password:
type: integer
example: pass
createdAt:
type: date
correctAnswers:
type: integer
incorrectAnswers:
type: integer
completedGames:
type: integer
averageTime:
type: integer
'404':
description: The user is not found.
content:
Expand All @@ -348,21 +313,14 @@ paths:
message:
type: string
description: Error information.
example: Error al actualizar Juegos completados
/getUserData:
example: Error al obtener los datos de usuario
/getUsernames:
get:
summary: Gets the data of an user.
operationId: getUserData
parameters:
in: path
name: username
required: true
description: Username for the search of data
schema:
type: string
summary: Gets all the usernames.
operationId: getUsernames
responses:
'200':
description: Finds the data of the user correctly.
description: Finds the data of the user correctly (or no users).
content:
application/json:
schema:
Expand All @@ -384,19 +342,6 @@ paths:
type: integer
averageTime:
type: integer
'404':
description: The user is not found.
content:
application/json:
schema:
type: object
properties:
success:
type: boolean
example: false
message:
type: string
example: Usuario no encontrado
'500':
description: Internal server error.
content:
Expand Down
Loading

0 comments on commit 5cae804

Please sign in to comment.