Increase Code Coverage

This commit is contained in:
Phan Huy Tran 2024-10-02 10:45:46 +02:00 committed by Phan Huy Tran
parent c8dedd6cee
commit 3b1c1b7929

@ -84,6 +84,55 @@ class UpdateProjectActionTest {
}
@Test
void updateProjectShouldUpdateProjectPartially() throws Exception {
ProjectEntity project = new ProjectEntity();
project.setId(1);
project.setName("name");
project.setLeadingEmployee(1);
project.setContractor(1);
project.setComment("comment");
project.setEmployees(List.of(1L, 2L, 3L));
project.setContractorName("contractorName");
project.setStartDate(LocalDate.of(2021, 1, 1));
project.setPlannedEndDate(LocalDate.of(2023, 1, 1));
project.setEndDate(LocalDate.of(2024, 1, 1));
this.projectRepository.save(project);
String content = """
{}
""";
final var contentAsString = this.mockMvc.perform(
put("/projects/1").content(content).contentType(MediaType.APPLICATION_JSON)
)
.andExpect(status().isOk())
.andExpect(jsonPath("name", is("name")))
.andExpect(jsonPath("leading_employee", is(1)))
.andExpect(jsonPath("employees", is(List.of(1,2,3))))
.andExpect(jsonPath("contractor", is(1)))
.andExpect(jsonPath("contractor_name", is("contractorName")))
.andExpect(jsonPath("comment", is("comment")))
.andExpect(jsonPath("start_date", is("01.01.2021")))
.andExpect(jsonPath("planned_end_date", is("01.01.2023")))
.andExpect(jsonPath("end_date", is("01.01.2024")))
.andReturn()
.getResponse()
.getContentAsString();
final var id = Long.parseLong(new JSONObject(contentAsString).get("id").toString());
final var existingProject = this.projectRepository.findById(id);
assertThat(existingProject.get().getName()).isEqualTo("name");
assertThat(existingProject.get().getLeadingEmployee()).isEqualTo(1);
assertThat(existingProject.get().getContractor()).isEqualTo(1);
assertThat(existingProject.get().getContractorName()).isEqualTo("contractorName");
assertThat(existingProject.get().getComment()).isEqualTo("comment");
assertThat(existingProject.get().getStartDate()).isEqualTo(LocalDate.of(2021, 1, 1));
assertThat(existingProject.get().getPlannedEndDate()).isEqualTo(LocalDate.of(2023, 1, 1));
assertThat(existingProject.get().getEndDate()).isEqualTo(LocalDate.of(2024, 1, 1));
}
@Test
void updateProjectShouldReturnNotFoundResponseWhenProjectIsNotFound() throws Exception {
this.mockMvc.perform(put("/projects/2").content("{}").contentType(MediaType.APPLICATION_JSON)).andExpect(status().isNotFound());