add test related to post mentor id#583
add test related to post mentor id#583lulu-cao wants to merge 2 commits intoWomen-Coding-Community:mainfrom
Conversation
|
@womencodingcommunity Requested test has been added. Thanks for reviewing :) |
womencodingcommunity
left a comment
There was a problem hiding this comment.
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)— thee.g.is slightly misleading since the factory always returns1L;// id = 1L, DB-assignedis clearer
| mockMvc | ||
| .perform(postRequest(API_MENTORS, requestWithId)) | ||
| .andExpect(status().isCreated()) | ||
| .andExpect(jsonPath("$.id").value(not(999))); |
There was a problem hiding this comment.
| .andExpect(jsonPath("$.id").value(not(999))); | |
| .andExpect(jsonPath("$.id", is(1))) |
|



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
Screenshots
Pull request checklist
Please check if your PR fulfills the following requirements: