Skip to content

Commit

Permalink
Merge ADM-572 [backend][frontend][stub]
Browse files Browse the repository at this point in the history
Adm 572
  • Loading branch information
yanzxu authored Sep 14, 2023
2 parents 212bfe0 + 7f78877 commit ca73567
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -471,13 +471,19 @@ private List<JiraCardDTO> getRealDoneCards(StoryPointsAndCycleTimeRequest reques
private boolean isRealDoneCardByHistory(CardHistoryResponseDTO jiraCardHistory,
StoryPointsAndCycleTimeRequest request) {
List<String> upperDoneStatuses = request.getStatus().stream().map(String::toUpperCase).toList();
long validStartTime = parseLong(request.getStartTime());

return jiraCardHistory.getItems()
List<Long> doneTimes = jiraCardHistory.getItems()
.stream()
.filter(history -> STATUS_FIELD_ID.equals(history.getFieldId()))
.filter(history -> upperDoneStatuses.contains(history.getTo().getDisplayValue().toUpperCase()))
.allMatch(history -> history.getTimestamp() > validStartTime);
.map(HistoryDetail::getTimestamp)
.toList();

long validStartTime = parseLong(request.getStartTime());
long validEndTime = parseLong(request.getEndTime());

return doneTimes.stream().allMatch(time -> validStartTime <= time)
&& doneTimes.stream().anyMatch(time -> validEndTime >= time);
}

private CycleTimeInfoDTO getCycleTime(URI baseUrl, String doneCardKey, String token, Boolean treatFlagCardAsBlock,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,16 @@ public static AllDoneCardsResponseDTO.AllDoneCardsResponseDTOBuilder ALL_DONE_CA
JiraCardField.builder().assignee(new Assignee(ASSIGNEENAME)).storyPoints(5).build())));
}

public static AllDoneCardsResponseDTO.AllDoneCardsResponseDTOBuilder NEED_FILTERED_ALL_DONE_CARDS_BUILDER() {
return AllDoneCardsResponseDTO.builder()
.total("2")
.issues(List.of(
new JiraCard("1",
JiraCardField.builder().assignee(new Assignee(ASSIGNEENAME)).storyPoints(5).build()),
new JiraCard("2",
JiraCardField.builder().assignee(new Assignee(ASSIGNEENAME)).storyPoints(5).build())));
}

public static AllDoneCardsResponseDTO.AllDoneCardsResponseDTOBuilder ALL_NON_DONE_CARDS_RESPONSE_FOR_STORY_POINT_BUILDER() {
return AllDoneCardsResponseDTO.builder()
.total("3")
Expand Down Expand Up @@ -202,6 +212,20 @@ public static CardHistoryResponseDTO.CardHistoryResponseDTOBuilder CARD_HISTORY_
new Status("removeFlag"))));
}

public static CardHistoryResponseDTO.CardHistoryResponseDTOBuilder CARD_HISTORY_DONE_TIME_GREATER_THAN_END_TIME_BUILDER() {
return CardHistoryResponseDTO.builder()
.items(List.of(new HistoryDetail(1, "status", new Status("To do"), new Status(BLOCK)),
new HistoryDetail(2, "assignee", new Status("In Dev"), new Status("To do")),
new HistoryDetail(3, "status", new Status(REVIEW), new Status("In Dev")),
new HistoryDetail(4, "status", new Status(WAITING_FOR_TESTING), new Status(REVIEW)),
new HistoryDetail(1682642740000L, "status", new Status(TESTING), new Status(WAITING_FOR_TESTING)),
new HistoryDetail(1682642740001L, "status", new Status(BLOCK), new Status(TESTING)),
new HistoryDetail(1682642740002L, "status", new Status(FLAG), new Status(BLOCK)),
new HistoryDetail(1682642750001L, "customfield_10021", new Status("Impediment"), new Status(FLAG)),
new HistoryDetail(1682642750002L, "flagged", new Status("Impediment"), new Status("removeFlag")),
new HistoryDetail(1686908799000L, "status", new Status("Done"), new Status(TESTING))));
}

