Skip to content

Commit

Permalink
Merge branch 'master' into 88-users-enhancenment
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Mario committed Apr 21, 2024
2 parents bb17d39 + fe4f955 commit 72850e7
Show file tree
Hide file tree
Showing 52 changed files with 2,300 additions and 147 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ docker compose --profile dev up --build
```

### Deployed in Cloud
In order to view the application deploy in the cloud click [here](http://172.203.216.60:3000)
In order to view the application deploy in the cloud click [here](http://wiqen1b.serveminecraft.net:3000)
### Members

- Lucía Ruiz Núñez [email protected]
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
prometheus:
image: prom/prometheus
container_name: prometheus-${teamname:-defaultASW}
profiles: ["dev"]
profiles: ["dev", "prod"]
networks:
- mynetwork
volumes:
Expand All @@ -127,7 +127,7 @@
grafana:
image: grafana/grafana
container_name: grafana-${teamname:-defaultASW}
profiles: ["dev"]
profiles: ["dev", "prod"]
networks:
- mynetwork
volumes:
Expand Down
104 changes: 103 additions & 1 deletion gatewayservice/gateway-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,69 @@ app.get('/questions', verifyToken, async (req, res) => {
}
});

app.get('/questions/:lang/:amount/:type', async (req, res) => {
try {
const lang = req.params.lang.toString();
const amount = req.params.amount.toString();
const type = req.params.type.toString();
// Forward the question request to the quetion service
const questionResponse = await axios.get(questionServiceUrl+'/questions/' + lang + '/' + amount + '/' + type);

res.json(questionResponse.data);
} catch (error) {

res.status(error.response.status).json({ error: error.response.data.error });
}
});


app.get('/questions/:lang/:amount', verifyToken, async (req, res) => {
try {
const lang = req.params.lang.toString();
const amount = req.params.amount.toString();
// Forward the question request to the quetion service
const questionResponse = await axios.get(questionServiceUrl+'/questions/' + lang + '/' + amount);

res.json(questionResponse.data);
} catch (error) {

res.status(error.response.status).json({ error: error.response.data.error });
}
});

app.get('/questions/:lang/:amount/:type', verifyToken, async (req, res) => {
try {
const lang = req.params.lang.toString();
const amount = req.params.amount.toString();
const type = req.params.type.toString();
// Forward the question request to the quetion service
const questionResponse = await axios.get(questionServiceUrl+'/questions/' + lang + '/' + amount + '/' + type);

res.json(questionResponse.data);
} catch (error) {

res.status(error.response.status).json({ error: error.response.data.error });
}
});


app.get('/questions/:lang/:amount', async (req, res) => {
try {
const lang = req.params.lang.toString();
const amount = req.params.amount.toString();
// Forward the question request to the quetion service
const questionResponse = await axios.get(questionServiceUrl+'/questions/' + lang + '/' + amount);

res.json(questionResponse.data);
} catch (error) {

res.status(error.response.status).json({ error: error.response.data.error });
}
});

app.get('/questions/:lang', verifyToken, async (req, res) => {
try {
const lang = req.params.lang;
const lang = req.params.lang.toString();
// Forward the question request to the quetion service
const questionResponse = await axios.get(questionServiceUrl+'/questions/' + lang.toString());

Expand All @@ -82,6 +142,48 @@ app.post('/record', verifyToken, async(req, res) => {
}
});

app.get('/record/ranking/top10', verifyToken, async(req, res)=>{
try {
// Forward the record request to the record service
const recordResponse = await axios.get(recordServiceUrl + '/record/ranking/top10');
res.json(recordResponse.data);
} catch (error) {
res.send(error);
}
});

app.get('/record/ranking/:user', verifyToken, async(req, res)=>{
try {
const user = req.params.user;
// Forward the record request to the record service
const recordResponse = await axios.get(recordServiceUrl + '/record/ranking/' + user);
res.json(recordResponse.data);
} catch (error) {
res.send(error);
}
});

app.get('/record/ranking/top10', verifyToken, async(req, res)=>{
try {
// Forward the record request to the record service
const recordResponse = await axios.get(recordServiceUrl + '/record/ranking/top10');
res.json(recordResponse.data);
} catch (error) {
res.send(error);
}
});

app.get('/record/ranking/:user', async(req, res)=>{
try {
const user = req.params.user;
// Forward the record request to the record service
const recordResponse = await axios.get(recordServiceUrl + '/record/ranking/' + user);
res.json(recordResponse.data);
} catch (error) {
res.send(error);
}
});

app.get('/record/:user', verifyToken, async(req, res)=>{
try {
const user = req.params.user;
Expand Down
78 changes: 65 additions & 13 deletions gatewayservice/gateway-service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,28 @@ describe('Gateway Service with token mock', () => {
}
});

const question = { data: [{question: "¿Cuál es la población de Oviedo?",
answers: ["225089","272357","267855","231841"]}] };

//Dont need to check a good record just that it redirects the call
const record = {data : {record:'undefined'}};

axios.get.mockImplementation((url, data) => {
if (url.endsWith('/questions')){
return Promise.resolve({ data: [{question: "¿Cuál es la población de Oviedo?",
answers: ["225089","272357","267855","231841"]}] });
return Promise.resolve(question);
} else if (url.endsWith('/questions/es/1/CAPITAL')){
return Promise.resolve(question);
} else if (url.endsWith('/questions/es/1')){
return Promise.resolve(question);
} else if (url.endsWith('/questions/es')){
return Promise.resolve({ data: [{question: "¿Cuál es la población de Oviedo?",
answers: ["225089","272357","267855","231841"]}] });
return Promise.resolve(question);

} else if(url.endsWith('/record/testuser')){
//Dont need to check a good record just that it redirects the call
return Promise.resolve({data : {record:'undefined'}})
return Promise.resolve(record)
} else if(url.endsWith('/record/ranking/top10')){
return Promise.resolve(record)
} else if(url.endsWith('/record/ranking/testuser')){
return Promise.resolve(record)
}
});

Expand Down Expand Up @@ -74,17 +86,31 @@ describe('Gateway Service with token mock', () => {
const response = await request(app)
.get('/questions').set('token', 'valorDelToken');

expect(response.statusCode).toBe(200);
expect(response.body[0]).toHaveProperty('question', "¿Cuál es la población de Oviedo?");
checkQuestion(response);
});

// Test /questions/:lang endpoint
it('should forward questions request to question service', async () => {
const response = await request(app)
.get('/questions/es').set('token', 'valorDelToken');

expect(response.statusCode).toBe(200);
expect(response.body[0]).toHaveProperty('question', "¿Cuál es la población de Oviedo?");
checkQuestion(response);
});

// Test /questions/:lang/:amount endpoint
it('should forward questions request to question service', async () => {
const response = await request(app)
.get('/questions/es/1');

checkQuestion(response);
});

// Test /questions/:lang/:amount/:type endpoint
it('should forward questions request to question service', async () => {
const response = await request(app)
.get('/questions/es/1/CAPITAL');

checkQuestion(response);
});

// Test /record endpoint
Expand Down Expand Up @@ -112,7 +138,33 @@ describe('Gateway Service without token mock', () => {
it('should not verify the token', async () => {
const response = await request(app)
.get('/record/testuser');
expect(response.statusCode).toBe(200);
expect(response.body).toHaveProperty('record', "undefined");

checkRecord(response);
});

// Test /record/ranking/:user endpoint
it('should forward record request to record service', async () => {
const response = await request(app)
.get('/record/ranking/testuser');

checkRecord(response);
});
})

// Test /record/ranking/top10 endpoint
it('should forward record request to record service', async () => {
const response = await request(app)
.get('/record/ranking/top10');
checkRecord(response);

});
});

function checkRecord(response){
expect(response.statusCode).toBe(200);
expect(response.body).toHaveProperty('record', "undefined");
}

function checkQuestion(response){
expect(response.statusCode).toBe(200);
expect(response.body[0]).toHaveProperty('question', "¿Cuál es la población de Oviedo?");
}
2 changes: 1 addition & 1 deletion gatewayservice/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ info:
servers:
- url: http://localhost:8000
description: Development server
- url: http://172.203.216.60:8000
- url: http://wiqen1b.serveminecraft.net:8000
description: Production server
paths:
/adduser:
Expand Down
Loading

0 comments on commit 72850e7

Please sign in to comment.