Skip to content

Commit

Permalink
Merge pull request #336 from Arquisoft/develop
Browse files Browse the repository at this point in the history
Integrate develop into master
  • Loading branch information
uo288543 authored Apr 27, 2024
2 parents 7bfffa0 + 2ea80b4 commit fdae091
Show file tree
Hide file tree
Showing 66 changed files with 2,483 additions and 2,543 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
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,17 @@
"steppedLine": false,
"targets": [
{
"expr": "sum(increase(http_request_duration_seconds_count[1m]))",
"expr": "sum(increase(http_request_duration_seconds_count[1h]))",
"interval": "",
"legendFormat": "Requests per minute",
"legendFormat": "Requests per hour",
"refId": "A"
}
],
"thresholds": [],
"timeFrom": null,
"timeRegions": [],
"timeShift": null,
"title": "Rate (R): Number of requests per minute",
"title": "Rate (R): Number of requests per hour",
"tooltip": {
"shared": true,
"sort": 0,
Expand Down Expand Up @@ -189,7 +189,7 @@
"steppedLine": false,
"targets": [
{
"expr": "sum(increase(http_request_duration_seconds_count{code=~\"5.*\"}[1m]))",
"expr": "sum(increase(http_request_duration_seconds_count{status_code=~\"4.*\"}[1m]))",
"interval": "",
"legendFormat": "",
"refId": "A"
Expand Down Expand Up @@ -369,7 +369,7 @@
]
},
"timezone": "",
"title": "Example Service Dashboard",
"title": "Wiq_es04 Dashboard",
"uid": "1DYaynomMk",
"version": 2
}
2 changes: 1 addition & 1 deletion gatewayservice/monitoring/prometheus/prometheus.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
global:
scrape_interval: 5s
scrape_configs:
- job_name: "example-nodejs-app"
- job_name: "wiq-es04-nodejs-app"
static_configs:
- targets: ["gatewayservice:8000"]
6 changes: 3 additions & 3 deletions multiplayer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ const app = express();
const server = http.createServer(app);
const io = socketIO(server, {
cors: { //permit connections from webapp
origin: [process.env.WEBAPP_ENDPOINT, "http://localhost:3000"],
//origin: "*", //this should be changed to improve security
//origin: [process.env.WEBAPP_ENDPOINT, "http://localhost:3000"],
origin: "*", //this should be changed to improve security
methods: ["GET", "POST"],
//allowedHeaders: "*" //this should be changed to improve security
allowedHeaders: "*" //this should be changed to improve security
}
});

Expand Down
105 changes: 89 additions & 16 deletions questions/__tests/routes/question-routes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const bodyParser = require('body-parser');
let mongoServer;
let questionFunctions;
let questionRoutes;
let generateQuestionsService;

//let mongoServer;
let app = express();
Expand All @@ -21,11 +22,11 @@ const questionData1 = {
};

const questionData2 = {
question: "Which is the capital of UK?",
question: "Which is the capital of Spain?",
options: ["Madrid", "Barcelona", "Paris", "London"],
correctAnswer: "London",
categories: ["Geography"],
language: "es"
language: "en"
};

