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

Mejorado coverage en wikiquery, creo #98

Merged
merged 1 commit into from
Apr 29, 2024
Merged
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
49 changes: 49 additions & 0 deletions questionservice/wikiUtils/wikiQuery.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ describe("WikiQuery", () => {
beforeEach(() => {
// Limpiar mocks antes de cada test
jest.clearAllMocks();
Question.mockImplementation(({ question, answers, questionCategory }) => ({
question,
answers,
questionCategory
}));
});

it("debería obtener preguntas de Wikidata y formatearlas correctamente", async () => {
Expand Down Expand Up @@ -54,4 +59,48 @@ describe("WikiQuery", () => {
expect(questions).toHaveLength(mockResults.length);

});
it("debería reemplazar respuestas con formato URL y manejar respuestas repetidas usando respuestas de resguardo", async () => {
const mockResults = [
{ questionLabel: { value: "¿Cuál es el río más largo?" }, answerLabel: { value: "http://amazon.com" } },
{ questionLabel: { value: "¿Cuál es el río más largo?1" }, answerLabel: { value: "http://nile.com" } },
{ questionLabel: { value: "¿Cuál es el río más largo?2" }, answerLabel: { value: "Nilo" } },
{ questionLabel: { value: "¿Cuál es el río más largo?3" }, answerLabel: { value: "Nilo" } } // respuesta repetida
];

// Mock para las respuestas de resguardo
const mockBackupAnswers = [
{ itemLabel: { value: "Mississippi" } },
{ itemLabel: { value: "Yangtsé" } }
];

wikiCall.mockImplementation(query => {
if (query.includes("LIMIT 100")) {
return Promise.resolve(mockBackupAnswers);
} else {
return Promise.resolve(mockResults);
}
});

const template = {
questionVariable: "?q",
answerVariable: "?a",
question: "¿Cuál es el río más largo de __x__?",
year: false,
questionCategory: "Geografía"
};
const limitValue = 4;

const questions = await WikiQuery.getQuestions(template, limitValue, mockBackupAnswers);

// Verificar que las respuestas URL son reemplazadas por 'No hay'
expect(questions[0].answers.some(ans => ans.answer === "No hay")).toBe(true);
expect(questions[1].answers.some(ans => ans.answer === "No hay")).toBe(true);

// Verificar que las respuestas repetidas son reemplazadas por respuestas de resguardo
expect(questions.some(q => q.answers.some(ans => ans.answer === "Mississippi" || ans.answer === "Yangtsé"))).toBe(true);

// Verificar el llamado correcto a wikiCall
expect(wikiCall).toHaveBeenCalledTimes(1);
});

});