Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IA-4912] Add DELETE chartVersion endpoint #6

Merged
merged 10 commits into from
May 22, 2024
27 changes: 27 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!-- Welcome to your Terra-app-manager pull request! -->
<!-- Contributor guidelines found in CONTRIBUTING.md -->

__Jira ticket__: https://broadworkbench.atlassian.net/browse/[ticket_number]

<!-- ## Dependencies -->
<!-- Include any dependent tickets and describe the relationship. Include any other relevant Jira tickets. -->

## Summary of changes

<!-- Please give an abridged version of the ticket description here and/or fill out the following fields. -->

### What

-

### Why

-


## Checklist

- [ ] Thorough tests have been added and/or updated for this change
- [ ] Documentation has been updated for this change <!-- (if applicable) -->
- [ ] This change has been validated in a BEE and/or locally <!-- (in what environment?) -->
- [ ] Primary reviewer validated this change <!-- (consider a pair review!) -->
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ public ResponseEntity<Void> createChartVersions(List<ChartVersion> body) {
return ResponseEntity.noContent().build();
}

@Override
public ResponseEntity<Void> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ public void createVersions(@NotNull List<ChartVersion> 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
*
Expand Down
19 changes: 19 additions & 0 deletions service/src/main/resources/api/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -38,6 +39,7 @@ class AdminControllerTest {
@Autowired AdminController controller;

@Captor ArgumentCaptor<List<bio.terra.appmanager.model.ChartVersion>> capture_chartVersions;
@Captor ArgumentCaptor<String> capture_chartName;

private AutoCloseable closeable;

Expand Down Expand Up @@ -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");
Expand All @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ void testCreateChartVersion_multipleElement() {
assertNull(argument.getValue().activeAt());
}

@Test
void testDeleteVersion() {
String chartName1 = "chart-name-here";

ArgumentCaptor<List<String>> 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<String> chartNameList = List.of("chart-name-here");
Expand Down
Loading