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

ADM 834[Backend]Identify sites is available during validation board process #1337

Merged
merged 6 commits into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions backend/src/main/java/heartbeat/client/JiraFeignClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,8 @@ 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);

}
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,16 @@ public String verify(BoardType boardType, BoardVerifyRequestParam boardVerifyReq
URI baseUrl = urlGenerator.getUri(boardVerifyRequestParam.getSite());
verifyBoardTypeIsJira(boardType);

try {
jiraFeignClient.getDashboard(baseUrl, boardVerifyRequestParam.getToken());
}
catch (NotFoundException e) {
throw new NotFoundException("site is incorrect");
}
try {
JiraBoardVerifyDTO jiraBoardVerifyDTO = jiraFeignClient.getBoard(baseUrl,
boardVerifyRequestParam.getBoardId(), boardVerifyRequestParam.getToken());

return jiraBoardVerifyDTO.getLocation().getProjectKey();
}
catch (NotFoundException e) {
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
Loading