Skip to content

Commit

Permalink
Merge branch 'develop' into Fernado-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fer4github committed Apr 8, 2024
2 parents f56f792 + 12a64cc commit 896e172
Show file tree
Hide file tree
Showing 39 changed files with 10,679 additions and 814 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ jobs:
- run: npm --prefix userservice/authservice test -- --coverage
- run: npm --prefix userservice/userservice test -- --coverage
- run: npm --prefix gatewayservice test -- --coverage
#- run: npm --prefix questionservice test -- --coverage
#- run: npm --prefix webapp test -- --coverage
- run: npm --prefix questionservice test -- --coverage
- run: npm --prefix webapp test -- --coverage
- name: Analyze with SonarCloud
uses: sonarsource/sonarcloud-github-action@master
env:
Expand Down
80 changes: 75 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,16 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm --prefix questionservice ci
- run: npm --prefix userservice/authservice ci
- run: npm --prefix userservice/userservice ci
- run: npm --prefix gatewayservice ci
- run: npm --prefix webapp ci
#- run: npm --prefix webapp test -- --coverage
- run: npm --prefix questionservice ci
- run: npm --prefix userservice/authservice test -- --coverage
- run: npm --prefix userservice/userservice test -- --coverage
- run: npm --prefix gatewayservice test -- --coverage
- run: npm --prefix webapp test -- --coverage
- run: npm --prefix questionservice test -- --coverage
- name: Analyze with SonarCloud
uses: sonarsource/sonarcloud-github-action@master
env:
Expand All @@ -28,10 +35,13 @@ jobs:
- 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
- run: npm --prefix webapp run test:e2e
docker-push-webapp:
name: Push webapp Docker Image to GitHub Packages
runs-on: ubuntu-latest
Expand All @@ -52,6 +62,61 @@ jobs:
registry: ghcr.io
workdir: webapp
buildargs: API_URI
docker-push-authservice:
name: Push auth service Docker Image to GitHub Packages
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
needs: [e2e-tests]
steps:
- uses: actions/checkout@v4
- name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@v5
with:
name: arquisoft/wiq_es05a/authservice
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
workdir: users/authservice
docker-push-userservice:
name: Push user service Docker Image to GitHub Packages
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
needs: [e2e-tests]
steps:
- uses: actions/checkout@v4
- name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@v5
with:
name: arquisoft/wiq_es05a/userservice
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
workdir: users/userservice
docker-push-gatewayservice:
name: Push gateway service Docker Image to GitHub Packages
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
needs: [e2e-tests]
steps:
- uses: actions/checkout@v4
- name: Update OpenAPI configuration
run: |
DEPLOY_HOST=${{ secrets.DEPLOY_HOST }}
sed -i "s/SOMEIP/${DEPLOY_HOST}/g" gatewayservice/openapi.yaml
- name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@v5
with:
name: arquisoft/wiq_es05a/gatewayservice
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
workdir: gatewayservice
docker-push-questionservice:
name: Push questionservice Docker Image to GitHub Packages
runs-on: ubuntu-latest
Expand All @@ -72,7 +137,12 @@ jobs:
deploy:
name: Deploy over SSH
runs-on: ubuntu-latest
needs: [docker-push-questionservice,docker-push-webapp]
needs:
- docker-push-userservice
- docker-push-authservice
- docker-push-gatewayservice
- docker-push-questionservice
- docker-push-webapp
steps:
- name: Deploy over SSH
uses: fifsky/ssh-action@master
Expand All @@ -84,4 +154,4 @@ jobs:
wget https://raw.githubusercontent.com/arquisoft/wiq_es05a/master/docker-compose.yml -O docker-compose.yml
wget https://raw.githubusercontent.com/arquisoft/wiq_es05a/master/.env -O .env
docker compose --profile prod down
docker compose --profile prod up -d
docker compose --profile prod up -d --pull always
1 change: 1 addition & 0 deletions debug.log
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[0404/101930.492:ERROR:registration_protocol_win.cc(107)] CreateFile: El sistema no puede encontrar el archivo especificado. (0x2)
Binary file added docs/images/07_DiagramaDespliegue3.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/images/07_diagramaDespliegue2.png
Binary file not shown.
1 change: 0 additions & 1 deletion docs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/src/07_deployment_view.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Describe (usually in a combination of diagrams, tables, and text):
For multiple environments or alternative deployments please copy and adapt this section of arc42 for all relevant environments.
****

image::07_diagramaDespliegue2.png["Diagrama de despliegue"]
image::07_DiagramaDespliegue3.png["Diagrama de despliegue"]

Motivación::

