Skip to content

Commit

Permalink
Fix some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Pelayori committed Apr 1, 2024
1 parent 45eadc8 commit b4d14e1
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/main/java/com/uniovi/services/InsertSampleDataService.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ public InsertSampleDataService(PlayerService playerService, QuestionService ques
@Transactional
@EventListener(ApplicationReadyEvent.class) // Uncomment this line to insert sample data on startup
public void insertSampleQuestions() {
if (!playerService.getUserByEmail("[email protected]").isPresent()) {
PlayerDto player = new PlayerDto();
player.setEmail("[email protected]");
player.setUsername("test");
player.setPassword("test");
player.setRoles(new String[]{"ROLE_USER"});
playerService.generateApiKey(playerService.addNewPlayer(player));
}

if (Arrays.stream(environment.getActiveProfiles()).anyMatch(env -> (env.equalsIgnoreCase("test")))) {
log.info("Test profile active, skipping sample data insertion");
return;
Expand All @@ -60,14 +69,6 @@ public void insertSampleQuestions() {

@Transactional
public void generateSampleData() {
if (!playerService.getUserByEmail("[email protected]").isPresent()) {
PlayerDto player = new PlayerDto();
player.setEmail("[email protected]");
player.setUsername("test");
player.setPassword("test");
player.setRoles(new String[]{"ROLE_USER"});
playerService.generateApiKey(playerService.addNewPlayer(player));
}

questionRepository.deleteAll();

Expand Down

0 comments on commit b4d14e1

Please sign in to comment.