test(recipe): cover null serves/cookTimeMin and capitalised effort rejection
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -161,6 +161,19 @@ class RecipeControllerTest {
|
|||||||
verify(recipeService).deleteRecipe(HOUSEHOLD_ID, RECIPE_ID);
|
verify(recipeService).deleteRecipe(HOUSEHOLD_ID, RECIPE_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void createRecipeWithCapitalisedEffortShouldReturn400() throws Exception {
|
||||||
|
var body = """
|
||||||
|
{"name":"Test","effort":"Easy","tagIds":["%s"],"ingredients":[{"quantity":1,"unit":"g","newIngredientName":"x","sortOrder":0}]}
|
||||||
|
""".formatted(UUID.randomUUID());
|
||||||
|
|
||||||
|
mockMvc.perform(post("/v1/recipes")
|
||||||
|
.principal(() -> "sarah@example.com")
|
||||||
|
.contentType(org.springframework.http.MediaType.APPLICATION_JSON)
|
||||||
|
.content(body))
|
||||||
|
.andExpect(status().isBadRequest());
|
||||||
|
}
|
||||||
|
|
||||||
private RecipeCreateRequest sampleCreateRequest() {
|
private RecipeCreateRequest sampleCreateRequest() {
|
||||||
var ingredientId = UUID.randomUUID();
|
var ingredientId = UUID.randomUUID();
|
||||||
return new RecipeCreateRequest(
|
return new RecipeCreateRequest(
|
||||||
|
|||||||
@@ -526,6 +526,29 @@ class RecipeServiceTest {
|
|||||||
.isInstanceOf(ResourceNotFoundException.class);
|
.isInstanceOf(ResourceNotFoundException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void createRecipeWithNullServesAndCookTimeShouldStoreZero() {
|
||||||
|
var household = testHousehold();
|
||||||
|
when(householdRepository.findById(HOUSEHOLD_ID)).thenReturn(Optional.of(household));
|
||||||
|
when(recipeRepository.save(any(Recipe.class))).thenAnswer(i -> {
|
||||||
|
Recipe r = i.getArgument(0);
|
||||||
|
try {
|
||||||
|
var field = Recipe.class.getDeclaredField("id");
|
||||||
|
field.setAccessible(true);
|
||||||
|
field.set(r, UUID.randomUUID());
|
||||||
|
} catch (Exception e) { throw new RuntimeException(e); }
|
||||||
|
return r;
|
||||||
|
});
|
||||||
|
|
||||||
|
var request = new RecipeCreateRequest("Soup", null, null, "easy", null,
|
||||||
|
List.of(), List.of(), List.of());
|
||||||
|
|
||||||
|
RecipeDetailResponse result = recipeService.createRecipe(HOUSEHOLD_ID, request);
|
||||||
|
|
||||||
|
assertThat(result.serves()).isEqualTo((short) 0);
|
||||||
|
assertThat(result.cookTimeMin()).isEqualTo((short) 0);
|
||||||
|
}
|
||||||
|
|
||||||
// ── Tag/Category edge cases ──
|
// ── Tag/Category edge cases ──
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user