Skip to content

Commit

Permalink
Merge pull request #156 from Arquisoft/150-increase-code-coverage
Browse files Browse the repository at this point in the history
Removed console logs
  • Loading branch information
uo289267 authored Apr 28, 2024
2 parents 2de8ce9 + a1833d4 commit c0f4488
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 9 deletions.
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

0 comments on commit c0f4488

Please sign in to comment.