Skip to content

Commit

Permalink
TRIB-211: adds connect cntrl test for deleteCosign
Browse files Browse the repository at this point in the history
- adds test for when exception thrown
  • Loading branch information
mrsbluerose committed Jan 22, 2024
1 parent ea501f3 commit 2620a2a
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/test/java/com/savvato/tribeapp/controllers/ConnectAPITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@
import org.springframework.web.context.WebApplicationContext;

import java.util.HashSet;
import java.util.NoSuchElementException;
import java.util.Optional;
import java.util.Set;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.*;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.delete;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post;
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
Expand Down Expand Up @@ -258,4 +260,34 @@ public void deleteCosign() throws Exception {

}

@Test
public void deleteCosignWhenExceptionThrown() throws Exception {
when(userPrincipalService.getUserPrincipalByEmail(Mockito.anyString()))
.thenReturn(new UserPrincipal(user));
String auth = AuthServiceImpl.generateAccessToken(user);

Long userIdIssuing = 1L;
Long userIdReceiving = 1L;
Long phraseId = 1L;

CosignRequest cosignRequest = new CosignRequest();
cosignRequest.userIdIssuing = userIdIssuing;
cosignRequest.userIdReceiving = userIdReceiving;
cosignRequest.phraseId = phraseId;

doThrow(new NoSuchElementException("Cosign not found for the specified ids")).when(cosignService)
.deleteCosign(any(Long.class), any(Long.class), any(Long.class));

this.mockMvc
.perform(
delete("/api/connect/cosign")
.content(gson.toJson(cosignRequest))
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + auth)
.characterEncoding("utf-8"))
.andExpect(status().isInternalServerError())
.andExpect(content().string("Error: Cosign not found for the specified ids"));;
}


}

0 comments on commit 2620a2a

Please sign in to comment.