Skip to content

Commit

Permalink
deberian de pasar ya los tests del dailygame
Browse files Browse the repository at this point in the history
  • Loading branch information
uo282189 committed Apr 25, 2024
1 parent d8029ab commit fc99847
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
27 changes: 14 additions & 13 deletions webapp/src/components/game/gameModes/DailyGameMode.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,20 @@ class DailyGameMode extends BasicGame{
this.volverAJugarCoockie();
}

async volverAJugarCoockie(){
async volverAJugarCoockie(){

// Obtener la fecha actual y establecer la hora a las 12 de la noche
let expiryDate = new Date();
expiryDate.setHours(24, 0, 0, 0);

// Almacenar la variable en localStorage con la fecha de caducidad
localStorage.setItem('lastDailyGame', JSON.stringify({
value: 'valor que quieras almacenar',
expiry: expiryDate.getTime(),
}));

console.log("localStorage" + localStorage.getItem('lastDailyGame'));

try {
console.log("entra en el try");
const volverJugarData = {
Expand All @@ -122,18 +135,6 @@ class DailyGameMode extends BasicGame{
} catch (error) {
console.error('Error enviando los datos de diaria del usuario:', error);
}

// Obtener la fecha actual y establecer la hora a las 12 de la noche
let expiryDate = new Date();
expiryDate.setHours(24, 0, 0, 0);

// Almacenar la variable en localStorage con la fecha de caducidad
localStorage.setItem('lastDailyGame', JSON.stringify({
value: 'valor que quieras almacenar',
expiry: expiryDate.getTime(),
}));

console.log("localStorage" + localStorage.getItem('lastDailyGame'));
}

fechaActual(){
Expand Down
10 changes: 5 additions & 5 deletions webapp/src/components/game/gameModes/DailyGameMode.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('DailyGameMode', () => {

const questions = await dailyGameMode.fetchQuestions();

expect(global.fetch).toHaveBeenCalledWith(`${dailyGameMode.apiEndpoint}/getQuestionDiaria`);
expect(global.fetch).toHaveBeenCalledWith(`${dailyGameMode.apiEndpoint}/getQuestionDiaria?idioma=${dailyGameMode.idioma}&fecha=${dailyGameMode.fechaAct}`);
expect(questions).toEqual(Object.values(mockData));
expect(dailyGameMode.isLoading).toBe(false);
});
Expand All @@ -58,7 +58,7 @@ describe('DailyGameMode', () => {

const questions = await dailyGameMode.fetchQuestions();

expect(global.fetch).toHaveBeenCalledWith(`${dailyGameMode.apiEndpoint}/getQuestionDiaria`);
expect(global.fetch).toHaveBeenCalledWith(`${dailyGameMode.apiEndpoint}/getQuestionDiaria?idioma=${dailyGameMode.idioma}&fecha=${dailyGameMode.fechaAct}`);
expect(questions).toEqual([]);
expect(console.error).toHaveBeenCalledWith('Error fetching question data:', mockError);
});
Expand Down Expand Up @@ -106,21 +106,21 @@ describe('DailyGameMode', () => {
dailyGameMode.incrementIncorrectas();

expect(dailyGameMode.incorrectas).toBe(1);
expect(localStorage.getItem('diaria')).toBeTruthy();
expect(localStorage.getItem('lastDailyGame')).toBeTruthy();
});

it('should increment correctas correctly', () => {
dailyGameMode.incrementCorrectas();

expect(dailyGameMode.correctas).toBe(1);
expect(dailyGameMode.enviarHistorialPorQueHasAcetado).toBe(true);
expect(localStorage.getItem('diaria')).toBeTruthy();
expect(localStorage.getItem('lastDailyGame')).toBeTruthy();
});

it('should set volverAJugarCoockie correctly', () => {
dailyGameMode.volverAJugarCoockie();

const diaria = JSON.parse(localStorage.getItem('diaria'));
const diaria = JSON.parse(localStorage.getItem('lastDailyGame'));

expect(diaria.value).toBe('valor que quieras almacenar');
expect(diaria.expiry).toBeGreaterThan(Date.now());
Expand Down

0 comments on commit fc99847

Please sign in to comment.