diff --git a/src/main/java/com/cruru/process/controller/ProcessController.java b/src/main/java/com/cruru/process/controller/ProcessController.java index a41412753..ba6b4b681 100644 --- a/src/main/java/com/cruru/process/controller/ProcessController.java +++ b/src/main/java/com/cruru/process/controller/ProcessController.java @@ -27,4 +27,10 @@ public ResponseEntity create(@RequestParam(name = "dashboard_id") Long das processService.create(dashboardId, request); return ResponseEntity.status(HttpStatus.CREATED).build(); } + + @DeleteMapping("/{process_id}") + public ResponseEntity delete(@PathVariable(name = "process_id") Long processId) { + processService.delete(processId); + return ResponseEntity.noContent().build(); + } } diff --git a/src/main/java/com/cruru/process/service/ProcessService.java b/src/main/java/com/cruru/process/service/ProcessService.java index b848f2285..cd756b1a6 100644 --- a/src/main/java/com/cruru/process/service/ProcessService.java +++ b/src/main/java/com/cruru/process/service/ProcessService.java @@ -70,4 +70,9 @@ public void create(long dashboardId, ProcessCreateRequest request) { dashboardRepository.findById(dashboardId).orElseThrow()) ); } + + @Transactional + public void delete(long processId) { + processRepository.deleteById(processId); + } } diff --git a/src/test/java/com/cruru/process/controller/ProcessControllerTest.java b/src/test/java/com/cruru/process/controller/ProcessControllerTest.java index a38b205a7..15fa00448 100644 --- a/src/test/java/com/cruru/process/controller/ProcessControllerTest.java +++ b/src/test/java/com/cruru/process/controller/ProcessControllerTest.java @@ -57,4 +57,12 @@ void create() { .when().post("/api/v1/processes?dashboard_id=" + dashboard.getId()) .then().log().all().statusCode(201); } + + @DisplayName("프로세스 삭제 성공 시, 204를 응답한다.") + @Test + void delete() { + RestAssured.given().log().all() + .when().delete("/api/v1/processes/" + process.getId()) + .then().log().all().statusCode(204); + } } diff --git a/src/test/java/com/cruru/process/service/ProcessServiceTest.java b/src/test/java/com/cruru/process/service/ProcessServiceTest.java index 1408fb315..44d91515b 100644 --- a/src/test/java/com/cruru/process/service/ProcessServiceTest.java +++ b/src/test/java/com/cruru/process/service/ProcessServiceTest.java @@ -9,8 +9,7 @@ import com.cruru.process.controller.dto.ProcessesResponse; import com.cruru.process.domain.Process; import com.cruru.process.domain.repository.ProcessRepository; -import jakarta.persistence.EntityManager; -import jakarta.persistence.PersistenceContext; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -26,17 +25,26 @@ @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE) class ProcessServiceTest { - @PersistenceContext - EntityManager em; @Autowired private DashboardRepository dashboardRepository; + @Autowired private ProcessRepository processRepository; + @Autowired private ApplicantRepository applicantRepository; + @Autowired private ProcessService processService; + @BeforeEach + void setUp() { + applicantRepository.deleteAll(); + processRepository.deleteAll(); + dashboardRepository.deleteAll(); + } + + @DisplayName("ID에 해당하는 대시보드의 프로세스 목록과 지원자 정보를 조회한다.") @Test void findByDashboardId() { @@ -93,4 +101,20 @@ void create() { assertThat(allByDashboardId).hasSize(3); assertThat(allByDashboardId.get(1).getName()).isEqualTo("면접"); } + + @DisplayName("프로세스를 삭제한다.") + @Test + void delete() { + // given + Dashboard dashboard = new Dashboard("name", null); + dashboard = dashboardRepository.save(dashboard); + Process process1 = new Process(0, "name", "description", dashboard); + process1 = processRepository.save(process1); + + // when + processService.delete(process1.getId()); + + // then + assertThat(processRepository.findAll()).hasSize(0); + } }