Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Franko-bugs-fixed #116

Merged
merged 28 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
168f05a
Update readme.md
SkulderLock Jul 26, 2023
c9aebaf
Update readme.md
SkulderLock Jul 26, 2023
c966947
Update readme.md
SkulderLock Jul 26, 2023
78dcf4d
Update readme.md
SkulderLock Jul 31, 2023
b3db753
Update readme.md
SkulderLock Jul 31, 2023
d265299
Update readme.md
SkulderLock Jul 31, 2023
033c1ae
Update readme.md
SkulderLock Jul 31, 2023
f0c0b52
Update readme.md
SkulderLock Jul 31, 2023
13d80a5
Merge pull request #104 from COS301-SE-2023/development
SkulderLock Aug 1, 2023
831d3b8
🚑 hotfix
SkulderLock Aug 1, 2023
ac1bd70
tests
Krygsmancode Aug 28, 2023
5dafb01
fixing bugs
Krygsmancode Aug 28, 2023
f6af6de
more bug fixes
Krygsmancode Aug 28, 2023
4a85bed
fixed preferences bug
Krygsmancode Aug 29, 2023
c2ef165
fixed buget range bug
Krygsmancode Aug 29, 2023
d8b6a3f
fixed so many bugs
Krygsmancode Aug 30, 2023
dd07ad4
added quality of life for settings
Krygsmancode Aug 30, 2023
dbdfa7e
reset logic for cancel
Krygsmancode Aug 31, 2023
b884f17
fixed cancel logic
Krygsmancode Aug 31, 2023
4d95f2d
i broke it
Krygsmancode Aug 31, 2023
4514caa
broke more fixes
Krygsmancode Aug 31, 2023
7f5c833
added disabled confirm fuctionality
Krygsmancode Sep 2, 2023
26dcd39
final frontend bug fixes
Krygsmancode Sep 2, 2023
a874c31
fiexed final bugs for Settings page
Krygsmancode Sep 3, 2023
93a6517
fixed the shopping interval bug
Krygsmancode Sep 4, 2023
8fd0732
fixed preferences bugs
Krygsmancode Sep 5, 2023
41aacf9
final-final bug fixing
Krygsmancode Sep 5, 2023
024b909
small scss change for profile
Krygsmancode Sep 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public DaysMealsModel(MealModel breakfast, MealModel lunch, MealModel dinner, Da
this.mealDate = mealDate;
this.user = user;
this.userDateIdentifier = (user.getEmail() + mealDate.toString());
this.meal = "";
}

