From dc9f931c16414d334459abb864fcff0d374eb3aa Mon Sep 17 00:00:00 2001 From: Julien WITTOUCK Date: Fri, 5 Aug 2022 18:57:42 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20:=20delete=20jobs=20related=20to=20?= =?UTF-8?q?stack?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/gaia_app/stacks/controller/StackRestController.java | 1 + src/main/java/io/gaia_app/stacks/repository/JobRepository.kt | 1 + .../io/gaia_app/stacks/controller/StackRestControllerTest.java | 3 +++ 3 files changed, 5 insertions(+) diff --git a/src/main/java/io/gaia_app/stacks/controller/StackRestController.java b/src/main/java/io/gaia_app/stacks/controller/StackRestController.java index 664b06b7..f6f5141a 100644 --- a/src/main/java/io/gaia_app/stacks/controller/StackRestController.java +++ b/src/main/java/io/gaia_app/stacks/controller/StackRestController.java @@ -92,6 +92,7 @@ public void delete(@PathVariable String id, User user){ } // delete stack if it was found stackRepository.delete(stack); + jobRepository.deleteByStackId(id); } @PostMapping("/{id}/{jobType}") diff --git a/src/main/java/io/gaia_app/stacks/repository/JobRepository.kt b/src/main/java/io/gaia_app/stacks/repository/JobRepository.kt index 83bbc53e..ac5085f7 100644 --- a/src/main/java/io/gaia_app/stacks/repository/JobRepository.kt +++ b/src/main/java/io/gaia_app/stacks/repository/JobRepository.kt @@ -11,5 +11,6 @@ import org.springframework.stereotype.Repository interface JobRepository : MongoRepository { fun findAllByStackIdOrderByScheduleTimeDesc(stackId: String): List + fun deleteByStackId(stackId: String); } diff --git a/src/test/java/io/gaia_app/stacks/controller/StackRestControllerTest.java b/src/test/java/io/gaia_app/stacks/controller/StackRestControllerTest.java index 83796f33..5adb6ed7 100644 --- a/src/test/java/io/gaia_app/stacks/controller/StackRestControllerTest.java +++ b/src/test/java/io/gaia_app/stacks/controller/StackRestControllerTest.java @@ -182,6 +182,7 @@ void delete_shouldRemoveStack_forAdmin(){ // then verify(stackRepository).delete(stack); + verify(jobRepository).deleteByStackId("42"); } @Test @@ -195,6 +196,7 @@ void delete_shouldRemoveStack_forStandardUser() { // then verify(stackRepository).delete(stack); + verify(jobRepository).deleteByStackId("42"); } @Test @@ -208,6 +210,7 @@ void delete_shouldRemoveStack_forUserWithoutOrganization() { // then verify(stackRepository).delete(stack); + verify(jobRepository).deleteByStackId("42"); } @Test