diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..7368f8b --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,27 @@ + + + +__Jira ticket__: https://broadworkbench.atlassian.net/browse/[ticket_number] + + + + +## Summary of changes + + + +### What + +- + +### Why + +- + + +## Checklist + +- [ ] Thorough tests have been added and/or updated for this change +- [ ] Documentation has been updated for this change +- [ ] This change has been validated in a BEE and/or locally +- [ ] Primary reviewer validated this change diff --git a/service/src/main/java/bio/terra/appmanager/controller/AdminController.java b/service/src/main/java/bio/terra/appmanager/controller/AdminController.java index 6f13876..716b949 100644 --- a/service/src/main/java/bio/terra/appmanager/controller/AdminController.java +++ b/service/src/main/java/bio/terra/appmanager/controller/AdminController.java @@ -29,6 +29,12 @@ public ResponseEntity createChartVersions(List body) { return ResponseEntity.noContent().build(); } + @Override + public ResponseEntity deleteChartVersion(String body) { + this.chartService.deleteVersion(body); + return ResponseEntity.noContent().build(); + } + // Note that this method's implementation relies on `includeAll` having a default value and being // not null @Override diff --git a/service/src/main/java/bio/terra/appmanager/service/ChartService.java b/service/src/main/java/bio/terra/appmanager/service/ChartService.java index 29f55c7..06e5774 100644 --- a/service/src/main/java/bio/terra/appmanager/service/ChartService.java +++ b/service/src/main/java/bio/terra/appmanager/service/ChartService.java @@ -27,6 +27,15 @@ public void createVersions(@NotNull List versions) { versions.forEach(chartVersionDao::upsert); } + /** + * Soft-delete the specified chart entries with associated chartName. + * + * @param names non-null {@ ChartName} to delete + */ + public void deleteVersion(@NotNull String name) { + chartVersionDao.delete(List.of(name)); + } + /** * Get chart versions by name * diff --git a/service/src/main/resources/api/openapi.yml b/service/src/main/resources/api/openapi.yml index 2ffd6cc..adea478 100644 --- a/service/src/main/resources/api/openapi.yml +++ b/service/src/main/resources/api/openapi.yml @@ -59,6 +59,25 @@ paths: description: Request did not come from an admin '500': $ref: '#/components/responses/ServerError' + delete: + tags: [ admin ] + summary: Delete ChartVersion + operationId: deleteChartVersion + security: [ ] # TODO: remove this to turn on "security" + parameters: + - in: query + name: chartName + description: ChartName to delete. + required: true + schema: + type: string + responses: + '204': + description: ChartVersion has been successfully deleted + '403': + description: Request did not come from an admin + '500': + $ref: '#/components/responses/ServerError' get: tags: [ admin ] summary: Get ChartVersion(s) diff --git a/service/src/test/java/bio/terra/appmanager/api/AdminControllerTest.java b/service/src/test/java/bio/terra/appmanager/api/AdminControllerTest.java index 37e1834..3f388f0 100644 --- a/service/src/test/java/bio/terra/appmanager/api/AdminControllerTest.java +++ b/service/src/test/java/bio/terra/appmanager/api/AdminControllerTest.java @@ -5,6 +5,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -38,6 +39,7 @@ class AdminControllerTest { @Autowired AdminController controller; @Captor ArgumentCaptor> capture_chartVersions; + @Captor ArgumentCaptor capture_chartName; private AutoCloseable closeable; @@ -134,7 +136,7 @@ void testGet_200_WithNoNameAndIncludeAll() throws Exception { @Test @Disabled("Enable when Authorization is implemented") - void testGet_403() throws Exception { + void testGet_403() { // we need to do this when we put in authorization // this will fail if someone removes @Disabled(...) fail("force whomever removes @Disabled(...) to implement test"); @@ -148,6 +150,26 @@ void testCreate_403() throws Exception { fail("force whomever removes @Disabled(...) to implement test"); } + @Test + void testDelete_204() throws Exception { + String chartName = "chart-name-here"; + + mockMvc + .perform(delete("/api/admin/v1/charts/versions").queryParam("chartName", chartName)) + .andExpect(status().isNoContent()); + + verify(serviceMock).deleteVersion(capture_chartName.capture()); + assertEquals(capture_chartName.getValue(), chartName); + } + + @Test + @Disabled("Enable when Authorization is implemented") + void testDelete_403() throws Exception { + // we need to do this when we put in authorization + // this will fail if someone removes @Disabled(...) + fail("force whomever removes @Disabled(...) to implement test"); + } + @Test void testGet_ChartVersionModelToApi() { String chartName = "chart-name-here"; diff --git a/service/src/test/java/bio/terra/appmanager/service/ChartServiceTest.java b/service/src/test/java/bio/terra/appmanager/service/ChartServiceTest.java index 5d0c56d..3ba6293 100644 --- a/service/src/test/java/bio/terra/appmanager/service/ChartServiceTest.java +++ b/service/src/test/java/bio/terra/appmanager/service/ChartServiceTest.java @@ -63,6 +63,18 @@ void testCreateChartVersion_multipleElement() { assertNull(argument.getValue().activeAt()); } + @Test + void testDeleteVersion() { + String chartName1 = "chart-name-here"; + + ArgumentCaptor> argument = ArgumentCaptor.forClass(List.class); + + chartService.deleteVersion(chartName1); + verify(chartVersionDao, times(1)).delete(argument.capture()); + assertEquals(1, argument.getValue().size()); + assertEquals(chartName1, argument.getValue().get(0)); + } + @Test void testGetVersions() { List chartNameList = List.of("chart-name-here");