diff --git a/src/main/java/uk/gov/hmcts/reform/civil/enums/ClaimType.java b/src/main/java/uk/gov/hmcts/reform/civil/enums/ClaimType.java index 2f56dbbaeb5..37c90e0f65b 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/enums/ClaimType.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/enums/ClaimType.java @@ -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; diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/CreateClaimSpecCallbackHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/CreateClaimSpecCallbackHandler.java index ffc3d2b47b4..7dc8d457b95 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/CreateClaimSpecCallbackHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/CreateClaimSpecCallbackHandler.java @@ -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; @@ -230,6 +231,7 @@ protected Map 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(); } @@ -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(); diff --git a/src/main/java/uk/gov/hmcts/reform/civil/model/CaseData.java b/src/main/java/uk/gov/hmcts/reform/civil/model/CaseData.java index 953b02321d3..96dd6656365 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/model/CaseData.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/model/CaseData.java @@ -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. diff --git a/src/main/java/uk/gov/hmcts/reform/civil/service/FeatureToggleService.java b/src/main/java/uk/gov/hmcts/reform/civil/service/FeatureToggleService.java index f4aa4bc5382..8b11403a6fc 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/service/FeatureToggleService.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/service/FeatureToggleService.java @@ -88,4 +88,8 @@ public boolean isCaseProgressionEnabled() { public boolean isEarlyAdoptersEnabled() { return featureToggleApi.isFeatureEnabled("early-adopters"); } + + public boolean isSdoR2Enabled() { + return featureToggleApi.isFeatureEnabled("isSdoR2Enabled"); + } } diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/CreateClaimSpecCallbackHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/CreateClaimSpecCallbackHandlerTest.java index c3b3ccad55a..72f96b705a7 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/CreateClaimSpecCallbackHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/CreateClaimSpecCallbackHandlerTest.java @@ -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; @@ -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 { diff --git a/src/test/java/uk/gov/hmcts/reform/civil/service/FeatureToggleServiceTest.java b/src/test/java/uk/gov/hmcts/reform/civil/service/FeatureToggleServiceTest.java index cba681c75a8..764bd837d0b 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/service/FeatureToggleServiceTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/service/FeatureToggleServiceTest.java @@ -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);