diff --git a/webapp/src/components/HistoricalData/HistoricalView.js b/webapp/src/components/HistoricalData/HistoricalView.js index 2a4d336..56caedc 100644 --- a/webapp/src/components/HistoricalData/HistoricalView.js +++ b/webapp/src/components/HistoricalData/HistoricalView.js @@ -20,7 +20,6 @@ export default function HistoricalView() { var recordsArray = jsonRecords.games; setRecords(recordsArray); } catch (error) { - console.log(error); } } diff --git a/webapp/src/components/questionView/CreationHistoricalRecord.js b/webapp/src/components/questionView/CreationHistoricalRecord.js index cac292c..0e52994 100644 --- a/webapp/src/components/questionView/CreationHistoricalRecord.js +++ b/webapp/src/components/questionView/CreationHistoricalRecord.js @@ -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); } } diff --git a/webapp/src/components/questionView/QuestionGenerator.js b/webapp/src/components/questionView/QuestionGenerator.js index 86e8aa3..442ed3b 100644 --- a/webapp/src/components/questionView/QuestionGenerator.js +++ b/webapp/src/components/questionView/QuestionGenerator.js @@ -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 = []; diff --git a/webapp/src/components/questionView/QuestionGenerator.test.js b/webapp/src/components/questionView/QuestionGenerator.test.js new file mode 100644 index 0000000..9764f98 --- /dev/null +++ b/webapp/src/components/questionView/QuestionGenerator.test.js @@ -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?"); + }); +}); diff --git a/webapp/src/components/questionView/QuestionView.js b/webapp/src/components/questionView/QuestionView.js index b6add26..6d8d7e8 100644 --- a/webapp/src/components/questionView/QuestionView.js +++ b/webapp/src/components/questionView/QuestionView.js @@ -30,8 +30,6 @@ function QuestionView({type= "COMPETITIVE", amount=5}){ points=0; setnumQuestion(0); } catch (error) { - //Como hacer que funcione esto - console.log(error); } } @@ -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]); diff --git a/webapp/src/components/ranking/RankingView.js b/webapp/src/components/ranking/RankingView.js index 60fd368..2794f64 100644 --- a/webapp/src/components/ranking/RankingView.js +++ b/webapp/src/components/ranking/RankingView.js @@ -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) => { @@ -34,7 +33,6 @@ const RankingView = () => { const rank = await retriever.getUser(searchTerm, cookie.token); setMyRankingData(rank); } catch (error) { - console.log(error); } }