Skip to content

Commit

Permalink
Merge branch 'master' into feat/CIV-10568
Browse files Browse the repository at this point in the history
  • Loading branch information
bhagyashreesharma90 authored Nov 15, 2023
2 parents 0dbff8b + 7e2e30e commit 7c9a519
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/main/java/uk/gov/hmcts/reform/civil/enums/ClaimType.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public enum ClaimType {
BREACH_OF_CONTRACT(FeeType.HIGHER),
CONSUMER(FeeType.HIGHER),
CONSUMER_CREDIT(FeeType.HIGHER),
OTHER(FeeType.HIGHER);
OTHER(FeeType.HIGHER),
FLIGHT_DELAY(null);

private final FeeType feeType;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import uk.gov.hmcts.reform.civil.config.ToggleConfiguration;
import uk.gov.hmcts.reform.civil.config.ClaimUrlsConfiguration;
import uk.gov.hmcts.reform.civil.enums.CaseCategory;
import uk.gov.hmcts.reform.civil.enums.ClaimType;
import uk.gov.hmcts.reform.civil.enums.MultiPartyScenario;
import uk.gov.hmcts.reform.civil.enums.YesOrNo;
import uk.gov.hmcts.reform.civil.model.Address;
Expand Down Expand Up @@ -230,6 +231,7 @@ protected Map<String, Callback> callbacks() {
)
.put(callbackKey(MID, "validate-spec-defendant-legal-rep-email"), this::validateSpecRespondentRepEmail)
.put(callbackKey(MID, "validate-spec-defendant2-legal-rep-email"), this::validateSpecRespondent2RepEmail)
.put(callbackKey(MID, "is-flight-delay-claim"), this::isFlightDelayClaim)
.build();
}

Expand Down Expand Up @@ -900,6 +902,23 @@ private CallbackResponse validateSpecRespondent2RepEmail(CallbackParams callback
.build();
}

private CallbackResponse isFlightDelayClaim(CallbackParams callbackParams) {
CaseData.CaseDataBuilder<?, ?> caseDataBuilder = callbackParams.getCaseData().toBuilder();

if (toggleService.isSdoR2Enabled()) {
caseDataBuilder.isFlightDelayClaim(callbackParams.getCaseData().getIsFlightDelayClaim());
if (callbackParams.getCaseData().getIsFlightDelayClaim().equals(YES)) {
caseDataBuilder.claimType(ClaimType.FLIGHT_DELAY);
} else {
caseDataBuilder.claimType(null);
}
}

return AboutToStartOrSubmitCallbackResponse.builder()
.data(caseDataBuilder.build().toMap(objectMapper))
.build();
}

private CallbackResponse setRespondent2SameLegalRepToNo(CallbackParams callbackParams) {
CaseData.CaseDataBuilder caseDataBuilder = callbackParams.getCaseData().toBuilder();

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/uk/gov/hmcts/reform/civil/model/CaseData.java
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,9 @@ public boolean hasNoOngoingBusinessProcess() {

private final TransferCaseDetails transferCaseDetails;

//SDO-R2
private YesOrNo isFlightDelayClaim;

/**
* There are several fields that can hold the I2P of applicant1 depending
* on multiparty scenario, which complicates all conditions depending on it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,8 @@ public boolean isCaseProgressionEnabled() {
public boolean isEarlyAdoptersEnabled() {
return featureToggleApi.isFeatureEnabled("early-adopters");
}

public boolean isSdoR2Enabled() {
return featureToggleApi.isFeatureEnabled("isSdoR2Enabled");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
Expand Down Expand Up @@ -1620,6 +1622,47 @@ void shouldReturnErrors_whenRequiredAddressIsYesAndNotValid() {
}
}

@Nested
class IsFlightDelayClaimMidCallback {
@ParameterizedTest
@ValueSource(booleans = {true, false})
void shouldSetIsFlightDelayClaim_whenPopulatedAndSdoR2Enabled(Boolean toggleStat) {
// Given
YesOrNo yesOrNo = toggleStat ? YES : NO;
CaseData caseData = CaseData.builder().isFlightDelayClaim(yesOrNo)
.build();

CallbackParams params = callbackParamsOf(caseData, MID, "is-flight-delay-claim");
// When
when(toggleService.isSdoR2Enabled()).thenReturn(true);
var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params);

// Then
assertThat(response.getData()).containsEntry("isFlightDelayClaim", toggleStat ? "Yes" : "No");
if (toggleStat) {
assertThat(response.getData()).containsEntry("claimType", "FLIGHT_DELAY");
} else {
assertThat(response.getData()).doesNotHaveToString("claimType");
}
}

@Test
void shouldSetIsFlightDelayClaim_whenPopulatedAndSdoR2Disabled() {
// Given
CaseData caseData = CaseData.builder().isFlightDelayClaim(YES)
.build();

CallbackParams params = callbackParamsOf(caseData, MID, "is-flight-delay-claim");
// When
when(toggleService.isSdoR2Enabled()).thenReturn(false);
var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params);

// Then
assertThat(response.getData()).doesNotHaveToString("isFlightDelayClaim");
assertThat(response.getData()).doesNotHaveToString("claimType");
}
}

@Nested
class AboutToSubmitCallbackV1 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,15 @@ void shouldReturnCorrectValue_whenEarlyAdopterEnabled(Boolean toggleStat) {
assertThat(featureToggleService.isEarlyAdoptersEnabled()).isEqualTo(toggleStat);
}

@ParameterizedTest
@ValueSource(booleans = {true, false})
void shouldReturnCorrectValue_whenIsSdoR2Enabled(Boolean toggleStat) {
var sdoR2Key = "isSdoR2Enabled";
givenToggle(sdoR2Key, toggleStat);

assertThat(featureToggleService.isSdoR2Enabled()).isEqualTo(toggleStat);
}

private void givenToggle(String feature, boolean state) {
when(featureToggleApi.isFeatureEnabled(eq(feature)))
.thenReturn(state);
Expand Down

0 comments on commit 7c9a519

Please sign in to comment.