[R7] Unit test method for put patient

This commit is contained in:
Mirna Gama 2024-01-10 15:06:44 -03:00 committed by Mirna Gama
parent d2c910011e
commit 59609dfe08

View File

@ -18,6 +18,7 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.mirna.hospitalmanagementapi.domain.dtos.AddressDTO; import com.mirna.hospitalmanagementapi.domain.dtos.AddressDTO;
import com.mirna.hospitalmanagementapi.domain.dtos.patient.PatientDTO; import com.mirna.hospitalmanagementapi.domain.dtos.patient.PatientDTO;
import com.mirna.hospitalmanagementapi.domain.dtos.patient.PatientUpdatedDataDTO;
import com.mirna.hospitalmanagementapi.domain.entities.Patient; import com.mirna.hospitalmanagementapi.domain.entities.Patient;
import com.mirna.hospitalmanagementapi.domain.repositories.PatientRepository; import com.mirna.hospitalmanagementapi.domain.repositories.PatientRepository;
@ -123,4 +124,36 @@ public class PatientControllerTest {
.characterEncoding("UTF-8")) .characterEncoding("UTF-8"))
.andExpect(MockMvcResultMatchers.status().isOk()).andDo(MockMvcResultHandlers.print()); .andExpect(MockMvcResultMatchers.status().isOk()).andDo(MockMvcResultHandlers.print());
} }
/**
* Put a valid patient
*/
@Test
@DisplayName("Should put a valid patient and return http status ok")
public void testPutValidDoctor() throws Exception {
PatientUpdatedDataDTO patientUpdatedDataDTO = new PatientUpdatedDataDTO(testPatient.getId(), "updated_test", null, null);
String patientUpdatedDataDTOContent = mapper.writeValueAsString(patientUpdatedDataDTO);
mockMvc.perform(MockMvcRequestBuilders.put("/api/v1.0/patients").contentType(MediaType.APPLICATION_JSON)
.characterEncoding("UTF-8").content(patientUpdatedDataDTOContent))
.andExpect(MockMvcResultMatchers.status().isOk()).andDo(MockMvcResultHandlers.print());
}
/**
* Avoid putting a invalid patient.
*/
@Test
@DisplayName("Should not put invalid patient and return http status bad request")
public void testPutInvalidDoctor() throws Exception {
PatientUpdatedDataDTO patientUpdatedDataDTO = new PatientUpdatedDataDTO(null, "updated_test", null, null);
String patientUpdatedDataDTOContent = mapper.writeValueAsString(patientUpdatedDataDTO);
mockMvc.perform(MockMvcRequestBuilders.put("/api/v1.0/patients").contentType(MediaType.APPLICATION_JSON)
.characterEncoding("UTF-8").content(patientUpdatedDataDTOContent))
.andExpect(MockMvcResultMatchers.status().isBadRequest()).andDo(MockMvcResultHandlers.print());
}
} }