Skip to content

Commit

Permalink
RIA_7921: Update helper method to check if the direction parties are …
Browse files Browse the repository at this point in the history
…valid for EDIT events
  • Loading branch information
neha-aggarw committed Oct 17, 2023
1 parent ceb00ab commit c8ec331
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.springframework.stereotype.Component;
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.AsylumCase;
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.DocumentTag;
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.Parties;
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.CaseDetails;
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.Event;
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.callback.Callback;
Expand Down Expand Up @@ -46,7 +47,7 @@ public boolean canHandle(
&& Event.CHANGE_DIRECTION_DUE_DATE == event
&& isInternalCase(asylumCase)
&& isAppellantInDetention(asylumCase)
&& isDirectionPartyRespondent(asylumCase);
&& isDirectionPartyValid(asylumCase, Parties.RESPONDENT);
}

public PreSubmitCallbackResponse<AsylumCase> handle(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package uk.gov.hmcts.reform.iacasedocumentsapi.domain.handlers.presubmit.letter;

import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.AsylumCaseDefinition.DIRECTION_EDIT_PARTIES;
import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.AsylumCaseDefinition.NOTIFICATION_ATTACHMENT_DOCUMENTS;
import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.utils.AsylumCaseUtils.isAppellantInDetention;
import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.utils.AsylumCaseUtils.isInternalCase;
import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.utils.AsylumCaseUtils.*;

import java.util.Objects;
import org.springframework.beans.factory.annotation.Qualifier;
Expand Down Expand Up @@ -50,7 +48,8 @@ public boolean canHandle(
&& Event.CHANGE_DIRECTION_DUE_DATE == event
&& isInternalCase(asylumCase)
&& isAppellantInDetention(asylumCase)
&& isDirectionPartyAppellantOrAppellantRespondent(asylumCase);
&& (isDirectionPartyValid(asylumCase, Parties.APPELLANT_AND_RESPONDENT)
|| isDirectionPartyValid(asylumCase, Parties.APPELLANT));
}

public PreSubmitCallbackResponse<AsylumCase> handle(
Expand All @@ -75,10 +74,4 @@ public PreSubmitCallbackResponse<AsylumCase> handle(

return new PreSubmitCallbackResponse<>(asylumCase);
}

private boolean isDirectionPartyAppellantOrAppellantRespondent(AsylumCase asylumCase) {
return asylumCase.read(DIRECTION_EDIT_PARTIES, Parties.class)
.map(Parties -> Parties.equals(Parties.APPELLANT) || Parties.equals(Parties.APPELLANT_AND_RESPONDENT))
.orElse(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ public static Optional<IdValue<DocumentWithMetadata>> getLatestAddendumEvidenceD
return optionalLatestAddendum.isEmpty() ? Optional.empty() : Optional.of(optionalLatestAddendum.get());
}

public static boolean isDirectionPartyRespondent(AsylumCase asylumCase) {
public static boolean isDirectionPartyValid(AsylumCase asylumCase, Parties party) {
return asylumCase.read(DIRECTION_EDIT_PARTIES, Parties.class)
.map(parties -> parties.equals(Parties.RESPONDENT))
.map(parties -> parties.equals(party))
.orElse(false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
import org.junit.jupiter.params.provider.ValueSource;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
Expand Down Expand Up @@ -285,14 +284,26 @@ void should_return_empty_list_when_no_addendum_evidence_documents_present() {
}

@ParameterizedTest
@ValueSource(strings = { "LEGAL_REPRESENTATIVE", "RESPONDENT", "APPELLANT", "BOTH", "APPELLANT_AND_RESPONDENT" })
void should_return_correct_value_for_is_direction_party_respondent(String party) {
when(asylumCase.read(DIRECTION_EDIT_PARTIES, Parties.class)).thenReturn(Optional.of(Parties.valueOf(party)));
@EnumSource(value = Parties.class)
void should_return_correct_value_for_is_direction_party_respondent(Parties party) {
when(asylumCase.read(DIRECTION_EDIT_PARTIES, Parties.class)).thenReturn(Optional.of(Parties.RESPONDENT));
if (party == Parties.RESPONDENT) {
assertTrue(AsylumCaseUtils.isDirectionPartyValid(asylumCase, party));
} else {
assertFalse(AsylumCaseUtils.isDirectionPartyValid(asylumCase, party));

}
}

if (party.equals("RESPONDENT")) {
assertTrue(AsylumCaseUtils.isDirectionPartyRespondent(asylumCase));
@ParameterizedTest
@EnumSource(value = Parties.class)
void should_return_correct_value_for_is_direction_party_appellant(Parties party) {
when(asylumCase.read(DIRECTION_EDIT_PARTIES, Parties.class)).thenReturn(Optional.of(Parties.APPELLANT));
if (party == Parties.APPELLANT) {
assertTrue(AsylumCaseUtils.isDirectionPartyValid(asylumCase, party));
} else {
assertFalse(AsylumCaseUtils.isDirectionPartyRespondent(asylumCase));
assertFalse(AsylumCaseUtils.isDirectionPartyValid(asylumCase, party));

}
}

Expand Down

0 comments on commit c8ec331

Please sign in to comment.