public MealModel getBreakfast() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class MealModel {
private String name;

@NotBlank(message = "An image is required")
private String image;
private String image = "https://images.unsplash.com/photo-1498837167922-ddd27525d352?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1170&q=80";

@NotBlank(message = "A Description is required")
private String description;
Expand All @@ -32,7 +32,7 @@ public MealModel(String name, String instructions,String description, String ima
this.name = name;
this.instructions = instructions;
this.description = description;
this.image = image;
this.image = "https://images.unsplash.com/photo-1498837167922-ddd27525d352?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1170&q=80";
this.ingredients = ingredients;
this.cookingTime = cookingTime;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,16 @@ public class OpenaiApiService {
private OpenaiPromptBuilder pBuilder = new OpenaiPromptBuilder();

public String fetchMealResponse(String Type) throws JsonMappingException, JsonProcessingException {
// String jsonResponse = getJSONResponse(Type);
// JsonNode jsonNode = jsonMapper.readTree(jsonResponse);
String jsonResponse = getJSONResponse(Type);
JsonNode jsonNode = jsonMapper.readTree(jsonResponse);

// String text = jsonNode.get("choices").get(0).get("text").asText();
// text = text.replace("\\\"", "\"");
// text = text.replace("\n", "");
// text = text.replace("/r/n", "\\r\\n");
// return text;
String text = jsonNode.get("choices").get(0).get("text").asText();
text = text.replace("\\\"", "\"");
text = text.replace("\n", "");
text = text.replace("/r/n", "\\r\\n");
return text;

return "{\"instructions\":\"1. Preheat oven to 375 degrees/r/n2. Grease a baking dish with butter/r/n3. Beat together the eggs, milk, and a pinch of salt/r/n4. Place the bread slices in the baking dish and pour the egg mixture over them/r/n5. Bake in the preheated oven for 25 minutes/r/n6. Serve warm with your favorite toppings\",\"name\":\"Baked French Toast\",\"description\":\"a delicious breakfast dish of egg-soaked bread\",\"ingredients\":\"6 slices of bread/r/n3 eggs/r/n3/4 cup of milk/r/nSalt/r/nButter\",\"cookingTime\":\"30 minutes\"}";
// return "{\"instructions\":\"1. Preheat oven to 375 degrees/r/n2. Grease a baking dish with butter/r/n3. Beat together the eggs, milk, and a pinch of salt/r/n4. Place the bread slices in the baking dish and pour the egg mixture over them/r/n5. Bake in the preheated oven for 25 minutes/r/n6. Serve warm with your favorite toppings\",\"name\":\"Baked French Toast\",\"description\":\"a delicious breakfast dish of egg-soaked bread\",\"ingredients\":\"6 slices of bread/r/n3 eggs/r/n3/4 cup of milk/r/nSalt/r/nButter\",\"cookingTime\":\"30 minutes\"}";
}

public String fetchMealResponse(String Type, String extendedPrompt)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package fellowship.mealmaestro.controllers;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.when;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.ResponseEntity;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import fellowship.mealmaestro.models.SettingsModel;
import fellowship.mealmaestro.services.SettingsService;

@SpringBootTest


public class SettingsControllerTest {

@InjectMocks
SettingsController settingsController;

@Mock
SettingsService settingsService;

@BeforeEach
public void setup() {
MockitoAnnotations.initMocks(this);
MockHttpServletRequest request = new MockHttpServletRequest();
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request));
}

@Test
public void testGetSettings() {
when(settingsService.getSettings("validToken")).thenReturn(new SettingsModel());

ResponseEntity<SettingsModel> responseEntity = settingsController.getSettings("Bearer validToken");

assertEquals(200, responseEntity.getStatusCodeValue());
}

@Test
public void testUpdateSettings() {
SettingsModel settings = new SettingsModel();
settings.setUserHeight(180);
settings.setUserWeight(75);

ResponseEntity<Void> responseEntity = settingsController.updateSettings(settings, "Bearer validToken");

assertEquals(200, responseEntity.getStatusCodeValue());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package fellowship.mealmaestro.models;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;


@SpringBootTest

public class SettingsModelTest {

SettingsModel settingsModel;

@BeforeEach
public void setup() {
settingsModel = new SettingsModel();
}

@Test
public void testSetGoal() {
settingsModel.setGoal("Lose Weight");
assertEquals("Lose Weight", settingsModel.getGoal());
}

@Test
public void testSetShoppingInterval() {
settingsModel.setShoppingInterval("Weekly");
assertEquals("Weekly", settingsModel.getShoppingInterval());
}

@Test
public void testSetFoodPreferences() {
settingsModel.setFoodPreferences(Arrays.asList("Vegetarian"));
assertEquals(Arrays.asList("Vegetarian"), settingsModel.getFoodPreferences());
}

@Test
public void testSetCalorieAmount() {
settingsModel.setCalorieAmount(2000);
assertEquals(2000, settingsModel.getCalorieAmount());
}

@Test
public void testSetBudgetRange() {
settingsModel.setBudgetRange("Low");
assertEquals("Low", settingsModel.getBudgetRange());
}

@Test
public void testSetMacroRatio() {
Map<String, Integer> macroRatio = new HashMap<>();
macroRatio.put("protein", 40);
macroRatio.put("carbs", 40);
macroRatio.put("fat", 20);
settingsModel.setMacroRatio(macroRatio);
assertEquals(macroRatio, settingsModel.getMacroRatio());
}

@Test
public void testSetAllergies() {
settingsModel.setAllergies(Arrays.asList("Peanuts"));
assertEquals(Arrays.asList("Peanuts"), settingsModel.getAllergies());
}

@Test
public void testSetCookingTime() {
settingsModel.setCookingTime("30 minutes");
assertEquals("30 minutes", settingsModel.getCookingTime());
}

@Test
public void testSetUserHeight() {
settingsModel.setUserHeight(180);
assertEquals(180, settingsModel.getUserHeight());
}

@Test
public void testSetUserWeight() {
settingsModel.setUserWeight(70);
assertEquals(70, settingsModel.getUserWeight());
}

@Test
public void testSetUserBMI() {
settingsModel.setUserBMI(22);
assertEquals(22, settingsModel.getUserBMI());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package fellowship.mealmaestro.services;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.springframework.boot.test.context.SpringBootTest;

import fellowship.mealmaestro.models.SettingsModel;
import fellowship.mealmaestro.repositories.SettingsRepository;
import fellowship.mealmaestro.services.auth.JwtService;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

@SpringBootTest

public class SettingsServiceTest {

@InjectMocks
SettingsService settingsService;

@Mock
JwtService jwtService;

@Mock
SettingsRepository settingsRepository;

@BeforeEach
public void setup() {
MockitoAnnotations.initMocks(this);
}

@Test
public void testGetSettings() {
SettingsModel settingsModel = new SettingsModel();
settingsModel.setGoal("Lose Weight");
settingsModel.setShoppingInterval("Weekly");
settingsModel.setFoodPreferences(Arrays.asList("Vegetarian"));
settingsModel.setCalorieAmount(2000);
settingsModel.setBudgetRange("Low");
Map<String, Integer> macroRatio = new HashMap<>();
macroRatio.put("protein", 40);
macroRatio.put("carbs", 40);
macroRatio.put("fat", 20);
settingsModel.setMacroRatio(macroRatio);
settingsModel.setAllergies(Arrays.asList("Peanuts"));
settingsModel.setCookingTime("30 minutes");
settingsModel.setUserHeight(180);
settingsModel.setUserWeight(70);
settingsModel.setUserBMI(22);

when(jwtService.extractUserEmail("validToken")).thenReturn("test@example.com");
when(settingsRepository.getSettings("test@example.com")).thenReturn(settingsModel);

SettingsModel result = settingsService.getSettings("validToken");

assertEquals(settingsModel, result);
}

@Test
public void testUpdateSettings() {
SettingsModel settingsModel = new SettingsModel();
settingsModel.setGoal("Gain Weight");
settingsModel.setShoppingInterval("Monthly");
settingsModel.setFoodPreferences(Arrays.asList("Vegan"));
settingsModel.setCalorieAmount(3000);
settingsModel.setBudgetRange("High");
Map<String, Integer> macroRatio = new HashMap<>();
macroRatio.put("protein", 30);
macroRatio.put("carbs", 50);
macroRatio.put("fat", 20);
settingsModel.setMacroRatio(macroRatio);
settingsModel.setAllergies(Arrays.asList("Dairy"));
settingsModel.setCookingTime("45 minutes");
settingsModel.setUserHeight(175);
settingsModel.setUserWeight(75);
settingsModel.setUserBMI(24);

when(jwtService.extractUserEmail("validToken")).thenReturn("test@example.com");

settingsService.updateSettings(settingsModel, "validToken");

verify(settingsRepository).updateSettings(settingsModel, "test@example.com");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package fellowship.repositories;

public class SettingsRepositoryTest {

}
4 changes: 2 additions & 2 deletions frontend/src/app/models/userpreference.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ export interface UserPreferencesI {
goal: string;
shoppingInterval: string;
foodPreferences: string[];
calorieAmount: number;
calorieAmount: number | string;
budgetRange: string;
macroRatio: {protein: number, carbs: number, fat: number};
allergies: string[];
cookingTime: string;
userHeight: number; //consider moving to account
userWeight: number; //consider moving to account
userBMI: number;
userBMI: number | string;

bmiset : boolean;
cookingTimeSet : boolean;
Expand Down
Loading
Loading