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

Mejora coverage de nuevo codigo en wikiquery #96

Closed
wants to merge 2 commits into from
Closed
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
33 changes: 31 additions & 2 deletions questionservice/wikiUtils/wikiQuery.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ describe("WikiQuery", () => {
{ questionLabel: { value: "¿Cuál es la capital de Francia?1" }, answerLabel: { value: "París1" } },
{ questionLabel: { value: "¿Cuál es la capital de Francia?2" }, answerLabel: { value: "París2" } },
{ questionLabel: { value: "¿Cuál es la capital de Francia?3" }, answerLabel: { value: "París3" } }
// Agrega más elementos según necesites para tu prueba
];

// Configurar wikiCall para retornar datos simulados
Expand Down Expand Up @@ -53,6 +52,36 @@ describe("WikiQuery", () => {

// Verifica que la cantidad de preguntas y sus formatos sean los esperados
expect(questions).toHaveLength(mockResults.length);


});

it("debería obtener preguntas correctamente si la plantilla tiene year:true", async () => {
const mockResults = [
{ questionLabel: { value: "¿Cuándo terminó la guerra test1?" }, answerLabel: { value: "http1900" } },
{ questionLabel: { value: "¿Cuándo terminó la guerra test2?" }, answerLabel: { value: "1901" } },
{ questionLabel: { value: "¿Cuándo terminó la guerra test3?" }, answerLabel: { value: "1901" } },
{ questionLabel: { value: "¿Cuándo terminó la guerra test4?" }, answerLabel: { value: "1903" } }
];
wikiCall.mockResolvedValue(mockResults);
const template = {
questionVariable: "?q",
answerVariable: "?a",
question: "¿Cuándo terminó la guerra __x__?",
questionCategory: "Historia",
year: true
};
const limitValue = 5;
const backupAnswers = [{itemLabel: "gato"}, {itemLabel: "gato2"}]
await WikiQuery.getQuestions(template, limitValue, backupAnswers);
expect(wikiCall).toHaveBeenCalledWith(expect.stringMatching(/SELECT DISTINCT\s+\?questionLabel\s+\(YEAR\(\?answer\) AS \?answerLabel\)\s+WHERE/gm));

});

it('should return a list of 100 objects with a property "itemLabel"', async () => {
const expectedResults = [{ itemLabel: 'Cat' }, { itemLabel: 'Dog' }, /* más resultados aquí */];
wikiCall.mockResolvedValue(expectedResults);
const results = await WikiQuery.getBackupAnswers();
expect(wikiCall).toHaveBeenCalledTimes(1);
expect(results).toEqual(expectedResults);
});
});