Skip to content

Commit

Permalink
Merge pull request #39 from Arquisoft/Generación-de-preguntasV2-#2
Browse files Browse the repository at this point in the history
Generación de preguntas v2 #2
  • Loading branch information
CANCI0 authored Mar 4, 2024
2 parents 40364c7 + a808bde commit 3ee43e8
Show file tree
Hide file tree
Showing 12 changed files with 14,187 additions and 21 deletions.
4 changes: 2 additions & 2 deletions gatewayservice/gateway-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,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 3ee43e8

Please sign in to comment.