From ebef7518d886ff98404a1124932a97cb11db0541 Mon Sep 17 00:00:00 2001 From: notweezer123 Date: Tue, 5 Dec 2023 19:30:44 -0800 Subject: [PATCH] Added Tests to Feature 13 --- .../test/java/cse/gradle/Feature13Tests.java | 30 +++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/app/src/test/java/cse/gradle/Feature13Tests.java b/app/src/test/java/cse/gradle/Feature13Tests.java index e0709d2..d890ba4 100644 --- a/app/src/test/java/cse/gradle/Feature13Tests.java +++ b/app/src/test/java/cse/gradle/Feature13Tests.java @@ -21,19 +21,39 @@ class Feature13Tests extends HTTPServerTests{ /* --------------------------------- UNIT TESTS --------------------------------- */ @Test - void checkServerError() { + void checkLoginError() { Server.stopServer(); - // Check for login error Model model = new MockModel(); String response = model.performLoginRequest("test_user", "password"); String error = "Error: Server down"; assertEquals(error, response); + } + + @Test + void checkRecipeError() { + Server.stopServer(); - // Check for generic request error + Model model = new MockModel(); Recipe originalRecipe = new Recipe("potatoes", "boil the potatoes", "brunch", "boiled potatoes"); - response = model.postRecipe(originalRecipe); - error = "Error: Server down"; + String response = model.postRecipe(originalRecipe); + String error = "Error: Server down"; + assertEquals(error, response); + } + + /* --------------------------------- BDD TESTS --------------------------------- */ + @Test + void completeServerErrorTest() { + // login with test user + Model model = new MockModel(); + String retrievedUserId = model.performLoginRequest("test_user", "password"); + assertEquals(MockModel.mockUserId, retrievedUserId); + + // cut connection and ask for recipe + Server.stopServer(); + Recipe originalRecipe = new Recipe("potatoes", "boil the potatoes", "brunch", "boiled potatoes"); + String response = model.postRecipe(originalRecipe); + String error = "Error: Server down"; assertEquals(error, response); } }