-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/visa comment integration #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
cfaaf84
feat: sync comment logic to section in visa case details
eeebbaandersson e6259ac
feat: implement tests for CommentMapper
eeebbaandersson c1367ee
style: align border-radius and improve typography in visa details
eeebbaandersson daf6f5a
chore: merge main and resolve conflicts in visa details
eeebbaandersson c1d766b
fix: remove invalid comment reference outside thymeleaf loop
eeebbaandersson fa04a0c
test: implement CommentService integration tests
eeebbaandersson da130cd
test: implement tests for CommentController
eeebbaandersson fd0851e
fix: suggested fixes from CodeRabbit
eeebbaandersson 54810d8
feature: add call to auditService to create log when a nwe comment is…
eeebbaandersson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/test/java/org/example/visacasemanagementsystem/comment/CommentControllerTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| package org.example.visacasemanagementsystem.comment; | ||
|
|
||
| import org.example.visacasemanagementsystem.comment.controller.CommentController; | ||
| import org.example.visacasemanagementsystem.comment.dto.CommentDTO; | ||
| import org.example.visacasemanagementsystem.comment.dto.CreateCommentDTO; | ||
| import org.example.visacasemanagementsystem.comment.service.CommentService; | ||
| import org.springframework.http.MediaType; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest; | ||
| import org.springframework.security.test.context.support.WithMockUser; | ||
| import org.springframework.test.context.bean.override.mockito.MockitoBean; | ||
| import org.springframework.test.web.servlet.MockMvc; | ||
| import tools.jackson.databind.ObjectMapper; | ||
|
|
||
| import java.time.LocalDateTime; | ||
| import java.util.List; | ||
|
|
||
|
|
||
| import static org.mockito.ArgumentMatchers.any; | ||
| import static org.mockito.Mockito.when; | ||
| import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; | ||
| import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | ||
| import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; | ||
| import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
| import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
|
|
||
|
|
||
|
|
||
| @WebMvcTest(CommentController.class) | ||
| class CommentControllerTest { | ||
|
|
||
| @Autowired | ||
| private MockMvc mockMvc; | ||
| @MockitoBean | ||
| private CommentService commentService; | ||
| @Autowired | ||
| private ObjectMapper objectMapper; | ||
|
|
||
| @Test | ||
| @WithMockUser | ||
| void createComment_shouldReturnCreated() throws Exception { | ||
| // Arrange | ||
| CreateCommentDTO createDto= new CreateCommentDTO(1L, 1L, "Test message"); | ||
| CommentDTO responseDto = new CommentDTO(100L, 1L,"Test User", "Test message", LocalDateTime.now()); | ||
|
|
||
| when(commentService.createComment(any(CreateCommentDTO.class))).thenReturn(responseDto); | ||
|
|
||
| // Act & Assert | ||
| mockMvc.perform(post("/api/comments") | ||
| .with(csrf()) | ||
| .contentType((MediaType.APPLICATION_JSON)) | ||
| .content(objectMapper.writeValueAsString(createDto))) | ||
| .andExpect(status().isCreated()) | ||
| .andExpect(jsonPath("$.id").value(100L)) | ||
| .andExpect(jsonPath("$.text").value("Test message")) | ||
| .andExpect(jsonPath("$.authorName").value("Test User")); | ||
| } | ||
|
|
||
| @Test | ||
| @WithMockUser | ||
| void getCommentsByVisa_ShouldReturnList() throws Exception { | ||
| // Arrange | ||
| String expectedText = "Hello World"; | ||
| CommentDTO comment = new CommentDTO(1L, 2L, "Admin", expectedText, LocalDateTime.now()); | ||
|
|
||
| when(commentService.getCommentsByVisaId(1L)).thenReturn(List.of(comment)); | ||
|
|
||
| // Act & Assert | ||
| mockMvc.perform(get("/api/comments/visa/1")) | ||
| .andExpect(status().isOk()) | ||
| .andExpect(jsonPath("$.length()").value(1)) | ||
| .andExpect(jsonPath("$[0].text").value(expectedText)); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not build audit attribution from the DTO-supplied author id.
authoris resolved fromdto.authorId(), so this new audit entry can be forged by posting another user’s id. Since the audit log is now security-sensitive, resolve the actor from the authenticated principal and use that same principal-derived user for both the comment author andcreateAuditLog.Suggested direction
Based on learnings, once Spring Security is added, the author should be resolved from the authenticated principal rather than from
dto.authorId().🤖 Prompt for AI Agents