Skip to content

Commit

Permalink
ADM-834:[backend]feat: added api for domain url check
Browse files Browse the repository at this point in the history
  • Loading branch information
PengxiWPix committed Apr 7, 2024
1 parent 461af35 commit 172f7ed
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ CardHistoryResponseDTO getJiraCardHistoryByCount(URI baseUrl, @PathVariable Stri
@GetMapping(path = "rest/api/2/project/{projectIdOrKey}")
JiraBoardProject getProject(URI baseUrl, @PathVariable String projectIdOrKey, @RequestHeader String authorization);

// This api is solely used for site url checking
@GetMapping(path = "/rest/api/3/dashboard")
String getDashboard(URI baseUrl, @RequestHeader String authorization);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,27 +137,18 @@ public String verify(BoardType boardType, BoardVerifyRequestParam boardVerifyReq
verifyBoardTypeIsJira(boardType);

try {
String test = jiraFeignClient.getDashboard(baseUrl, boardVerifyRequestParam.getToken());
System.out.println(test);
System.out.println("asdfasdfasdfasdfasdfasdfasdf");
jiraFeignClient.getDashboard(baseUrl, boardVerifyRequestParam.getToken());
}
catch (NotFoundException e) {
System.out.println(e);
System.out.println("===============================================");
throw new NotFoundException("site is incorrect");
}

try {

JiraBoardVerifyDTO jiraBoardVerifyDTO = jiraFeignClient.getBoard(baseUrl,
boardVerifyRequestParam.getBoardId(), boardVerifyRequestParam.getToken());



return jiraBoardVerifyDTO.getLocation().getProjectKey();
}
catch (NotFoundException e) {
System.out.println(e);
log.error("Failed to call Jira to verify board url, url: {}", baseUrl);
throw new NotFoundException("boardId is incorrect");
}
Expand Down
16 changes: 16 additions & 0 deletions backend/src/test/java/heartbeat/service/jira/JiraServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ class JiraServiceTest {

public static final String SITE_ATLASSIAN_NET = "https://site.atlassian.net";

public static final String INVALID_SITE_ATLASSIAN_NET = "https://unknown.atlassian.net";

private final BoardType boardTypeJira = BoardType.fromStyle("next-gen");

private final BoardType boardTypeClassicJira = BoardType.fromStyle("classic");
Expand Down Expand Up @@ -514,6 +516,20 @@ void shouldCallJiraFeignClientBoardAndThrowNotFoundWhenVerifyJiraBoard() {
assertThat(thrown).isInstanceOf(RuntimeException.class).hasMessageContaining("boardId is incorrect");
}

@Test
void shouldCallJiraFeignClientBoardAndThrowNotFoundWhenVerifyJiraBoardSite() {
URI baseUrl = URI.create(INVALID_SITE_ATLASSIAN_NET);
String token = "token";
BoardVerifyRequestParam boardVerifyRequestParam = BOARD_VERIFY_REQUEST_BUILDER().build();

when(urlGenerator.getUri(any())).thenReturn(URI.create(INVALID_SITE_ATLASSIAN_NET));
doThrow(new NotFoundException("site is incorrect")).when(jiraFeignClient).getDashboard(baseUrl, token);

Throwable thrown = catchThrowable(() -> jiraService.verify(boardTypeJira, boardVerifyRequestParam));
assertThat(thrown).isInstanceOf(RuntimeException.class).hasMessageContaining("site is incorrect");

}

@Test
@Deprecated
void shouldCallJiraFeignClientAndThrowNotFoundExceptionWhenGetJiraBoardConfig() throws JsonProcessingException {
Expand Down

0 comments on commit 172f7ed

Please sign in to comment.