From be7f8cc05f1e26561772fb820c8c55937665acbf Mon Sep 17 00:00:00 2001 From: Cosmin <250523019+cosmiinn75@users.noreply.github.com> Date: Thu, 15 Oct 2026 16:11:59 +0300 Subject: [PATCH 1/2] fix: reject mentee registration with missing applications --- .../mentorship/MenteeRegistration.java | 4 +++- .../controller/MenteeControllerTest.java | 20 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/wcc/platform/domain/platform/mentorship/MenteeRegistration.java b/src/main/java/com/wcc/platform/domain/platform/mentorship/MenteeRegistration.java index 9e519e5c..05cc8f31 100644 --- a/src/main/java/com/wcc/platform/domain/platform/mentorship/MenteeRegistration.java +++ b/src/main/java/com/wcc/platform/domain/platform/mentorship/MenteeRegistration.java @@ -24,7 +24,9 @@ public record MenteeRegistration( example = "2026", description = "The year of the mentorship cycle") Year cycleYear, - @Size(min = 1, max = 5) List applications) { + @NotNull + @Size(min = 1, max = 5) + List applications) { /** Converts a list of {@code MenteeApplicationDto} to a list of {@code MenteeApplication}. */ public List toApplications( diff --git a/src/test/java/com/wcc/platform/controller/MenteeControllerTest.java b/src/test/java/com/wcc/platform/controller/MenteeControllerTest.java index b0fe4a87..203d34ce 100644 --- a/src/test/java/com/wcc/platform/controller/MenteeControllerTest.java +++ b/src/test/java/com/wcc/platform/controller/MenteeControllerTest.java @@ -5,6 +5,8 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.springframework.http.MediaType.APPLICATION_JSON; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; @@ -69,6 +71,24 @@ void shouldCreateMenteeAndReturnCreated() throws Exception { .andExpect(jsonPath("$.fullName", is("Mark"))); } + @Test + @DisplayName("Given missing applications, when creating mentee, then return 400 Bad Request") + void shouldReturn400WhenApplicationsAreMissing() throws Exception { + var currentYear = java.time.Year.now(); + + mockMvc + .perform( + MockMvcRequestBuilders.post(API_MENTEES) + .header(API_KEY_HEADER, API_KEY_VALUE) + .contentType(APPLICATION_JSON) + .content( + "{\"mentee\":{\"id\":2,\"fullName\":\"Mark\",\"email\":\"mark@test.com\",\"position\":\"Software Engineer\",\"slackDisplayName\":\"mark-slack\",\"country\":{\"countryCode\":\"US\",\"countryName\":\"USA\"},\"city\":\"New York\",\"companyName\":\"Tech Corp\",\"images\":[],\"network\":[],\"profileStatus\":\"ACTIVE\",\"bio\":\"Mentee bio\",\"skills\":{\"yearsExperience\":2,\"areas\":[{\"technicalArea\":\"BACKEND\",\"proficiencyLevel\":\"BEGINNER\"}],\"languages\":[{\"language\":\"JAVASCRIPT\",\"proficiencyLevel\":\"BEGINNER\"}],\"mentorshipFocus\":[\"GROW_BEGINNER_TO_MID\"]}},\"mentorshipType\":\"AD_HOC\",\"cycleYear\":\"" + + currentYear+ "\"}")) + .andExpect(status().isBadRequest()); + + verify(menteeService, never()).saveRegistration(any()); + } + @Test @DisplayName( "Given active mentees exist, when listing mentees, then return 200 OK with active only") From ac124c94ede8dbdd992b46d210e2688721935379 Mon Sep 17 00:00:00 2001 From: Cosmin <250523019+cosmiinn75@users.noreply.github.com> Date: Mon, 26 Oct 2026 13:26:44 +0200 Subject: [PATCH 2/2] test: address mentee registration review feedback --- .../controller/MenteeControllerTest.java | 50 +++++++++++++++---- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/src/test/java/com/wcc/platform/controller/MenteeControllerTest.java b/src/test/java/com/wcc/platform/controller/MenteeControllerTest.java index 203d34ce..b5893c54 100644 --- a/src/test/java/com/wcc/platform/controller/MenteeControllerTest.java +++ b/src/test/java/com/wcc/platform/controller/MenteeControllerTest.java @@ -13,13 +13,18 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; import com.wcc.platform.configuration.SecurityConfig; import com.wcc.platform.configuration.TestConfig; import com.wcc.platform.domain.exceptions.ContentNotFoundException; import com.wcc.platform.domain.platform.mentorship.ApplicationRejectRequest; +import com.wcc.platform.domain.platform.mentorship.MenteeApplicationDto; +import com.wcc.platform.domain.platform.mentorship.MenteeRegistration; +import com.wcc.platform.domain.platform.mentorship.MentorshipType; import com.wcc.platform.service.MenteeAdminService; import com.wcc.platform.service.MenteeService; import com.wcc.platform.service.MenteeWorkflowService; +import java.time.Year; import java.util.List; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -53,7 +58,14 @@ class MenteeControllerTest { @DisplayName("Given valid mentee registration, when creating mentee, then return 201 Created") void shouldCreateMenteeAndReturnCreated() throws Exception { var mockMentee = createMenteeTest(2L, "Mark", "mark@test.com"); - var currentYear = java.time.Year.now(); + var registration = + new MenteeRegistration( + mockMentee, + MentorshipType.AD_HOC, + Year.now(), + List.of( + new MenteeApplicationDto( + 1L, 1, null, "This mentor has skills I want to improve"))); when(menteeService.saveRegistration(any())).thenReturn(mockMentee); @@ -62,10 +74,7 @@ void shouldCreateMenteeAndReturnCreated() throws Exception { MockMvcRequestBuilders.post(API_MENTEES) .header(API_KEY_HEADER, API_KEY_VALUE) .contentType(APPLICATION_JSON) - .content( - "{\"mentee\":{\"id\":2,\"fullName\":\"Mark\",\"email\":\"mark@test.com\",\"position\":\"Software Engineer\",\"slackDisplayName\":\"mark-slack\",\"country\":{\"countryCode\":\"US\",\"countryName\":\"USA\"},\"city\":\"New York\",\"companyName\":\"Tech Corp\",\"images\":[],\"network\":[],\"profileStatus\":\"ACTIVE\",\"bio\":\"Mentee bio\",\"skills\":{\"yearsExperience\":2,\"areas\":[{\"technicalArea\":\"BACKEND\",\"proficiencyLevel\":\"BEGINNER\"}],\"languages\":[{\"language\":\"JAVASCRIPT\",\"proficiencyLevel\":\"BEGINNER\"}],\"mentorshipFocus\":[\"GROW_BEGINNER_TO_MID\"]}},\"mentorshipType\":\"AD_HOC\",\"cycleYear\":\"" - + currentYear - + "\",\"applications\":[{\"mentorId\":1,\"priorityOrder\":1,\"whyMentor\":\"This mentor has skills I want to improve\"}]}")) + .content(objectMapper.writeValueAsString(registration))) .andExpect(status().isCreated()) .andExpect(jsonPath("$.id", is(2))) .andExpect(jsonPath("$.fullName", is("Mark"))); @@ -74,16 +83,37 @@ void shouldCreateMenteeAndReturnCreated() throws Exception { @Test @DisplayName("Given missing applications, when creating mentee, then return 400 Bad Request") void shouldReturn400WhenApplicationsAreMissing() throws Exception { - var currentYear = java.time.Year.now(); + var mockMentee = createMenteeTest(2L, "Mark", "mark@test.com"); + var registration = new MenteeRegistration(mockMentee, MentorshipType.AD_HOC, Year.now(), null); + ObjectNode request = objectMapper.valueToTree(registration); + request.remove("applications"); mockMvc .perform( MockMvcRequestBuilders.post(API_MENTEES) .header(API_KEY_HEADER, API_KEY_VALUE) .contentType(APPLICATION_JSON) - .content( - "{\"mentee\":{\"id\":2,\"fullName\":\"Mark\",\"email\":\"mark@test.com\",\"position\":\"Software Engineer\",\"slackDisplayName\":\"mark-slack\",\"country\":{\"countryCode\":\"US\",\"countryName\":\"USA\"},\"city\":\"New York\",\"companyName\":\"Tech Corp\",\"images\":[],\"network\":[],\"profileStatus\":\"ACTIVE\",\"bio\":\"Mentee bio\",\"skills\":{\"yearsExperience\":2,\"areas\":[{\"technicalArea\":\"BACKEND\",\"proficiencyLevel\":\"BEGINNER\"}],\"languages\":[{\"language\":\"JAVASCRIPT\",\"proficiencyLevel\":\"BEGINNER\"}],\"mentorshipFocus\":[\"GROW_BEGINNER_TO_MID\"]}},\"mentorshipType\":\"AD_HOC\",\"cycleYear\":\"" - + currentYear+ "\"}")) + .content(objectMapper.writeValueAsString(request))) + .andExpect(status().isBadRequest()); + + verify(menteeService, never()).saveRegistration(any()); + } + + @Test + @DisplayName( + "Given null applications in registration, when creating mentee, then return 400 Bad Request") + void shouldReturn400WhenApplicationsIsNull() throws Exception { + var mockMentee = createMenteeTest(2L, "Mark", "mark@test.com"); + var registration = new MenteeRegistration(mockMentee, MentorshipType.AD_HOC, Year.now(), null); + ObjectNode request = objectMapper.valueToTree(registration); + request.putNull("applications"); + + mockMvc + .perform( + MockMvcRequestBuilders.post(API_MENTEES) + .header(API_KEY_HEADER, API_KEY_VALUE) + .contentType(APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) .andExpect(status().isBadRequest()); verify(menteeService, never()).saveRegistration(any()); @@ -217,4 +247,4 @@ void shouldReturn404WhenRejectingNonExistentMentee() throws Exception { .content(objectMapper.writeValueAsString(request))) .andExpect(status().isNotFound()); } -} +} \ No newline at end of file