Skip to content

Commit

Permalink
fix: OH2-413 | OH2-414 (#494)
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverD3 authored Oct 30, 2024
1 parent 264cc26 commit f4fe33b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
8 changes: 5 additions & 3 deletions src/test/java/org/isf/agetype/rest/AgeTypeControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import org.isf.agetype.data.AgeTypeHelper;
import org.isf.agetype.dto.AgeTypeDTO;
Expand Down Expand Up @@ -61,7 +62,7 @@ public class AgeTypeControllerTest {
@Mock
private AgeTypeBrowserManager ageTypeManagerMock;

private AgeTypeMapper ageTypeMapper = new AgeTypeMapper();
private final AgeTypeMapper ageTypeMapper = new AgeTypeMapper();

private MockMvc mockMvc;

Expand Down Expand Up @@ -120,7 +121,7 @@ public void testUpdateAgeType_200() throws Exception {
MvcResult result = this.mockMvc
.perform(put(request)
.contentType(MediaType.APPLICATION_JSON)
.content(AgeTypeHelper.asJsonString(body))
.content(Objects.requireNonNull(AgeTypeHelper.asJsonString(body)))
)
.andDo(log())
.andExpect(status().is2xxSuccessful())
Expand Down Expand Up @@ -157,6 +158,7 @@ public void testGetAgeTypeByIndex_200() throws Exception {
String request = "/agetypes/{index}";
int index = 10;
AgeType ageType = AgeTypeHelper.setup(index);
AgeTypeDTO ageTypeDTO = ageTypeMapper.map2DTO(ageType);

when(ageTypeManagerMock.getTypeByCode(index))
.thenReturn(ageType);
Expand All @@ -166,7 +168,7 @@ public void testGetAgeTypeByIndex_200() throws Exception {
.andDo(log())
.andExpect(status().is2xxSuccessful())
.andExpect(status().isOk())
.andExpect(content().string(containsString(AgeTypeHelper.getObjectMapper().writeValueAsString(ageType))))
.andExpect(content().string(containsString(AgeTypeHelper.getObjectMapper().writeValueAsString(ageTypeDTO))))
.andReturn();

LOGGER.debug("result: {}", result);
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/org/isf/exam/rest/ExamControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class UpdateExamTests {

@Test
@DisplayName("Should update an exam with associated examrows")
@WithMockUser(username = "admin", authorities = { "exams.update", "examrows.create", "examrows.delete" })
@WithMockUser(username = "admin", authorities = { "exams.create", "exams.update", "examrows.create", "examrows.delete" })
void shouldUpdateExamWithRows() throws Exception {
ExamWithRowsDTO payload = ExamHelper.generateExamWithRowsDTO();
Exam exam = examMapper.map2Model(payload.exam());
Expand All @@ -166,7 +166,7 @@ void shouldUpdateExamWithRows() throws Exception {

@Test
@DisplayName("Should fail to update exam procedure 1 with rows when default result doesn't match")
@WithMockUser(username = "admin", authorities = { "exams.update", "examrows.create", "examrows.delete" })
@WithMockUser(username = "admin", authorities = { "exams.create", "exams.update", "examrows.create", "examrows.delete" })
void shouldFailToUpdateExamWithInvalidDefaultResult() throws Exception {
ExamDTO examDTO = ExamHelper.generateExam();
examDTO.setDefaultResult("IRES");
Expand All @@ -189,7 +189,7 @@ void shouldFailToUpdateExamWithInvalidDefaultResult() throws Exception {

@Test
@DisplayName("Should fail to update exam code in body doesn't match")
@WithMockUser(username = "admin", authorities = { "exams.update", "examrows.create", "examrows.delete" })
@WithMockUser(username = "admin", authorities = { "exams.create", "exams.update", "examrows.create", "examrows.delete" })
void shouldFailToUpdateExamWhenCodeInBodyDoesntMatch() throws Exception {
var result = mvc.perform(
put("/exams/{code}", "DD").contentType(MediaType.APPLICATION_JSON)
Expand All @@ -203,7 +203,7 @@ void shouldFailToUpdateExamWhenCodeInBodyDoesntMatch() throws Exception {

@Test
@DisplayName("Should fail to update exam when user doesn't have required permissions")
@WithMockUser(username = "admin", authorities = { "examrows.create", "examrows.delete" })
@WithMockUser(username = "admin", authorities = { "exams.create", "examrows.create", "examrows.delete" })
void shouldFailToUpdateExamWhenInsufficientPermissions() throws Exception {
var result = mvc.perform(
put("/exams/hd").contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValueAsString(ExamHelper.generateExamWithRowsDTO())))
Expand Down

0 comments on commit f4fe33b

Please sign in to comment.