async function addingQuestion(questionData) {
Expand All @@ -40,6 +41,12 @@ async function addingQuestion(questionData) {
await questionFunctions.addQuestion(newQuestion);
}

async function addingQuestions() {
for(var i = 0; i < 24; i++) {
await addingQuestion(questionData1);
await addingQuestion(questionData2);
}
}

beforeAll(async () => {
mongoServer = await MongoMemoryServer.create();
Expand All @@ -48,19 +55,17 @@ beforeAll(async () => {
await mongoose.connect(mongoURI);
questionFunctions = require('../../services/question-data-service');
questionRoutes = require('../../routes/question-routes.js');
generateQuestionsService = require('../../services/generate-questions-service');
jest.mock('../../services/generate-questions-service');
app.use(bodyParser.json());
app.use('/questions', questionRoutes);

});

beforeEach(async () => {
//Load database with initial conditions
//await mongoose.connection.dropDatabase();
await Question.deleteMany({});
for(var i = 0; i < 100; i++) {
await addingQuestion(questionData1);
await addingQuestion(questionData2);
}
await addingQuestions();
});

afterAll(async () => {
Expand All @@ -71,25 +76,92 @@ beforeEach(async () => {


describe('Question routes', function() {
it('It should get a question from the database', async function() {

describe('Get a question from the database', function() {
it('get question when 0 questions', async function() {
await Question.deleteMany({});
await generateQuestionsService.generateQuestions.mockResolvedValue({"response":{"status":"200"}});
const response = await request(app).get('/questions/es');
await expect(response.status).toBe(200);
await expect(response.body.question).toBe(undefined);
});

it('get question when less than 50 questions', async function() {
await generateQuestionsService.generateQuestions.mockResolvedValue({"response":{"status":"200"}});
const response = await request(app).get('/questions/en');
await expect(response.status).toBe(200);
await expect(response.body.question).toBe('Which is the capital of Spain?');
});


it('It should get n questions from the database', async function() {
const response = await request(app).get('/questions/getQuestionsFromDb/3/en');
it('get question when less than 100 questions', async function() {
await addingQuestions();
await generateQuestionsService.generateQuestions.mockResolvedValue({"response":{"status":"200"}});
const response = await request(app).get('/questions/en');
await expect(response.status).toBe(200);
await expect(response.body.length).toBe(3);
});
await expect(response.body.question).toBe('Which is the capital of Spain?');
});

it('get question when more than 100 questions', async function() {
await addingQuestions();
await addingQuestions();
await generateQuestionsService.generateQuestions.mockResolvedValue({"response":{"status":"200"}});
const response = await request(app).get('/questions/en');
await expect(response.status).toBe(200);
await expect(response.body.question).toBe('Which is the capital of Spain?');
});
});
describe('Get n questions from the database', function() {
it('get question when less than 50 questions', async function() {
await generateQuestionsService.generateQuestions.mockResolvedValue({"response":{"status":"200"}});
const response = await request(app).get('/questions/getQuestionsFromDb/3/en');
await expect(response.status).toBe(200);
await expect(response.body.length).toBe(3);
});

it('get question when less than 100 questions', async function() {
await addingQuestions();
await generateQuestionsService.generateQuestions.mockResolvedValue({"response":{"status":"200"}});
const response = await request(app).get('/questions/getQuestionsFromDb/3/en');
await expect(response.status).toBe(200);
await expect(response.body.length).toBe(3);
});

it('get question when more than 100 questions', async function() {
await addingQuestions();
await addingQuestions();
await generateQuestionsService.generateQuestions.mockResolvedValue({"response":{"status":"200"}});
const response = await request(app).get('/questions/getQuestionsFromDb/3/en');
await expect(response.status).toBe(200);
await expect(response.body.length).toBe(3);
});

it('It should not get n questions from the database', async function() {
const response = await request(app).get('/questions/getQuestionsFromDb/-1/en');
await expect(response.status).toBe(400);
});

it('It should get n questions of certain category from the database', async function() {
});
describe('Get n questions from the database filtered by category', function() {

it('get question when less than 50 questions', async function() {
await generateQuestionsService.generateQuestions.mockResolvedValue({"response":{"status":"200"}});
const response = await request(app).get('/questions/getQuestionsFromDb/2/Geography/en');
await expect(response.status).toBe(200);
await expect(response.body.length).toBe(2);
await expect(response.body[0].categories[0]).toBe("Geography");
});
it('get question when less than 100 questions', async function() {
await addingQuestions();
await generateQuestionsService.generateQuestions.mockResolvedValue({"response":{"status":"200"}});
const response = await request(app).get('/questions/getQuestionsFromDb/2/Geography/en');
await expect(response.status).toBe(200);
await expect(response.body.length).toBe(2);
await expect(response.body[0].categories[0]).toBe("Geography");
});

it('get question when more than 100 questions', async function() {
await addingQuestions();
await addingQuestions();
await generateQuestionsService.generateQuestions.mockResolvedValue({"response":{"status":"200"}});
const response = await request(app).get('/questions/getQuestionsFromDb/2/Geography/en');
await expect(response.status).toBe(200);
await expect(response.body.length).toBe(2);
Expand All @@ -106,4 +178,5 @@ describe('Question routes', function() {
it('should connect to the MongoDB server in memory', async () => {
expect(mongoose.connection.readyState).toBe(1); // 1 means connected
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('Question generation', function() {

dbService.addQuestion.mockResolvedValue();
// Llama a la función que deseas probar
await generator.generateQuestions(1);
await generator.generateQuestions(1,"en","Geography");

// Verifica que la función haya realizado las operaciones esperadas
expect(dbService.addQuestion).toHaveBeenCalledTimes(1);
Expand All @@ -76,7 +76,7 @@ describe('Question generation', function() {

console.error = jest.fn();
// Llama a la función que deseas probar
await generator.generateQuestions(1);
await generator.generateQuestions(1,"en");

// Verifica que la función haya realizado las operaciones esperadas
expect(dbService.addQuestion).toHaveBeenCalledTimes(0);
Expand Down
Loading

0 comments on commit fdae091

Please sign in to comment.