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

Removed console logs #156

Merged
merged 1 commit into from
Apr 28, 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
1 change: 0 additions & 1 deletion webapp/src/components/HistoricalData/HistoricalView.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export default function HistoricalView() {
var recordsArray = jsonRecords.games;
setRecords(recordsArray);
} catch (error) {
console.log(error);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ class CreationHistoricalRecord{
});

this.initRecord();
console.log('Registro enviado:', response.data);
} catch (error) {
console.error('Error al enviar el registro:', error.message);
}
}

Expand Down
1 change: 0 additions & 1 deletion webapp/src/components/questionView/QuestionGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class QuestionGenerator{
else{
response = await axios.get(this.apiUrl + '/' + lang + '/' +amount + '/' + type, {headers : {'token':token}});
}
console.log(response)
const receivedQuestions = await response.data;
let i = 0;
var questions = [];
Expand Down
69 changes: 69 additions & 0 deletions webapp/src/components/questionView/QuestionGenerator.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import QuestionGenerator from './QuestionGenerator';
import axios from 'axios';
import Question from './Question';

jest.mock('axios'); // Mockear axios para pruebas

describe('QuestionGenerator', () => {
let questionGenerator;

beforeEach(() => {
questionGenerator = new QuestionGenerator(); // Crear una nueva instancia antes de cada prueba
});

it('should generate questions with type "ALL"', async () => {
const token = 'mockedToken';
const lang = 'en';
const amount = 10;

// Simular respuesta exitosa de la API
axios.get.mockResolvedValue({
data: [{question: "What is the population of Oviedo?",
answers: ["225089","272357","267855","231841"]}],
});

const questions = await questionGenerator.generateQuestions(lang, 'ALL', amount, token);

// Verificar que axios.get fue llamado con la URL correcta
expect(axios.get).toHaveBeenCalledWith(
expect.stringMatching(/\/questions\/en\/10$/),
{ headers: { 'token': 'mockedToken' } }
);

// Verificar que se generaron las preguntas correctas
expect(questions.length).toBe(1);
expect(questions[0]).toBeInstanceOf(Question);
expect(questions[0].question).toBe("What is the population of Oviedo?");
});

it('should handle errors gracefully', async () => {
const token = 'mockedToken';
const lang = 'en';
const amount = 10;

// Simular una respuesta con error
axios.get.mockRejectedValue(new Error('API request failed'));

await expect(questionGenerator.generateQuestions(lang, 'ALL', amount, token)).rejects.toThrow('API request failed'); // Verificar que se lanza un error
});

it('should generate competitive questions', async () => {
const token = 'mockedToken';
const lang = 'en';

axios.get.mockResolvedValue({
data: [{question: "What is the population of Oviedo?",
answers: ["225089","272357","267855","231841"]}],
});

const questions = await questionGenerator.generateQuestions(lang, 'COMPETITIVE', 0, token);

expect(axios.get).toHaveBeenCalledWith(
expect.stringMatching(/\/questions\/en$/),
{ headers: { 'token': 'mockedToken' } }
);

expect(questions.length).toBe(1);
expect(questions[0].question).toBe("What is the population of Oviedo?");
});
});
3 changes: 0 additions & 3 deletions webapp/src/components/questionView/QuestionView.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ function QuestionView({type= "COMPETITIVE", amount=5}){
points=0;
setnumQuestion(0);
} catch (error) {
//Como hacer que funcione esto
console.log(error);
}

}
Expand Down Expand Up @@ -165,7 +163,6 @@ function QuestionComponent({questions, numQuestion, handleClick, t, points, lan
window.speechSynthesis.speak(speech);
})
.catch(error => {
console.error("Error al obtener las voces para el idioma:", error);
});
}, [getVoicesForLanguage, language]);

Expand Down
2 changes: 0 additions & 2 deletions webapp/src/components/ranking/RankingView.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const RankingView = () => {
var myrank = await retriever.getUser(cookie.username, cookie.token);
setMyRankingData(myrank);
} catch (error) {
console.log(error);
}
}
const handleSearch = async (e) => {
Expand All @@ -34,7 +33,6 @@ const RankingView = () => {
const rank = await retriever.getUser(searchTerm, cookie.token);
setMyRankingData(rank);
} catch (error) {
console.log(error);
}
}

Expand Down
Loading