-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'Tests' of https://github.com/ucsd-cse110-fa23/cse-110-p…
…roject-team-33 into Tests
- Loading branch information
Showing
3 changed files
with
58 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,15 +9,15 @@ | |
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import cse.gradle.Server.Server; | ||
|
||
public class Feature20Tests extends HTTPServerTests{ | ||
/* | ||
* --------------------------------- UNIT TESTS --------------------------------- | ||
*/ | ||
|
||
/* --------------------------------- UNIT TESTS --------------------------------- */ | ||
// Login to test user | ||
@Test | ||
public void testLoginEndpoint() { | ||
|
@@ -52,4 +52,57 @@ void completeServerErrorTest() { | |
assertEquals(error, response); | ||
} | ||
|
||
/* --------------------------------- BDD TESTS --------------------------------- */ | ||
@Test | ||
public void testLoginExistingRecipeList() { | ||
// Create a new List<Recipe> with 3 recipes | ||
List<Recipe> recipes = new ArrayList<Recipe>(); | ||
|
||
recipes.add(new Recipe("eggs, bacon", "cook for 10 minutes", "breakfast", "American breakfast")); | ||
recipes.add(new Recipe("salmon, salad", "cook for 20 minutes", "lunch", "Healthy Lunch")); | ||
recipes.add(new Recipe("potatoes", "boil the potatoes", "brunch", "boiled potatoes")); | ||
|
||
|
||
// Create a new Mock Model that accesses test_user in the database | ||
Model model = new MockModel(); | ||
|
||
// Log into test_user's account | ||
model.performLoginRequest("test_user", "password"); | ||
|
||
// Add the recipes to the database | ||
for (Recipe recipe : recipes) { | ||
model.postRecipe(recipe); | ||
} | ||
|
||
// Get all the recipes from the database sorted alphabetically A-Z (not case sensitive) | ||
String getAllResponse = model.getRecipeList("z-a", ""); | ||
|
||
// Delete the recipes from the database | ||
for (Recipe recipe : recipes) { | ||
model.deleteRecipe(recipe.getId().toString()); | ||
} | ||
|
||
// Parse the getAllResponse into a List<Recipe> | ||
List<Recipe> recipeArrayList = Recipe.parseRecipeListFromString(getAllResponse); | ||
|
||
System.out.println("recipeArrayList: " + recipeArrayList); | ||
|
||
// Check that the recieved recipes matches the test_user's list of recipes | ||
assertEquals(3, recipeArrayList.size()); | ||
Check failure on line 91 in app/src/test/java/cse/gradle/Feature20Tests.java GitHub Actions / JUnit Test ReportFeature20Tests.testLoginExistingRecipeList()
Raw output
|
||
assert(recipeArrayList.get(2).getName().equals("American breakfast")); | ||
// System.out.println(recipeArrayList.get(1).getName()); | ||
assert(recipeArrayList.get(1).getName().equals("boiled potatoes")); | ||
assert(recipeArrayList.get(0).getName().equals("Healthy Lunch")); | ||
} | ||
|
||
@Test | ||
public void testLoginIncorrectCredentials() { | ||
Model model = new MockModel(); | ||
|
||
// Attempt to log in with incorrect credentials | ||
String result = model.performLoginRequest("incorrect_user", "incorrect_password"); | ||
|
||
// Check that the result contains an error message | ||
assertEquals(true, result.contains("Error!")); | ||
Check failure on line 106 in app/src/test/java/cse/gradle/Feature20Tests.java GitHub Actions / JUnit Test ReportFeature20Tests.testLoginIncorrectCredentials()
Raw output
|
||
} | ||
} |