public static FieldResponseDTO.FieldResponseDTOBuilder FIELD_RESPONSE_BUILDER() {
IssueField storyPointIssueField = new IssueField("customfield_10016", "Story point estimate");
IssueField sprintIssueField = new IssueField("customfield_10020", "Sprint");
Expand Down
29 changes: 29 additions & 0 deletions backend/src/test/java/heartbeat/service/jira/JiraServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import static heartbeat.service.jira.JiraBoardConfigDTOFixture.ALL_FIELD_RESPONSE_BUILDER;
import static heartbeat.service.jira.JiraBoardConfigDTOFixture.ALL_NON_DONE_CARDS_RESPONSE_FOR_STORY_POINT_BUILDER;
import static heartbeat.service.jira.JiraBoardConfigDTOFixture.BOARD_ID;
import static heartbeat.service.jira.JiraBoardConfigDTOFixture.CARD_HISTORY_DONE_TIME_GREATER_THAN_END_TIME_BUILDER;
import static heartbeat.service.jira.JiraBoardConfigDTOFixture.CARD_HISTORY_MULTI_RESPONSE_BUILDER;
import static heartbeat.service.jira.JiraBoardConfigDTOFixture.CARD_HISTORY_RESPONSE_BUILDER;
import static heartbeat.service.jira.JiraBoardConfigDTOFixture.CARD_HISTORY_RESPONSE_BUILDER_TO_DONE;
Expand All @@ -61,6 +62,7 @@
import static heartbeat.service.jira.JiraBoardConfigDTOFixture.JIRA_BOARD_CONFIG_RESPONSE_BUILDER;
import static heartbeat.service.jira.JiraBoardConfigDTOFixture.JIRA_BOARD_SETTING_BUILD;
import static heartbeat.service.jira.JiraBoardConfigDTOFixture.JIRA_BOARD_SETTING_HAVE_UNKNOWN_COLUMN_BUILD;
import static heartbeat.service.jira.JiraBoardConfigDTOFixture.NEED_FILTERED_ALL_DONE_CARDS_BUILDER;
import static heartbeat.service.jira.JiraBoardConfigDTOFixture.NONE_STATUS_SELF_RESPONSE_BUILDER;
import static heartbeat.service.jira.JiraBoardConfigDTOFixture.ONE_PAGE_NO_DONE_CARDS_RESPONSE_BUILDER;
import static heartbeat.service.jira.JiraBoardConfigDTOFixture.STORY_POINTS_FORM_ALL_DONE_CARD;
Expand Down Expand Up @@ -499,6 +501,33 @@ void shouldGetCardsWhenCallGetStoryPointsAndCycleTimeWhenBoardTypeIsClassicJira(
assertThat(cardCollection.getCardsNumber()).isEqualTo(1);
}

@Test
void shouldGetCardsWhenCallGetStoryPointsAndCycleTimeWhenDoneTimeGreaterThanSelectedEndTime()
throws JsonProcessingException {
// given
URI baseUrl = URI.create(SITE_ATLASSIAN_NET);
String token = "token";

JiraBoardSetting jiraBoardSetting = CLASSIC_JIRA_BOARD_SETTING_BUILD().build();
StoryPointsAndCycleTimeRequest storyPointsAndCycleTimeRequest = CLASSIC_JIRA_STORY_POINTS_FORM_ALL_DONE_CARD()
.build();
String allDoneCards = objectMapper.writeValueAsString(NEED_FILTERED_ALL_DONE_CARDS_BUILDER().build());

// when
when(urlGenerator.getUri(any())).thenReturn(baseUrl);
when(jiraFeignClient.getJiraCards(any(), any(), anyInt(), anyInt(), any(), any())).thenReturn(allDoneCards);
when(jiraFeignClient.getJiraCardHistory(baseUrl, "1", token))
.thenReturn(CARD_HISTORY_MULTI_RESPONSE_BUILDER().build());
when(jiraFeignClient.getJiraCardHistory(baseUrl, "2", token))
.thenReturn(CARD_HISTORY_DONE_TIME_GREATER_THAN_END_TIME_BUILDER().build());
when(jiraFeignClient.getTargetField(baseUrl, "PLL", token)).thenReturn(ALL_FIELD_RESPONSE_BUILDER().build());
// then

CardCollection cardCollection = jiraService.getStoryPointsAndCycleTimeForDoneCards(
storyPointsAndCycleTimeRequest, jiraBoardSetting.getBoardColumns(), List.of("Zhang San"));
assertThat(cardCollection.getCardsNumber()).isEqualTo(1);
}

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

0 comments on commit ca73567

Please sign in to comment.