);
}
\ No newline at end of file
From 8c35c31422a5803a1fd6b9be3554bc34285393cf Mon Sep 17 00:00:00 2001
From: sergiorodriguezgarcia
<113514397+sergiorodriguezgarcia@users.noreply.github.com>
Date: Sat, 6 Apr 2024 14:30:56 +0200
Subject: [PATCH 006/118] fix: Changin the setGame
---
webapp/src/pages/Game.jsx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/webapp/src/pages/Game.jsx b/webapp/src/pages/Game.jsx
index 14869aed..15c2d77f 100644
--- a/webapp/src/pages/Game.jsx
+++ b/webapp/src/pages/Game.jsx
@@ -37,9 +37,9 @@ export default function Game() {
try {
const newGameResponse = await newGame();
if (newGameResponse) {
- setGameId(newGameResponse.id);
setLoading(false);
await startRound(newGameResponse.id);
+ setGameId(newGameResponse.id);
startTimer();
} else {
navigate("/dashboard");
From 290dcaa4869123681fc637ef701c3a8abf7bb1a3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gonzalo=20Su=C3=A1rez=20Losada?=
Date: Sat, 6 Apr 2024 15:00:32 +0200
Subject: [PATCH 007/118] feat: added user stories for login acceptance tests
---
.../user_stories/login_user_stories.txt | 35 +++++++++++++++++++
1 file changed, 35 insertions(+)
create mode 100644 webapp/e2e/acceptance/user_stories/login_user_stories.txt
diff --git a/webapp/e2e/acceptance/user_stories/login_user_stories.txt b/webapp/e2e/acceptance/user_stories/login_user_stories.txt
new file mode 100644
index 00000000..cf23663e
--- /dev/null
+++ b/webapp/e2e/acceptance/user_stories/login_user_stories.txt
@@ -0,0 +1,35 @@
+User story:
+ As a registered user
+ I want to log in
+ so that I can play the game
+
+
+Case 1:
+ SCENARIO: a registered user wants to log in using his correct credentials
+ GIVEN: a registered user
+ WHEN: user enters the log in screen
+ user writes his credentials properly
+
+ THEN: user is able to log in successfully
+
+Case 2:
+ SCENARIO: a registered user wants to log in using his incorrect credentials
+ GIVEN: a registered user
+ WHEN: user enters the log in screen
+ user writes his credentials wrong
+
+ THEN: user is not able to log in
+
+
+User story:
+ As an unregistered user
+ I want to log in
+ so that I can play the game
+
+Case 1:
+ SCENARIO: a registered user wants to log in without using an account
+ GIVEN: a registered user
+ WHEN: user enters the log in screen
+ user leaves the credentials in blank
+
+ THEN: user is not able to log in
From b6dc1c042c30daccd22e41377a035aad7ec2e5db Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gonzalo=20Su=C3=A1rez=20Losada?=
Date: Sat, 6 Apr 2024 16:32:04 +0200
Subject: [PATCH 008/118] feat: added user stories for playing a game
acceptance tests
---
.../user_stories/playing_game_user.txt | 20 +++++++++++++++++++
1 file changed, 20 insertions(+)
create mode 100644 webapp/e2e/acceptance/user_stories/playing_game_user.txt
diff --git a/webapp/e2e/acceptance/user_stories/playing_game_user.txt b/webapp/e2e/acceptance/user_stories/playing_game_user.txt
new file mode 100644
index 00000000..b8636c93
--- /dev/null
+++ b/webapp/e2e/acceptance/user_stories/playing_game_user.txt
@@ -0,0 +1,20 @@
+User story:
+ As a logged user
+ I want to start a game
+ so that I can play the game
+
+SCENARIO: a logged user wants to play a new game
+GIVEN: a logged user
+WHEN: clicking the button to start a new game
+THEN: a new game is created and the first question appears on the screen
+
+
+User story:
+ As a non-registered user
+ I want to start a game
+ so that I can play the game
+
+SCENARIO: a non-registered user tries to access to a new game via URL
+GIVEN: a non-registered user
+WHEN: trying to create a new game via URL
+THEN: game is not created as there's no open session and user is redirected to log in screen
From df0719e91a2533ebafcdf8643e865cf032c9f5cc Mon Sep 17 00:00:00 2001
From: sergioqfeg1
Date: Sat, 6 Apr 2024 17:26:02 +0200
Subject: [PATCH 009/118] fix: create 2 validate
---
api/src/main/resources/application.properties | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/api/src/main/resources/application.properties b/api/src/main/resources/application.properties
index 8f7af9da..14b5bf17 100644
--- a/api/src/main/resources/application.properties
+++ b/api/src/main/resources/application.properties
@@ -1,6 +1,6 @@
JWT_EXPIRATION_MS=86400000
REFRESH_TOKEN_DURATION_MS=86400000
-spring.jpa.hibernate.ddl-auto=create
+spring.jpa.hibernate.ddl-auto=validate
spring.datasource.url=${DATABASE_URL}
spring.datasource.username=${DATABASE_USER}
spring.datasource.password=${DATABASE_PASSWORD}
From 601f71b9143a188fb4815a5f29a44c25cef2a280 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gonzalo=20Su=C3=A1rez=20Losada?=
Date: Sat, 6 Apr 2024 17:45:56 +0200
Subject: [PATCH 010/118] feat: added user stories for seeing statistics
acceptance tests
---
.../user_stories/seeing_stats_stories.txt | 22 +++++++++++++++++++
1 file changed, 22 insertions(+)
create mode 100644 webapp/e2e/acceptance/user_stories/seeing_stats_stories.txt
diff --git a/webapp/e2e/acceptance/user_stories/seeing_stats_stories.txt b/webapp/e2e/acceptance/user_stories/seeing_stats_stories.txt
new file mode 100644
index 00000000..e880b67a
--- /dev/null
+++ b/webapp/e2e/acceptance/user_stories/seeing_stats_stories.txt
@@ -0,0 +1,22 @@
+SCENARIO: a fresh new logged user wants to see its stats where
+GIVEN: a logged user which has no games yet
+WHEN: clicking the button for seeing the stats
+THEN:
+
+
+SCENARIO: a logged user with many games wants to see its stats
+GIVEN: a logged user with many games and a full ladder board (many other users with many other games)
+WHEN: clicking the button for seeing stats
+THEN: it successfully displays both, the ladder board and the logged user statistics
+
+
+User story:
+ As a non-logged user
+ I want to see the statistics
+ so that I know the current global ranking
+
+SCENARIO: a non-logged user wants to access the global ranking
+GIVEN: a logged user
+WHEN: clicking the button for seeing stats
+THEN: he cannot see it as the web redirects it to the log in screen.
+
From e89cb695c5688f219540d84d37828f99f5ab57ef Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gonzalo=20Su=C3=A1rez=20Losada?=
Date: Sat, 6 Apr 2024 17:46:52 +0200
Subject: [PATCH 011/118] feat: added user stories for registering acceptance
tests
---
.../user_stories/register_user_stories.txt | 34 +++++++++++++++++++
1 file changed, 34 insertions(+)
create mode 100644 webapp/e2e/acceptance/user_stories/register_user_stories.txt
diff --git a/webapp/e2e/acceptance/user_stories/register_user_stories.txt b/webapp/e2e/acceptance/user_stories/register_user_stories.txt
new file mode 100644
index 00000000..0247fe51
--- /dev/null
+++ b/webapp/e2e/acceptance/user_stories/register_user_stories.txt
@@ -0,0 +1,34 @@
+User story:
+ As an unregistered user
+ I want to register
+ so that I can play the game
+
+Case 1:
+ SCENARIO: a new user registers into the game successfully
+ GIVEN: an unregistered user
+ WHEN: user enters the login screen
+ user types his information properly
+ THEN: a new user is created
+
+
+Case 2:
+ SCENARIO: a new user tries to register leaving a blank field
+ GIVEN: an unregistered user
+ WHEN: user enters the login screen
+ user types leaves the username field blank, fills all the other fields properly
+ THEN: the user is unable to create a new account
+
+Case 3:
+ SCENARIO: a new user tries to register having a wrong email format
+ GIVEN: an unregistered user
+ WHEN: user enters the login screen
+ user types sets an incorrect formatted email, fills all the other fields properly
+ THEN: the user is unable to create a new account
+
+
+Case 4:
+ SCENARIO: a new user tries to register placing a username already in use
+ GIVEN: an unregistered user
+ WHEN: user enters the login screen
+ user types sets a username which is already in use, fills all the other fields properly
+ THEN: the user is unable to create a new account
From 88dcd12cac5ae8ef623039bd7704432f935ec345 Mon Sep 17 00:00:00 2001
From: sergioqfeg1
Date: Sat, 6 Apr 2024 18:35:41 +0200
Subject: [PATCH 012/118] fix: statistics tests
---
.../quizapi/statistics/StatisticsService.java | 3 +-
.../statistics/StatisticsServiceTest.java | 33 ++++++++++++++++---
2 files changed, 30 insertions(+), 6 deletions(-)
diff --git a/api/src/main/java/lab/en2b/quizapi/statistics/StatisticsService.java b/api/src/main/java/lab/en2b/quizapi/statistics/StatisticsService.java
index 0f0ec3f6..49110478 100644
--- a/api/src/main/java/lab/en2b/quizapi/statistics/StatisticsService.java
+++ b/api/src/main/java/lab/en2b/quizapi/statistics/StatisticsService.java
@@ -7,6 +7,7 @@
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Service;
+import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
@@ -25,7 +26,7 @@ public StatisticsResponseDto getStatisticsForUser(Authentication authentication)
}
public List getTopTenStatistics(){
- List all = statisticsRepository.findAll();
+ List all = new ArrayList<>(statisticsRepository.findAll());
all.sort(Comparator.comparing(Statistics::getCorrectRate).reversed());
List topTen = all.stream().limit(10).collect(Collectors.toList());
return topTen.stream().map(statisticsResponseDtoMapper).collect(Collectors.toList());
diff --git a/api/src/test/java/lab/en2b/quizapi/statistics/StatisticsServiceTest.java b/api/src/test/java/lab/en2b/quizapi/statistics/StatisticsServiceTest.java
index 9a91a629..4d60c11b 100644
--- a/api/src/test/java/lab/en2b/quizapi/statistics/StatisticsServiceTest.java
+++ b/api/src/test/java/lab/en2b/quizapi/statistics/StatisticsServiceTest.java
@@ -118,14 +118,37 @@ public void getStatisticsForUserTest(){
Assertions.assertEquals(defaultStatisticsResponseDto1, result);
}
- /*@Test
+ @Test
public void getTopTenStatisticsTestWhenThereAreNotTen(){
when(statisticsRepository.findAll()).thenReturn(List.of(defaultStatistics2, defaultStatistics1));
- when(statisticsResponseDtoMapper.apply(any())).thenReturn(defaultStatisticsResponseDto1);
- when(statisticsResponseDtoMapper.apply(any())).thenReturn(defaultStatisticsResponseDto2);
- when(statisticsResponseDtoMapper.apply(any())).thenReturn(defaultStatisticsResponseDto1);
+ when(statisticsResponseDtoMapper.apply(defaultStatistics1)).thenReturn(defaultStatisticsResponseDto1);
+ when(statisticsResponseDtoMapper.apply(defaultStatistics2)).thenReturn(defaultStatisticsResponseDto2);
List result = statisticsService.getTopTenStatistics();
Assertions.assertEquals(List.of(defaultStatisticsResponseDto2,defaultStatisticsResponseDto1), result);
- }*/
+ }
+
+ @Test
+ public void getTopTenStatisticsTestWhenThereAreNotTenAndAreEqual(){
+ Statistics defaultStatistics3 = Statistics.builder()
+ .id(2L)
+ .user(defaultUser)
+ .correct(5L)
+ .wrong(5L)
+ .total(10L)
+ .build();
+ StatisticsResponseDto defaultStatisticsResponseDto3 = StatisticsResponseDto.builder()
+ .id(2L)
+ .right(5L)
+ .wrong(5L)
+ .total(10L)
+ .correctRate(50L)
+ .user(defaultUserResponseDto)
+ .build();
+ when(statisticsRepository.findAll()).thenReturn(List.of(defaultStatistics1, defaultStatistics3));
+ when(statisticsResponseDtoMapper.apply(defaultStatistics1)).thenReturn(defaultStatisticsResponseDto1);
+ when(statisticsResponseDtoMapper.apply(defaultStatistics3)).thenReturn(defaultStatisticsResponseDto3);
+ List result = statisticsService.getTopTenStatistics();
+ Assertions.assertEquals(List.of(defaultStatisticsResponseDto1,defaultStatisticsResponseDto3), result);
+ }
}
From f3dd08f90a55468bab81cf1e1af53ac2173ab12e Mon Sep 17 00:00:00 2001
From: sergioqfeg1
Date: Sat, 6 Apr 2024 18:56:21 +0200
Subject: [PATCH 013/118] feat: findRandomQuestion for GameService
---
.../en2b/quizapi/questions/question/QuestionService.java | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/api/src/main/java/lab/en2b/quizapi/questions/question/QuestionService.java b/api/src/main/java/lab/en2b/quizapi/questions/question/QuestionService.java
index 5710f7dc..498e5c8e 100644
--- a/api/src/main/java/lab/en2b/quizapi/questions/question/QuestionService.java
+++ b/api/src/main/java/lab/en2b/quizapi/questions/question/QuestionService.java
@@ -43,6 +43,15 @@ public QuestionResponseDto getRandomQuestion(String lang) {
return questionResponseDtoMapper.apply(q);
}
+
+ public Question findRandomQuestion(String lang){
+ if (lang==null || lang.isBlank()) {
+ lang = "en";
+ }
+ Question q = questionRepository.findRandomQuestion(lang);
+ loadAnswers(q);
+ return q;
+ }
public QuestionResponseDto getQuestionById(Long id) {
return questionResponseDtoMapper.apply(questionRepository.findById(id).orElseThrow());
From 9497ef618d41fa3c0292fbe2e6b86c6b22e4e452 Mon Sep 17 00:00:00 2001
From: sergioqfeg1
Date: Sat, 6 Apr 2024 18:57:05 +0200
Subject: [PATCH 014/118] fix: nextRound adds answers to the question
---
api/src/main/java/lab/en2b/quizapi/game/GameService.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/api/src/main/java/lab/en2b/quizapi/game/GameService.java b/api/src/main/java/lab/en2b/quizapi/game/GameService.java
index 447b3995..c0307d67 100644
--- a/api/src/main/java/lab/en2b/quizapi/game/GameService.java
+++ b/api/src/main/java/lab/en2b/quizapi/game/GameService.java
@@ -45,7 +45,7 @@ public GameResponseDto newGame(Authentication authentication) {
public GameResponseDto startRound(Long id, Authentication authentication) {
Game game = gameRepository.findByIdForUser(id, userService.getUserByAuthentication(authentication).getId()).orElseThrow();
- game.newRound(questionRepository.findRandomQuestion(game.getLanguage()));
+ game.newRound(questionService.findRandomQuestion(game.getLanguage()));
if (game.isGameOver()){
Statistics statistics = Statistics.builder()
.user(game.getUser())
From 60bb06521d520bf70781b6e3671f9a6e985f100f Mon Sep 17 00:00:00 2001
From: sergioqfeg1
Date: Sat, 6 Apr 2024 18:57:55 +0200
Subject: [PATCH 015/118] fix: errors in game tests
---
.../en2b/quizapi/game/GameServiceTest.java | 22 +++++++++----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/api/src/test/java/lab/en2b/quizapi/game/GameServiceTest.java b/api/src/test/java/lab/en2b/quizapi/game/GameServiceTest.java
index d42ef727..97deeffb 100644
--- a/api/src/test/java/lab/en2b/quizapi/game/GameServiceTest.java
+++ b/api/src/test/java/lab/en2b/quizapi/game/GameServiceTest.java
@@ -164,7 +164,7 @@ public void newGame(){
public void startRound(){
when(gameRepository.findByIdForUser(any(), any())).thenReturn(Optional.of(defaultGame));
when(gameRepository.save(any())).thenAnswer(invocation -> invocation.getArgument(0));
- when(questionRepository.findRandomQuestion(any())).thenReturn(defaultQuestion);
+ when(questionService.findRandomQuestion(any())).thenReturn(defaultQuestion);
when(userService.getUserByAuthentication(authentication)).thenReturn(defaultUser);
GameResponseDto gameDto = gameService.startRound(1L, authentication);
GameResponseDto result = defaultGameResponseDto;
@@ -177,7 +177,7 @@ public void startRound(){
@Test
public void startRoundGameOver(){
when(gameRepository.findByIdForUser(any(), any())).thenReturn(Optional.of(defaultGame));
- when(questionRepository.findRandomQuestion(any())).thenReturn(defaultQuestion);
+ when(questionService.findRandomQuestion(any())).thenReturn(defaultQuestion);
when(userService.getUserByAuthentication(authentication)).thenReturn(defaultUser);
defaultGame.setActualRound(10);
assertThrows(IllegalStateException.class, () -> gameService.startRound(1L,authentication));
@@ -187,7 +187,7 @@ public void startRoundGameOver(){
public void startRoundWhenRoundNotFinished(){
when(gameRepository.findByIdForUser(any(), any())).thenReturn(Optional.of(defaultGame));
when(gameRepository.save(any())).thenAnswer(invocation -> invocation.getArgument(0));
- when(questionRepository.findRandomQuestion(any())).thenReturn(defaultQuestion);
+ when(questionService.findRandomQuestion(any())).thenReturn(defaultQuestion);
when(userService.getUserByAuthentication(authentication)).thenReturn(defaultUser);
gameService.startRound(1L,authentication);
assertThrows(IllegalStateException.class, () -> gameService.startRound(1L,authentication));
@@ -197,7 +197,7 @@ public void startRoundWhenRoundNotFinished(){
public void getCurrentQuestion() {
when(gameRepository.findByIdForUser(any(), any())).thenReturn(Optional.of(defaultGame));
when(gameRepository.save(any())).thenAnswer(invocation -> invocation.getArgument(0));
- when(questionRepository.findRandomQuestion(any())).thenReturn(defaultQuestion);
+ when(questionService.findRandomQuestion(any())).thenReturn(defaultQuestion);
when(userService.getUserByAuthentication(authentication)).thenReturn(defaultUser);
gameService.startRound(1L,authentication);
QuestionResponseDto questionDto = gameService.getCurrentQuestion(1L,authentication);
@@ -215,7 +215,7 @@ public void getCurrentQuestionRoundNotStarted() {
public void getCurrentQuestionRoundFinished() {
when(gameRepository.findByIdForUser(any(), any())).thenReturn(Optional.of(defaultGame));
when(gameRepository.save(any())).thenAnswer(invocation -> invocation.getArgument(0));
- when(questionRepository.findRandomQuestion(any())).thenReturn(defaultQuestion);
+ when(questionService.findRandomQuestion(any())).thenReturn(defaultQuestion);
when(userService.getUserByAuthentication(authentication)).thenReturn(defaultUser);
gameService.startRound(1L,authentication);
defaultGame.setRoundStartTime(LocalDateTime.now().minusSeconds(100));
@@ -227,7 +227,7 @@ public void getCurrentQuestionGameFinished() {
when(gameRepository.findByIdForUser(any(), any())).thenReturn(Optional.of(defaultGame));
when(userService.getUserByAuthentication(authentication)).thenReturn(defaultUser);
when(gameRepository.save(any())).thenAnswer(invocation -> invocation.getArgument(0));
- when(questionRepository.findRandomQuestion(any())).thenReturn(defaultQuestion);
+ when(questionService.findRandomQuestion(any())).thenReturn(defaultQuestion);
gameService.startRound(1L,authentication);
defaultGame.setActualRound(10);
assertThrows(IllegalStateException.class, () -> gameService.getCurrentQuestion(1L,authentication));
@@ -238,7 +238,7 @@ public void answerQuestionCorrectly(){
when(gameRepository.findByIdForUser(any(), any())).thenReturn(Optional.of(defaultGame));
when(gameRepository.save(any())).thenAnswer(invocation -> invocation.getArgument(0));
when(userService.getUserByAuthentication(authentication)).thenReturn(defaultUser);
- when(questionRepository.findRandomQuestion(any())).thenReturn(defaultQuestion);
+ when(questionService.findRandomQuestion(any())).thenReturn(defaultQuestion);
gameService.newGame(authentication);
gameService.startRound(1L, authentication);
gameService.answerQuestion(1L, new GameAnswerDto(1L), authentication);
@@ -252,7 +252,7 @@ public void answerQuestionIncorrectly(){
when(gameRepository.findByIdForUser(any(), any())).thenReturn(Optional.of(defaultGame));
when(gameRepository.save(any())).thenAnswer(invocation -> invocation.getArgument(0));
when(userService.getUserByAuthentication(authentication)).thenReturn(defaultUser);
- when(questionRepository.findRandomQuestion(any())).thenReturn(defaultQuestion);
+ when(questionService.findRandomQuestion(any())).thenReturn(defaultQuestion);
gameService.newGame(authentication);
gameService.startRound(1L, authentication);
gameService.answerQuestion(1L, new GameAnswerDto(2L), authentication);
@@ -266,7 +266,7 @@ public void answerQuestionWhenGameHasFinished(){
when(gameRepository.findByIdForUser(any(), any())).thenReturn(Optional.of(defaultGame));
when(gameRepository.save(any())).thenAnswer(invocation -> invocation.getArgument(0));
when(userService.getUserByAuthentication(authentication)).thenReturn(defaultUser);
- when(questionRepository.findRandomQuestion(any())).thenReturn(defaultQuestion);
+ when(questionService.findRandomQuestion(any())).thenReturn(defaultQuestion);
gameService.newGame(authentication);
gameService.startRound(1L, authentication);
defaultGame.setActualRound(30);
@@ -278,7 +278,7 @@ public void answerQuestionWhenRoundHasFinished(){
when(gameRepository.findByIdForUser(any(), any())).thenReturn(Optional.of(defaultGame));
when(gameRepository.save(any())).thenAnswer(invocation -> invocation.getArgument(0));
when(userService.getUserByAuthentication(authentication)).thenReturn(defaultUser);
- when(questionRepository.findRandomQuestion(any())).thenReturn(defaultQuestion);
+ when(questionService.findRandomQuestion(any())).thenReturn(defaultQuestion);
gameService.newGame(authentication);
gameService.startRound(1L, authentication);
defaultGame.setRoundStartTime(LocalDateTime.now().minusSeconds(100));
@@ -290,7 +290,7 @@ public void answerQuestionInvalidId(){
when(gameRepository.findByIdForUser(any(), any())).thenReturn(Optional.of(defaultGame));
when(gameRepository.save(any())).thenAnswer(invocation -> invocation.getArgument(0));
when(userService.getUserByAuthentication(authentication)).thenReturn(defaultUser);
- when(questionRepository.findRandomQuestion(any())).thenReturn(defaultQuestion);
+ when(questionService.findRandomQuestion(any())).thenReturn(defaultQuestion);
gameService.newGame(authentication);
gameService.startRound(1L, authentication);
assertThrows(IllegalArgumentException.class, () -> gameService.answerQuestion(1L, new GameAnswerDto(3L), authentication));
From a689f329bed70880a81881d7d0892aca19f57e97 Mon Sep 17 00:00:00 2001
From: jjgancfer
Date: Sat, 6 Apr 2024 19:02:42 +0200
Subject: [PATCH 016/118] fix: map deploy port to 80:3000
---
docker-compose.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docker-compose.yml b/docker-compose.yml
index 902d8f0c..3e8e23bf 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -65,7 +65,7 @@ services:
environment:
- REACT_APP_API_ENDPOINT=${API_URI}
ports:
- - "3000:3000"
+ - "80:3000"
prometheus:
image: prom/prometheus
From e527ca21ba832355ec9953c7e739392ba9360303 Mon Sep 17 00:00:00 2001
From: jjgancfer
Date: Sat, 6 Apr 2024 19:04:42 +0200
Subject: [PATCH 017/118] fix: map correct url to deploy
---
webapp/src/components/LateralMenu.jsx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/webapp/src/components/LateralMenu.jsx b/webapp/src/components/LateralMenu.jsx
index e3a0a075..c9066075 100644
--- a/webapp/src/components/LateralMenu.jsx
+++ b/webapp/src/components/LateralMenu.jsx
@@ -25,7 +25,7 @@ const LateralMenu = ({ isOpen, onClose, changeLanguage, isDashboard }) => {
};
const handleApiClick = () => {
- window.open("http://localhost:8080/swagger/swagger-ui/index.html#/auth-controller/registerUser", "_blank", "noopener");
+ window.open(`http://${process.env.REACT_APP_API_ENDPOINT}/swagger/swagger-ui/index.html#/auth-controller/registerUser`, "_blank", "noopener");
};
const handleLogout = async () => {
From d6209310bfc58f3ac3809367340b00f507ff6410 Mon Sep 17 00:00:00 2001
From: Gonzalo Alonso Fernandez
Date: Sat, 6 Apr 2024 19:05:51 +0200
Subject: [PATCH 018/118] feat: changing the game.
---
webapp/src/pages/Game.jsx | 34 +++++++++++++++++++++-------------
1 file changed, 21 insertions(+), 13 deletions(-)
diff --git a/webapp/src/pages/Game.jsx b/webapp/src/pages/Game.jsx
index 15c2d77f..b0282b7f 100644
--- a/webapp/src/pages/Game.jsx
+++ b/webapp/src/pages/Game.jsx
@@ -4,7 +4,6 @@ import { Center } from "@chakra-ui/layout";
import { useNavigate } from "react-router-dom";
import { useTranslation } from "react-i18next";
import Confetti from "react-confetti";
-import ButtonEf from '../components/ButtonEf';
import { newGame, startRound, getCurrentQuestion, answerQuestion } from '../components/game/Game';
import axios from "axios";
import LateralMenu from '../components/LateralMenu';
@@ -74,24 +73,24 @@ export default function Game() {
}
}, [gameId, generateQuestion]);
- const answerButtonClick = (option) => {
- setAnswer(question.answers[option-1]);
- setSelectedOption((prevOption) => (prevOption === option ? null : option));
- const anyOptionSelected = option === selectedOption ? null : option;
- setNextDisabled(anyOptionSelected === null);
- };
+ const answerButtonClick = (optionIndex) => {
+ const selectedOptionIndex = selectedOption === optionIndex ? null : optionIndex;
+ setSelectedOption(selectedOptionIndex);
+ const anyOptionSelected = selectedOptionIndex !== null;
+ setNextDisabled(!anyOptionSelected);
+ };
- const nextButtonClick = async () => {
+ const nextButtonClick = useCallback(async () => {
try {
const isCorrect = (await answerQuestion(gameId, answer.id)).wasCorrect;
-
+
if (isCorrect) {
setCorrectAnswers((prevCorrectAnswers) => prevCorrectAnswers + 1);
setShowConfetti(true);
}
-
+
setSelectedOption(null);
-
+
const nextRoundNumber = roundNumber + 1;
if (nextRoundNumber > 9)
navigate("/dashboard/game/results", { state: { correctAnswers: correctAnswers + (isCorrect ? 1 : 0) } });
@@ -104,7 +103,7 @@ export default function Game() {
console.error("Error processing next question:", error);
navigate("/dashboard");
}
- };
+ }, [gameId, answer.id, roundNumber, correctAnswers, generateQuestion, navigate]);
useEffect(() => {
let timeout;
@@ -158,7 +157,16 @@ export default function Game() {
{question.answers.map((answer, index) => (
- answerButtonClick(index + 1)} />
+
))}
From 6beac8866c7853a27f303342695764ace2c4626c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gonzalo=20Su=C3=A1rez=20Losada?=
Date: Sat, 6 Apr 2024 19:15:46 +0200
Subject: [PATCH 019/118] feat: added feature for cucumber acceptance
---
webapp/e2e/features/playing-game.feature | 7 +++++++
1 file changed, 7 insertions(+)
create mode 100644 webapp/e2e/features/playing-game.feature
diff --git a/webapp/e2e/features/playing-game.feature b/webapp/e2e/features/playing-game.feature
new file mode 100644
index 00000000..d7d2da11
--- /dev/null
+++ b/webapp/e2e/features/playing-game.feature
@@ -0,0 +1,7 @@
+Feature: Starting a new game
+
+Scenario: A logged user wants to play a new game
+ Given A logged user
+ When Clicking the button to start a new game
+ Then A new game is created and the first question appears on the screen
+
From 5173295e36eb4953f57f58ae87b3f51d13e7e9b5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gonzalo=20Su=C3=A1rez=20Losada?=
Date: Sat, 6 Apr 2024 19:32:55 +0200
Subject: [PATCH 020/118] feat: added feature for cucumber acceptance
---
webapp/e2e/features/login.features | 7 +++++++
1 file changed, 7 insertions(+)
create mode 100644 webapp/e2e/features/login.features
diff --git a/webapp/e2e/features/login.features b/webapp/e2e/features/login.features
new file mode 100644
index 00000000..482b23db
--- /dev/null
+++ b/webapp/e2e/features/login.features
@@ -0,0 +1,7 @@
+Feature: Creating an account
+
+Scenario: A registered user wants to log in using his correct credentials
+ Given A registered user
+ When User enters the log in screen
+ And User writes his credentials properly
+ Then User is able to log in successfully
From fe3e1f90883c1c8878ac00e8224f0aff44f91c47 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gonzalo=20Su=C3=A1rez=20Losada?=
Date: Sat, 6 Apr 2024 19:34:36 +0200
Subject: [PATCH 021/118] feat: added feature for cucumber acceptance
---
webapp/e2e/features/seeing-stats.feature | 5 +++++
1 file changed, 5 insertions(+)
create mode 100644 webapp/e2e/features/seeing-stats.feature
diff --git a/webapp/e2e/features/seeing-stats.feature b/webapp/e2e/features/seeing-stats.feature
new file mode 100644
index 00000000..1e85c965
--- /dev/null
+++ b/webapp/e2e/features/seeing-stats.feature
@@ -0,0 +1,5 @@
+Feature: Seeing the ladder board
+Scenario: A logged user with many games wants to see its stats
+ Given A logged user with many games and a full ladder board (many other users with many other games)
+ When Clicking the button for seeing stats
+ Then it successfully displays both, the ladder board and the logged user statistics
\ No newline at end of file
From 9227e5024c89fc61f16ab817f9a407aa66f78a5f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gonzalo=20Su=C3=A1rez=20Losada?=
Date: Sat, 6 Apr 2024 19:36:05 +0200
Subject: [PATCH 022/118] feat: added feature for cucumber acceptance
---
webapp/e2e/features/register-form.feature | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/webapp/e2e/features/register-form.feature b/webapp/e2e/features/register-form.feature
index aad790a5..6917adf4 100644
--- a/webapp/e2e/features/register-form.feature
+++ b/webapp/e2e/features/register-form.feature
@@ -3,4 +3,4 @@ Feature: Registering a new user
Scenario: The user is not registered in the site
Given An unregistered user
When I fill the data in the form and press submit
- Then A confirmation message should be shown in the screen
\ No newline at end of file
+ Then The main menu screen is shown and the new user is created
\ No newline at end of file
From 7d6226fa14bcf0293a81ccfbcf6bdd0cc3e19c32 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gonzalo=20Su=C3=A1rez=20Losada?=
Date: Sat, 6 Apr 2024 19:36:25 +0200
Subject: [PATCH 023/118] fix: corrected Then feature for cucumber acceptance
---
webapp/e2e/features/login.features | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/webapp/e2e/features/login.features b/webapp/e2e/features/login.features
index 482b23db..721fe32c 100644
--- a/webapp/e2e/features/login.features
+++ b/webapp/e2e/features/login.features
@@ -4,4 +4,4 @@ Scenario: A registered user wants to log in using his correct credentials
Given A registered user
When User enters the log in screen
And User writes his credentials properly
- Then User is able to log in successfully
+ Then The main menu screen shows on the user device
From dc728b2f486fd528d33ff6e978951835ca7b858f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gonzalo=20Su=C3=A1rez=20Losada?=
Date: Sat, 6 Apr 2024 19:41:56 +0200
Subject: [PATCH 024/118] fix: corrected When feature for cucumber acceptance
---
webapp/e2e/features/login.features | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/webapp/e2e/features/login.features b/webapp/e2e/features/login.features
index 721fe32c..f85cac7f 100644
--- a/webapp/e2e/features/login.features
+++ b/webapp/e2e/features/login.features
@@ -1,7 +1,9 @@
Feature: Creating an account
Scenario: A registered user wants to log in using his correct credentials
- Given A registered user
- When User enters the log in screen
- And User writes his credentials properly
+ Given A registered user in the root screen
+ When User presses the log in button
+ And User enters in the log in screen
+ And User fills the form with his credentials properly
+ And User presses the log in button
Then The main menu screen shows on the user device
From 41580e4cd9a4f87dd1ade5d0b2c7812cbc7fe206 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gonzalo=20Su=C3=A1rez=20Losada?=
Date: Sat, 6 Apr 2024 19:42:06 +0200
Subject: [PATCH 025/118] fix: corrected When feature for cucumber acceptance
---
webapp/e2e/features/seeing-stats.feature | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/webapp/e2e/features/seeing-stats.feature b/webapp/e2e/features/seeing-stats.feature
index 1e85c965..7e2bec22 100644
--- a/webapp/e2e/features/seeing-stats.feature
+++ b/webapp/e2e/features/seeing-stats.feature
@@ -1,5 +1,8 @@
Feature: Seeing the ladder board
+
Scenario: A logged user with many games wants to see its stats
- Given A logged user with many games and a full ladder board (many other users with many other games)
- When Clicking the button for seeing stats
+ Given A logged user in the main menu with many games
+ And A full ladder board (many other users with many other games)
+ When The user presses the button for deploying the lateral menu
+ And the user presses the button for seeing stats
Then it successfully displays both, the ladder board and the logged user statistics
\ No newline at end of file
From 31108ef9333739678b98fd0a1ecfa733f1a794cb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gonzalo=20Su=C3=A1rez=20Losada?=
Date: Sat, 6 Apr 2024 19:42:20 +0200
Subject: [PATCH 026/118] fix: corrected Then feature for cucumber acceptance
---
webapp/e2e/features/playing-game.feature | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/webapp/e2e/features/playing-game.feature b/webapp/e2e/features/playing-game.feature
index d7d2da11..1f4ae9ee 100644
--- a/webapp/e2e/features/playing-game.feature
+++ b/webapp/e2e/features/playing-game.feature
@@ -1,7 +1,7 @@
Feature: Starting a new game
Scenario: A logged user wants to play a new game
- Given A logged user
+ Given A logged user in the main menu
When Clicking the button to start a new game
Then A new game is created and the first question appears on the screen
From 0852984e3bd7c58c8a3e2ee34322efad2c719dc3 Mon Sep 17 00:00:00 2001
From: Dario
Date: Sat, 6 Apr 2024 20:14:02 +0200
Subject: [PATCH 027/118] fix: removed category and language from question
---
.../java/lab/en2b/quizapi/questions/question/Question.java | 3 ---
api/src/main/resources/application.properties | 2 +-
2 files changed, 1 insertion(+), 4 deletions(-)
diff --git a/api/src/main/java/lab/en2b/quizapi/questions/question/Question.java b/api/src/main/java/lab/en2b/quizapi/questions/question/Question.java
index 8ff15be0..17234423 100644
--- a/api/src/main/java/lab/en2b/quizapi/questions/question/Question.java
+++ b/api/src/main/java/lab/en2b/quizapi/questions/question/Question.java
@@ -39,9 +39,6 @@ public class Question {
@Enumerated(EnumType.STRING)
@Column(name = "question_category")
private QuestionCategory questionCategory;
- @Column(name = "answer_category")
- private AnswerCategory answerCategory;
- private String language;
@Enumerated(EnumType.STRING)
private QuestionType type;
diff --git a/api/src/main/resources/application.properties b/api/src/main/resources/application.properties
index 14b5bf17..c5fffc71 100644
--- a/api/src/main/resources/application.properties
+++ b/api/src/main/resources/application.properties
@@ -1,6 +1,6 @@
JWT_EXPIRATION_MS=86400000
REFRESH_TOKEN_DURATION_MS=86400000
-spring.jpa.hibernate.ddl-auto=validate
+spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=${DATABASE_URL}
spring.datasource.username=${DATABASE_USER}
spring.datasource.password=${DATABASE_PASSWORD}
From de190f9f60c867536ee882ee813b39566083f6e8 Mon Sep 17 00:00:00 2001
From: Dario
Date: Sat, 6 Apr 2024 20:22:27 +0200
Subject: [PATCH 028/118] fix: removed attributes from tests
---
api/src/test/java/lab/en2b/quizapi/game/GameServiceTest.java | 2 --
1 file changed, 2 deletions(-)
diff --git a/api/src/test/java/lab/en2b/quizapi/game/GameServiceTest.java b/api/src/test/java/lab/en2b/quizapi/game/GameServiceTest.java
index 97deeffb..b71bb584 100644
--- a/api/src/test/java/lab/en2b/quizapi/game/GameServiceTest.java
+++ b/api/src/test/java/lab/en2b/quizapi/game/GameServiceTest.java
@@ -88,9 +88,7 @@ void setUp() {
.id(1L)
.content("What is the capital of France?")
.answers(new ArrayList<>())
- .language("en")
.questionCategory(QuestionCategory.GEOGRAPHY)
- .answerCategory(AnswerCategory.CAPITAL_CITY)
.type(QuestionType.TEXT)
.build();
From 37a1620665a1666b8906c9867318405480d56113 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gonzalo=20Su=C3=A1rez=20Losada?=
Date: Sat, 6 Apr 2024 20:39:00 +0200
Subject: [PATCH 029/118] fix: reorganized structure for login feature
(acceptance tests)
---
.../{login.features => login_features/positive_login.features} | 0
1 file changed, 0 insertions(+), 0 deletions(-)
rename webapp/e2e/features/{login.features => login_features/positive_login.features} (100%)
diff --git a/webapp/e2e/features/login.features b/webapp/e2e/features/login_features/positive_login.features
similarity index 100%
rename from webapp/e2e/features/login.features
rename to webapp/e2e/features/login_features/positive_login.features
From 13ade404ce5eec4d45dc6cc9d9c61db2aa256088 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gonzalo=20Su=C3=A1rez=20Losada?=
Date: Sat, 6 Apr 2024 20:58:56 +0200
Subject: [PATCH 030/118] feat: added feature for blank email login (acceptance
tests)
---
.../login_features/negative_blank_email_login.features | 9 +++++++++
1 file changed, 9 insertions(+)
create mode 100644 webapp/e2e/features/login_features/negative_blank_email_login.features
diff --git a/webapp/e2e/features/login_features/negative_blank_email_login.features b/webapp/e2e/features/login_features/negative_blank_email_login.features
new file mode 100644
index 00000000..83795c21
--- /dev/null
+++ b/webapp/e2e/features/login_features/negative_blank_email_login.features
@@ -0,0 +1,9 @@
+Feature: Preventing wrong login accesses
+
+Scenario: A registered user wants to log in using his credentials but leaving the password in blank
+ Given A registered user in the root screen
+ When User presses the log in button
+ And User enters in the log in screen
+ And User fills the form with his proper email but leaves the password in blank
+ And User presses the log in button
+ Then Log in screen shows an informative error message and does not allow the user to log in
\ No newline at end of file
From 1474009e9124b3c2ac7d878f7e2e8c6188b9dd36 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gonzalo=20Su=C3=A1rez=20Losada?=
Date: Sat, 6 Apr 2024 20:59:54 +0200
Subject: [PATCH 031/118] feat: added feature for blank password login
(acceptance tests)
---
.../negative_blank_password_login.features | 9 +++++++++
1 file changed, 9 insertions(+)
create mode 100644 webapp/e2e/features/login_features/negative_blank_password_login.features
diff --git a/webapp/e2e/features/login_features/negative_blank_password_login.features b/webapp/e2e/features/login_features/negative_blank_password_login.features
new file mode 100644
index 00000000..2239ea5f
--- /dev/null
+++ b/webapp/e2e/features/login_features/negative_blank_password_login.features
@@ -0,0 +1,9 @@
+Feature: Preventing wrong login accesses
+
+Scenario: A registered user wants to log in using his credentials but leaving the email in blank
+ Given A registered user in the root screen
+ When User presses the log in button
+ And User enters in the log in screen
+ And User fills the form with his proper password but leaves the email in blank
+ And User presses the log in button
+ Then Log in screen shows an informative error message and does not allow the user to log in
\ No newline at end of file
From c007141472e98dec42658ef35188bace7a44d5c2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gonzalo=20Su=C3=A1rez=20Losada?=
Date: Sat, 6 Apr 2024 21:03:16 +0200
Subject: [PATCH 032/118] feat: added feature for blank email login (acceptance
tests)
---
.../negative_incorrect_credentials.feature | 9 +++++++++
1 file changed, 9 insertions(+)
create mode 100644 webapp/e2e/features/login_features/negative_incorrect_credentials.feature
diff --git a/webapp/e2e/features/login_features/negative_incorrect_credentials.feature b/webapp/e2e/features/login_features/negative_incorrect_credentials.feature
new file mode 100644
index 00000000..662052c5
--- /dev/null
+++ b/webapp/e2e/features/login_features/negative_incorrect_credentials.feature
@@ -0,0 +1,9 @@
+Feature: Preventing wrong login accesses
+
+ Scenario: A registered user wants to log in using his credentials but leaving the email in blank
+ Given A registered user in the root screen
+ When User presses the log in button
+ And User enters in the log in screen
+ And User fills the form with his proper password but leaves the email in blank
+ And User presses the log in button
+ Then Log in screen shows an informative error message and does not allow the user to log in
\ No newline at end of file
From d9d1691f87a43e7c172cf51e838912f546a96078 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gonzalo=20Su=C3=A1rez=20Losada?=
Date: Sat, 6 Apr 2024 21:07:11 +0200
Subject: [PATCH 033/118] fix: solved typo in login features (acceptance tests)
---
...nk_email_login.features => negative_blank_email_login.feature} | 0
...sword_login.features => negative_blank_password_login.feature} | 0
.../{positive_login.features => positive_login.feature} | 0
3 files changed, 0 insertions(+), 0 deletions(-)
rename webapp/e2e/features/login_features/{negative_blank_email_login.features => negative_blank_email_login.feature} (100%)
rename webapp/e2e/features/login_features/{negative_blank_password_login.features => negative_blank_password_login.feature} (100%)
rename webapp/e2e/features/login_features/{positive_login.features => positive_login.feature} (100%)
diff --git a/webapp/e2e/features/login_features/negative_blank_email_login.features b/webapp/e2e/features/login_features/negative_blank_email_login.feature
similarity index 100%
rename from webapp/e2e/features/login_features/negative_blank_email_login.features
rename to webapp/e2e/features/login_features/negative_blank_email_login.feature
diff --git a/webapp/e2e/features/login_features/negative_blank_password_login.features b/webapp/e2e/features/login_features/negative_blank_password_login.feature
similarity index 100%
rename from webapp/e2e/features/login_features/negative_blank_password_login.features
rename to webapp/e2e/features/login_features/negative_blank_password_login.feature
diff --git a/webapp/e2e/features/login_features/positive_login.features b/webapp/e2e/features/login_features/positive_login.feature
similarity index 100%
rename from webapp/e2e/features/login_features/positive_login.features
rename to webapp/e2e/features/login_features/positive_login.feature
From 1ef3b1db5c942e4e3e8ef6e92fde1a731de7b0ab Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gonzalo=20Su=C3=A1rez=20Losada?=
Date: Sat, 6 Apr 2024 21:09:35 +0200
Subject: [PATCH 034/118] feat: added feature for bad email formatting in login
screen (acceptance tests)
---
.../negative_bad_format_email_login.feature | 9 +++++++++
1 file changed, 9 insertions(+)
create mode 100644 webapp/e2e/features/login_features/negative_bad_format_email_login.feature
diff --git a/webapp/e2e/features/login_features/negative_bad_format_email_login.feature b/webapp/e2e/features/login_features/negative_bad_format_email_login.feature
new file mode 100644
index 00000000..fde5ef2f
--- /dev/null
+++ b/webapp/e2e/features/login_features/negative_bad_format_email_login.feature
@@ -0,0 +1,9 @@
+Feature: Preventing wrong login accesses
+
+ Scenario: A registered user wants to log in using his credentials but with an invalid email
+ Given A registered user in the root screen
+ When User presses the log in button
+ And User enters in the log in screen
+ And User fills the form with his proper password but writes a wrong formatted email
+ And User presses the log in button
+ Then Log in screen shows an informative error message and does not allow the user to log in
\ No newline at end of file
From 2aebcfbe0caee935b4ce87e989ebd9b0241925a4 Mon Sep 17 00:00:00 2001
From: sergioqfeg1
Date: Sat, 6 Apr 2024 21:10:40 +0200
Subject: [PATCH 035/118] fix: new round conditions
---
api/src/main/java/lab/en2b/quizapi/game/Game.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/api/src/main/java/lab/en2b/quizapi/game/Game.java b/api/src/main/java/lab/en2b/quizapi/game/Game.java
index 5028b9d7..cd928e0e 100644
--- a/api/src/main/java/lab/en2b/quizapi/game/Game.java
+++ b/api/src/main/java/lab/en2b/quizapi/game/Game.java
@@ -54,7 +54,7 @@ public void newRound(Question question){
if(getActualRound() != 0){
if (isGameOver())
throw new IllegalStateException("You can't start a round for a finished game!");
- if(!currentRoundIsOver())
+ if(!currentQuestionAnswered || roundTimeHasExpired())
throw new IllegalStateException("You can't start a new round when the current round is not over yet!");
}
From 94626aca56a0b37a2a5a25ba0f818187587198c0 Mon Sep 17 00:00:00 2001
From: Gonzalo Alonso Fernandez
Date: Sat, 6 Apr 2024 21:16:53 +0200
Subject: [PATCH 036/118] feat: changiong the game implementation.
---
api/src/main/resources/application.properties | 2 +-
webapp/src/pages/Game.jsx | 21 ++++++++++++-------
2 files changed, 14 insertions(+), 9 deletions(-)
diff --git a/api/src/main/resources/application.properties b/api/src/main/resources/application.properties
index c5fffc71..8f7af9da 100644
--- a/api/src/main/resources/application.properties
+++ b/api/src/main/resources/application.properties
@@ -1,6 +1,6 @@
JWT_EXPIRATION_MS=86400000
REFRESH_TOKEN_DURATION_MS=86400000
-spring.jpa.hibernate.ddl-auto=update
+spring.jpa.hibernate.ddl-auto=create
spring.datasource.url=${DATABASE_URL}
spring.datasource.username=${DATABASE_USER}
spring.datasource.password=${DATABASE_PASSWORD}
diff --git a/webapp/src/pages/Game.jsx b/webapp/src/pages/Game.jsx
index b0282b7f..aad355b4 100644
--- a/webapp/src/pages/Game.jsx
+++ b/webapp/src/pages/Game.jsx
@@ -15,7 +15,7 @@ export default function Game() {
const [loading, setLoading] = useState(true);
const [gameId, setGameId] = useState(null);
const [question, setQuestion] = useState(null);
- const [answer, setAnswer] = useState({id:1, text:"answer1", category:"category1" });
+ const [answer, setAnswer] = useState({});
const [selectedOption, setSelectedOption] = useState(null);
const [nextDisabled, setNextDisabled] = useState(true);
const [roundNumber, setRoundNumber] = useState(1);
@@ -69,16 +69,19 @@ export default function Game() {
useEffect(() => {
if (gameId !== null) {
+ setSelectedOption(null);
generateQuestion();
}
}, [gameId, generateQuestion]);
+
- const answerButtonClick = (optionIndex) => {
+ const answerButtonClick = (optionIndex, answer) => {
const selectedOptionIndex = selectedOption === optionIndex ? null : optionIndex;
setSelectedOption(selectedOptionIndex);
+ setAnswer(answer);
const anyOptionSelected = selectedOptionIndex !== null;
setNextDisabled(!anyOptionSelected);
- };
+ };
const nextButtonClick = useCallback(async () => {
try {
@@ -95,9 +98,11 @@ export default function Game() {
if (nextRoundNumber > 9)
navigate("/dashboard/game/results", { state: { correctAnswers: correctAnswers + (isCorrect ? 1 : 0) } });
else {
+ setAnswer({});
setRoundNumber(nextRoundNumber);
setNextDisabled(true);
await generateQuestion();
+ startRound(gameId);
}
} catch (error) {
console.error("Error processing next question:", error);
@@ -157,12 +162,12 @@ export default function Game() {
{question.answers.map((answer, index) => (
-