Skip to content

Commit

Permalink
Merge branch 'develop' into stats-ui
Browse files Browse the repository at this point in the history
  • Loading branch information
iyanfdezz authored Mar 4, 2024
2 parents 93a9a65 + bc5ac14 commit b71b5df
Show file tree
Hide file tree
Showing 22 changed files with 14,218 additions and 342 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:
- run: npm --prefix users/authservice ci
- run: npm --prefix users/userservice ci
- run: npm --prefix gatewayservice ci
- run: npm --prefix questionservice ci
- run: npm --prefix statsservice ci
- run: npm --prefix webapp ci
- run: npm --prefix questionservice ci
- run: npm --prefix statsservice ci
Expand Down
15 changes: 15 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ services:
- "8003:8003"
networks:
- mynetwork

statsservice:
container_name: statsservice-${teamname:-defaultASW}
image: ghcr.io/arquisoft/wiq_es1a/statsservice:latest
profiles: ["dev", "prod"]
build: ./statsservice
depends_on:
- mongodb
ports:
- "8004:8004"
networks:
- mynetwork
environment:
MONGODB_URI: mongodb://mongodb:27017/userdb

statsservice:
container_name: statsservice-${teamname:-defaultASW}
Expand Down Expand Up @@ -72,6 +86,7 @@ services:
build: ./gatewayservice
depends_on:
- mongodb
- statsservice
- userservice
- authservice
- questionservice
Expand Down
4 changes: 2 additions & 2 deletions gatewayservice/gateway-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ app.post('/adduser', async (req, res) => {
}
});

app.get('/randomQuestion', async (req, res) => {
app.get('/questions', async (req, res) => {
try {
// Forward the question request to the question service
const questionResponse = await axios.get(questionServiceUrl+'/randomQuestion', req.body);
const questionResponse = await axios.get(questionServiceUrl+'/questions', req.body);
res.json(questionResponse.data);
} catch (error) {
res.status(error.response.status).json({ error: error.response.data.error });
Expand Down
52 changes: 52 additions & 0 deletions gatewayservice/gateway-service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,30 @@ describe('Gateway Service', () => {
}
});

axios.get.mockImplementation((url, data) => {
if (url.endsWith("/questions")) {
return Promise.resolve({
data: [
{
pregunta: "¿Cuál es la capital de Finlandia?",
respuestas: ["Ámsterdam", "Pretoria", "Lima", "Helsinki"],
correcta: "Helsinki"
}
],
});
} else if (url.endsWith("/questions?n=1&tematica=all")) {
return Promise.resolve({
data: [
{
pregunta: "¿Cuál es la capital de Finlandia?",
respuestas: ["Ámsterdam", "Pretoria", "Lima", "Helsinki"],
correcta: "Helsinki"
}
],
});
}
});

// Test /login endpoint
it('should forward login request to auth service', async () => {
const response = await request(app)
Expand All @@ -37,4 +61,32 @@ describe('Gateway Service', () => {
expect(response.statusCode).toBe(200);
expect(response.body.userId).toBe('mockedUserId');
});

// Prueba de la ruta /questions
it("should return a question", async () => {
const response = await request(app).get("/questions");

expect(response.statusCode).toBe(200);
expect(response.body).toEqual([
{
pregunta: "¿Cuál es la capital de Finlandia?",
respuestas: ["Ámsterdam", "Pretoria", "Lima", "Helsinki"],
correcta: "Helsinki",
},
]);
});

// Prueba de la ruta /questions?n=1&tematica=all
it("should return a question", async () => {
const response = await request(app).get("/questions?n=1&tematica=all");

expect(response.statusCode).toBe(200);
expect(response.body).toEqual([
{
pregunta: "¿Cuál es la capital de Finlandia?",
respuestas: ["Ámsterdam", "Pretoria", "Lima", "Helsinki"],
correcta: "Helsinki"
}
]);
});
});
1 change: 1 addition & 0 deletions questionservice/data/tematicas.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"¿Cuál es la esperanza de vida media de ",
"¿En qué fecha se fundó ",
"¿Cuál es la forma de gobierno de ",

"¿Cuál es el lema de "
]
},
Expand Down
Loading

0 comments on commit b71b5df

Please sign in to comment.