EDIT::Finding bugs in tests and try to fix them
This commit is contained in:
@@ -13,8 +13,8 @@ public class AchievementService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
UserService userService;
|
UserService userService;
|
||||||
|
|
||||||
@Autowired
|
// @Autowired
|
||||||
UserRepository userRepository;
|
// UserRepository userRepository;
|
||||||
|
|
||||||
private Logger logger = LoggerFactory.getLogger(UserService.class);
|
private Logger logger = LoggerFactory.getLogger(UserService.class);
|
||||||
|
|
||||||
@@ -24,7 +24,8 @@ public class AchievementService {
|
|||||||
*/
|
*/
|
||||||
public void updateAchievements(User user) {
|
public void updateAchievements(User user) {
|
||||||
achieveGettingStarted(user);
|
achieveGettingStarted(user);
|
||||||
userRepository.save(user);
|
System.out.println("\n\nI GOT HERE \n\n");
|
||||||
|
// userRepository.save(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -32,9 +33,10 @@ public class AchievementService {
|
|||||||
* @param user user for whom achiev1 changes
|
* @param user user for whom achiev1 changes
|
||||||
*/
|
*/
|
||||||
public void achieveGettingStarted(User user) {
|
public void achieveGettingStarted(User user) {
|
||||||
|
// System.out.print("\n\nUSERNAME:" + userRepository.findByName(user.getName()) );
|
||||||
if (!user.getFootPrintInputs().equals(InputValidator.getDefaultValues())) {
|
if (!user.getFootPrintInputs().equals(InputValidator.getDefaultValues())) {
|
||||||
userService.setAchievement(user.getName(), "Starting off", true);
|
userService.setAchievement(user.getName(), "Starting off", true);
|
||||||
userRepository.save(user);
|
// userRepository.save(user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -114,8 +114,8 @@ public class UserService {
|
|||||||
if (InputValidator.isValidItem(inputName)
|
if (InputValidator.isValidItem(inputName)
|
||||||
&& InputValidator.isValidItemValue(inputName, value)) {
|
&& InputValidator.isValidItemValue(inputName, value)) {
|
||||||
user.getFootPrintInputs().put(inputName, value);
|
user.getFootPrintInputs().put(inputName, value);
|
||||||
userRepository.save(user);
|
|
||||||
achievementService.updateAchievements(user);
|
achievementService.updateAchievements(user);
|
||||||
|
userRepository.save(user);
|
||||||
} else {
|
} else {
|
||||||
throw new ApplicationException("Invalid input");
|
throw new ApplicationException("Invalid input");
|
||||||
}
|
}
|
||||||
@@ -242,16 +242,14 @@ public class UserService {
|
|||||||
User user = userRepository.findByName(name);
|
User user = userRepository.findByName(name);
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
throw new ApplicationException("User does not exist");
|
throw new ApplicationException("User does not exist");
|
||||||
} else {
|
|
||||||
if (AllAchievements.isValidAchievement(achievement)) {
|
|
||||||
Map<String, Boolean> temp = user.getAchievements();
|
|
||||||
temp.put(achievement, achieved);
|
|
||||||
user.setAchievements(temp);
|
|
||||||
userRepository.save(user);
|
|
||||||
} else {
|
|
||||||
throw new ApplicationException("Invalid achievement");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (!AllAchievements.isValidAchievement(achievement)) {
|
||||||
|
throw new ApplicationException("Invalid achievement");
|
||||||
|
}
|
||||||
|
Map<String, Boolean> temp = user.getAchievements();
|
||||||
|
temp.put(achievement, achieved);
|
||||||
|
user.setAchievements(temp);
|
||||||
|
userRepository.save(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import static org.mockito.Mockito.when;
|
|||||||
import greenify.server.InputValidator;
|
import greenify.server.InputValidator;
|
||||||
import greenify.server.data.model.User;
|
import greenify.server.data.model.User;
|
||||||
import greenify.server.data.repository.UserRepository;
|
import greenify.server.data.repository.UserRepository;
|
||||||
|
import jdk.internal.util.xml.impl.Input;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -54,7 +55,8 @@ public class AchievementServiceTest {
|
|||||||
public void updateAchievementsTest() {
|
public void updateAchievementsTest() {
|
||||||
User alex = userRepository.findByName("alex");
|
User alex = userRepository.findByName("alex");
|
||||||
userService.setInput("alex","input_footprint_shopping_food_otherfood", "9.9");
|
userService.setInput("alex","input_footprint_shopping_food_otherfood", "9.9");
|
||||||
achievementService.updateAchievements(alex);
|
// achievementService.updateAchievements(alex);
|
||||||
|
//Shouldn't even have to call updateAchievements, since it's called in setInput.
|
||||||
// userService.setAchievement(alex.getName(), "Starting off", true);
|
// userService.setAchievement(alex.getName(), "Starting off", true);
|
||||||
// ^should not be here, does not work otherwise and I don't know why
|
// ^should not be here, does not work otherwise and I don't know why
|
||||||
System.out.println("\n\n"+ alex.getAchievements() + "\n\n" + alex.getFootPrintInputs().equals(InputValidator.getDefaultValues()));
|
System.out.println("\n\n"+ alex.getAchievements() + "\n\n" + alex.getFootPrintInputs().equals(InputValidator.getDefaultValues()));
|
||||||
|
|||||||
Reference in New Issue
Block a user