Skip to content

add test related to post mentor id#583

Open
lulu-cao wants to merge 2 commits intoWomen-Coding-Community:mainfrom
lulu-cao:add-test-to-post-mentor-id
Open

add test related to post mentor id#583
lulu-cao wants to merge 2 commits intoWomen-Coding-Community:mainfrom
lulu-cao:add-test-to-post-mentor-id

Conversation

@lulu-cao
Copy link
Copy Markdown
Contributor

@lulu-cao lulu-cao commented Mar 25, 2026

Description

Add test to verify the id field in POST /mentors request body will be ignored in the backend.

Related Issue / PR

Issue #486
PR #540 (comment)

Change Type

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

Screenshots

Screenshot 2026-03-24 at 8 25 42 PM

Pull request checklist

Please check if your PR fulfills the following requirements:

@lulu-cao
Copy link
Copy Markdown
Contributor Author

@womencodingcommunity Requested test has been added. Thanks for reviewing :)

Copy link
Copy Markdown
Contributor

@womencodingcommunity womencodingcommunity left a comment

Choose a reason for hiding this comment

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

Good contribution — plugging the gap identified in PR #540 is exactly the right follow-up, and the @DisplayName follows the Given-When-Then convention correctly.

One change needed before merge:

[WARNING] The final assertion jsonPath("$.id").value(not(999)) is too loose — it passes for any value that is not 999, including null. Swap it for an exact match on the DB-assigned id (see inline comment). The mock already pins savedMentor to id = 1L, so jsonPath("$.id", is(1)) is both more precise and consistent with the existing shouldCreateMentorAndReturnCreated test.

Two minor optional follow-ups (no blocker):

  • when(mentorshipService.create(any()))any(Mentor.class) for consistency with the rest of the file
  • Comment // returns DB-assigned id (e.g. 1) — the e.g. is slightly misleading since the factory always returns 1L; // id = 1L, DB-assigned is clearer

mockMvc
.perform(postRequest(API_MENTORS, requestWithId))
.andExpect(status().isCreated())
.andExpect(jsonPath("$.id").value(not(999)));
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
.andExpect(jsonPath("$.id").value(not(999)));
.andExpect(jsonPath("$.id", is(1)))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated 81c83a5

@sonarqubecloud
Copy link
Copy Markdown

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.

3 participants