Skip to content

fix: reject mentee registration with missing applications - #820

Open
cosmiinn75 wants to merge 1 commit into
Women-Coding-Community:mainfrom
cosmiinn75:fix/mentee-registration-null-validation
Open

cosmiinn75 wants to merge 1 commit into
Women-Coding-Community:mainfrom
cosmiinn75:fix/mentee-registration-null-validation

Conversation

@cosmiinn75

Copy link
Copy Markdown

Description

  • Added @NotNull to the applications field in MenteeRegistration.
  • Added a regression test to ensure that missing applications return HTTP 400 instead of 500.
  • Verified that the test fails without the fix and passes with it.

Related Issue

Fixes #740

Change Type

  • Bug Fix
  • New Feature
  • Code Refactor
  • Documentation
  • Test
  • Other

Screenshots

Not applicable.

Pull request checklist

  • I checked and followed the [contributor guide](../CONTRIBUTING.md).
  • I have tested my changes locally.

@cosmiinn75
cosmiinn75 requested a review from a team as a code owner October 15, 2026 13:13
@sonarqubecloud

Copy link
Copy Markdown

.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\":\""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we avoid, raw json content in file, yes it has been used before in previous tests but that is incorrect, would be good to clean-up that as well.

Why - Makes it harder to read the test data.

Suggested change
"{\"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\":\""
@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);
mockMvc
.perform(
MockMvcRequestBuilders.post(API_MENTEES)
.header(API_KEY_HEADER, API_KEY_VALUE)
.contentType(APPLICATION_JSON)
.content(objectMapper.writeValueAsString(registration)))
.andExpect(status().isBadRequest());
}

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Mentee registration without 'applications' field returns 500 (NPE)

2 participants