Expand Down
57 changes: 55 additions & 2 deletions gatewayservice/gateway-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ const axios = require('axios');
const cors = require('cors');
const promBundle = require('express-prom-bundle');

//librerias para OpenAPI-Swagger
const swaggerUi = require('swagger-ui-express');
const fs = require("fs");
const YAML = require('yaml');

const app = express();
const port = 8000;

const userServiceUrl = process.env.USER_SERVICE_URL || 'http://localhost:8001';
const authServiceUrl = process.env.AUTH_SERVICE_URL || 'http://localhost:8002';
const questionServiceUrl = process.env.QUESTION_SERVICE_URL || 'http://localhost:8003';
const statServiceUrl = process.env.STAT_SERVICE_URL || 'http://localhost:8004';

app.use(cors());
app.use(express.json());
Expand Down Expand Up @@ -75,15 +79,64 @@ app.get('/pregunta', async (req, res) => {

app.get('/updateCorrectAnswers', async (req, res) => {
console.log(req.query)
const params = {username: req.query.username, numAnswers: req.query.numAnswers};
try{
const updateStatsResponse = await axios.get(userServiceUrl+ `/updateCorrectAnswers?params=${params}`)
res.json(updateStatsResponse.data);
}catch(error){
res.status(error.response.status).json({error: error.response.data.error});
}
});

app.get('/updateIncorrectAnswers', async (req, res) => {
const params = {username: req.query.username, numAnswers: req.query.numAnswers};
try{
const updateStatsResponse = await axios.get(userServiceUrl+ `/updateIncorrectAnswers?params=${params}`)
res.json(updateStatsResponse.data);
}catch(error){
res.status(error.response.status).json({error: error.response.data.error});
}
});

app.get('/updateCompletedGames', async (req, res) => {
const { username } = req.query;
try{
const updateStatsResponse = await axios.get(userServiceUrl+ `/updateCorrectAnswers?username=${username}`)
const updateStatsResponse = await axios.get(userServiceUrl+ `/updateCompletedGames?username=${username}`)
res.json(updateStatsResponse.data);
}catch(error){
res.status(error.response.status).json({error: error.response.data.error});
}
});



app.get('/getUserData', async (req, res) => {
console.log(req.query)
const { username } = req.query;
try{
const getUserDataResponse = await axios.get(userServiceUrl+ `/getUserData?username=${username}`)
res.json(getUserDataResponse.data);
}catch(error){
res.status(error.response.status).json({error: error.response.data.error});
}
});

// Read the OpenAPI YAML file synchronously
let openapiPath='./openapi.yaml';
if (fs.existsSync(openapiPath)) {
const file = fs.readFileSync(openapiPath, 'utf8');

// Parse the YAML content into a JavaScript object representing the Swagger document
const swaggerDocument = YAML.parse(file);

// Serve the Swagger UI documentation at the '/api-doc' endpoint
// This middleware serves the Swagger UI files and sets up the Swagger UI page
// It takes the parsed Swagger document as input
app.use('/api-doc', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
} else {
console.log("Not configuring OpenAPI. Configuration file not present.")
}

// Start the gateway service
const server = app.listen(port, () => {
console.log(`Gateway Service listening at http://localhost:${port}`);
Expand Down
20 changes: 5 additions & 15 deletions gatewayservice/gateway-service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,11 @@ describe('Gateway Service', () => {
});

// Test /login endpoint
it('should handle authentication securely', async () => {
// Datos de prueba para iniciar sesión
const loginData = {
username: 'testuser',
password: 'testpassword'
};

// Realizamos una solicitud POST al endpoint /login
it('should forward login request to auth service', async () => {
const response = await request(app)
.post('/login')
.send(loginData);
.post('/login')
.send({ username: 'testuser', password: 'testpassword' });

// Verificamos que la respuesta tenga un código de estado 200
expect(response.statusCode).toBe(200);
expect(response.body.token).toBe('mockedToken');
});
Expand Down Expand Up @@ -63,8 +55,8 @@ describe('Gateway Service', () => {

// Realizamos una solicitud POST al endpoint /login con datos incorrectos
const response = await request(app)
.post('/login')
.send(invalidLoginData);
.post('/adduser')
.send({ username: 'newuser', password: 'newpassword' });

// Verificamos que la respuesta tenga un código de estado 401 (Unauthorized)
expect(response.statusCode).toBe(401);
Expand Down Expand Up @@ -93,6 +85,4 @@ describe('Gateway Service', () => {
expect(response.status).toBe(200);
expect(response.body).toEqual(mockData);
});


});
Loading

0 comments on commit 896e172

Please sign in to comment.