Skip to content

Commit

Permalink
Merge pull request #76 from Arquisoft/Develop
Browse files Browse the repository at this point in the history
Another error solved in deployment
  • Loading branch information
UO287747 authored Mar 4, 2024
2 parents 76e0050 + 1bb48b8 commit 4bc9adc
Show file tree
Hide file tree
Showing 13 changed files with 17,948 additions and 1,400 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ jobs:
- run: npm --prefix users/userservice ci
- run: npm --prefix question_generator ci
- run: npm --prefix questionservice ci
- run: npm --prefix gameservice ci
- run: npm --prefix gatewayservice ci
- run: npm --prefix webapp ci
- run: npm --prefix users/authservice test -- --coverage
- run: npm --prefix users/userservice test -- --coverage
- run: npm --prefix gameservice test -- --coverage
- run: npm --prefix questionservice test -- --coverage
- run: npm --prefix question_generator test -- --coverage
- run: npm --prefix gatewayservice test -- --coverage
- run: npm --prefix webapp test -- --coverage
- name: Analyze with SonarCloud
Expand Down
31 changes: 25 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ jobs:
- run: npm --prefix users/userservice ci
- run: npm --prefix question_generator ci
- run: npm --prefix questionservice ci
- run: npm --prefix gameservice ci
- run: npm --prefix gatewayservice ci
- run: npm --prefix webapp ci
- run: npm --prefix users/authservice test -- --coverage
- run: npm --prefix users/userservice test -- --coverage
- run: npm --prefix questionservice test -- --coverage
- run: npm --prefix question_generator test -- --coverage
- run: npm --prefix gameservice test -- --coverage
- run: npm --prefix gatewayservice test -- --coverage
- run: npm --prefix webapp test -- --coverage
- name: Analyze with SonarCloud
Expand All @@ -39,6 +43,7 @@ jobs:
- run: npm --prefix users/userservice install
- run: npm --prefix question_generator install
- run: npm --prefix questionservice install
- run: npm --prefix gameservice install
- run: npm --prefix gatewayservice install
- run: npm --prefix webapp install
- run: npm --prefix webapp run build
Expand Down Expand Up @@ -97,9 +102,8 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
workdir: users/userservice

docker-push-questiongenerationservice:
name: Push question service Docker Image to GitHub Packages
name: Push question generation service Docker Image to GitHub Packages
runs-on: ubuntu-latest
permissions:
contents: read
Expand All @@ -110,12 +114,11 @@ jobs:
- name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@v5
with:
name: arquisoft/wiq_es3b/questiongenerationservice
name: arquisoft/wiq_es3b/question_generator
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
workdir: question_generator

docker-push-questionservice:
name: Push question service Docker Image to GitHub Packages
runs-on: ubuntu-latest
Expand All @@ -133,7 +136,23 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
workdir: questionservice

docker-push-gameservice:
name: Push game 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_es3b/gameservice
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
workdir: gameservice
docker-push-gatewayservice:
name: Push gateway service Docker Image to GitHub Packages
runs-on: ubuntu-latest
Expand All @@ -154,7 +173,7 @@ jobs:
deploy:
name: Deploy over SSH
runs-on: ubuntu-latest
needs: [docker-push-userservice,docker-push-authservice,docker-push-questiongenerationservice,docker-push-questionservice,docker-push-gatewayservice,docker-push-webapp]
needs: [docker-push-userservice,docker-push-authservice,docker-push-questiongenerationservice,docker-push-questionservice,docker-push-gameservice,docker-push-gatewayservice,docker-push-webapp]
steps:
- name: Deploy over SSH
uses: fifsky/ssh-action@master
Expand Down
7 changes: 4 additions & 3 deletions gameservice/game-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@ const mongoose = require('mongoose');
const gameSchema = new mongoose.Schema({
user: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User',
required: true,
},
questions: {
type: mongoose.Schema.Types.ObjectId,
questions: {
type: [mongoose.Schema.Types.ObjectId],
ref: 'Question',
required: true,
},
answers: [
{
response: {
type: String,
required: true,
required: true,
},
isCorrect: {
type: Boolean,
Expand Down
17 changes: 11 additions & 6 deletions gameservice/game-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ const port = 8005; // Puerto para el servicio de juegos

app.use(express.json());

// Connect to MongoDB
const mongoUri = process.env.MONGODB_URI || 'mongodb://localhost:27017/gamesdb';
mongoose.connect(mongoUri);

// Función para validar campos requeridos
const validateRequiredFields = (req, fields) => {
for (const field of fields) {
Expand Down Expand Up @@ -34,20 +38,21 @@ app.post('/addgame', async (req, res) => {
// Guarda el nuevo juego en la base de datos
const savedGame = await newGame.save();

res.status(201).json(savedGame);
res.status(200).json(savedGame);
} catch (error) {
res.status(500).json({ error: 'Internal Server Error' });
res.status(500).json({ error: error.message });
}
});

// Lógica para juegos??

// Conecta a la base de datos de juegos
const mongoUri = process.env.MONGODB_URI || 'mongodb://localhost:27017/gamesdb';
mongoose.connect(mongoUri);

const server = app.listen(port, () => {
console.log(`Games Service listening at http://localhost:${port}`);
});

server.on('close', () => {
// Close the Mongoose connection
mongoose.connection.close();
});

module.exports = server;
39 changes: 39 additions & 0 deletions gameservice/game-service.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const request = require('supertest');
const { MongoMemoryServer } = require('mongodb-memory-server');

let mongoServer;
let app;

beforeAll(async () => {
mongoServer = await MongoMemoryServer.create();
const mongoUri = mongoServer.getUri();
process.env.MONGODB_URI = mongoUri;
app = require('./game-service');
});

afterAll(async () => {
app.close();
await mongoServer.stop();
});

describe('Game Service', () => {
it('should add a new game on POST /addgame', async () => {
const newGame = {
user: '609c6e365308ce1a1c2658d1',
questions: [
"609c6e365308ce1a1c2658d2", "609c6e365308ce1a1c2658d3"
],
answers: [
{
response: 'User response',
isCorrect: true,
},
],
totalTime: 120, // Tiempo total de la partida en segundos
};

const response = await request(app).post('/addgame').send(newGame);
expect(response.status).toBe(200);
expect(response.body).toHaveProperty('user', newGame.user.toString());
});
});
Loading

0 comments on commit 4bc9adc

Please sign in to comment.