Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generación de preguntas v2 #2 #39

Merged
merged 7 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading