Skip to content

Commit

Permalink
✨ : add backend implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
juwit committed Aug 5, 2022
1 parent fb48a86 commit 99f6176
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,17 @@ public Stack update(@PathVariable String id, @RequestBody @Valid Stack stack, Us
return stackRepository.save(stack);
}

@DeleteMapping("/{id}")
public void delete(@PathVariable String id, User user){
// try to load stack for the current user
var stack = this.getStack(id, user);
if(!stack.isArchived()){
throw new StackArchivedException();
}
// delete stack if it was found
stackRepository.delete(stack);
}

@PostMapping("/{id}/{jobType}")
public Map<String, String> launchJob(@PathVariable String id, @PathVariable JobType jobType, User user) {
// get the stack
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,55 @@ void update_shouldSaveStack() {
verify(stackRepository).save(stack);
}

@Test
void delete_shouldRemoveStack_forAdmin(){
// given
when(stackRepository.findById("42")).thenReturn(Optional.of(stack));
stack.setState(StackState.ARCHIVED);

//when
stackRestController.delete("42", adminUser);

// then
verify(stackRepository).delete(stack);
}

@Test
void delete_shouldRemoveStack_forStandardUser() {
// given
when(stackRepository.findByIdAndOwnerOrganization("42", userOrganization)).thenReturn(Optional.of(stack));
stack.setState(StackState.ARCHIVED);

// when
stackRestController.delete("42", standardUser);

// then
verify(stackRepository).delete(stack);
}

@Test
void delete_shouldRemoveStack_forUserWithoutOrganization() {
// given
when(stackRepository.findById("42")).thenReturn(Optional.of(stack));
stack.setState(StackState.ARCHIVED);

// when
stackRestController.delete("42", userWithNoOrganization);

// then
verify(stackRepository).delete(stack);
}

@Test
void delete_shouldFail_forNonArchivedStacks(){
// given
when(stackRepository.findById("42")).thenReturn(Optional.of(stack));
stack.setState(StackState.RUNNING);

//when
assertThrows(StackArchivedException.class, () -> stackRestController.delete("42", adminUser));
}

@Test
void launchJob_shouldConfigureAndSaveTheJob() {
// given
Expand Down

0 comments on commit 99f6176

Please sign in to comment.