### Question:
CommonDecoupledPiisService extends CommonDecoupledConsentService<SpiPiisConsent> { @Override protected SpiResponse<SpiAuthorisationDecoupledScaResponse> startScaDecoupled(SpiContextData spiContextData, String authorisationId, String authenticationMethodId, SpiPiisConsent spiConsent, SpiAspspConsentDataProvider spiAspspConsentDataProvider) { return piisConsentSpi.startScaDecoupled(spiContextData, authorisationId, authenticationMethodId, spiConsent, spiAspspConsentDataProvider); } CommonDecoupledPiisService(SpiErrorMapper spiErrorMapper,
                                      SpiAspspConsentDataProviderFactory aspspConsentDataProviderFactory,
                                      SpiContextDataProvider spiContextDataProvider,
                                      Xs2aAuthorisationService authorisationService,
                                      PiisConsentSpi piisConsentSpi);   }### Answer:
@Test void proceedDecoupledApproach_by_request_spiAccountConsent_psuData_success() { when(piisConsentSpi.startScaDecoupled(SPI_CONTEXT_DATA, AUTHORISATION_ID, null, spiPiisConsent, spiAspspConsentDataProvider)) .thenReturn(buildSuccessSpiResponse(new SpiAuthorisationDecoupledScaResponse(PSU_SUCCESS_MESSAGE))); UpdateConsentPsuDataResponse actualResponse = commonDecoupledPiisService.proceedDecoupledApproach(CONSENT_ID, AUTHORISATION_ID, spiPiisConsent, PSU_ID_DATA); assertThat(actualResponse).isEqualTo(UPDATE_CONSENT_PSU_DATA_RESPONSE); }
@Test void proceedDecoupledApproach_Success() { when(piisConsentSpi.startScaDecoupled(SPI_CONTEXT_DATA, AUTHORISATION_ID, AUTHENTICATION_METHOD_ID, spiPiisConsent, spiAspspConsentDataProvider)) .thenReturn(buildSuccessSpiResponse(new SpiAuthorisationDecoupledScaResponse(PSU_SUCCESS_MESSAGE))); UpdateConsentPsuDataResponse actualResponse = commonDecoupledPiisService.proceedDecoupledApproach(CONSENT_ID, AUTHORISATION_ID, spiPiisConsent, AUTHENTICATION_METHOD_ID, PSU_ID_DATA); assertThat(actualResponse).isNotNull(); assertThat(actualResponse.getPsuMessage()).isEqualTo(PSU_SUCCESS_MESSAGE); assertThat(actualResponse.getScaStatus()).isEqualTo(METHOD_SELECTED_SCA_STATUS); }
@Test void proceedDecoupledApproach_Failure_StartScaDecoupledHasError() { when(piisConsentSpi.startScaDecoupled(SPI_CONTEXT_DATA, AUTHORISATION_ID, AUTHENTICATION_METHOD_ID, spiPiisConsent, spiAspspConsentDataProvider)) .thenReturn(buildErrorSpiResponse(new SpiAuthorisationDecoupledScaResponse(PSU_ERROR_MESSAGE))); when(spiErrorMapper.mapToErrorHolder(buildErrorSpiResponse(new SpiAuthorisationDecoupledScaResponse(PSU_ERROR_MESSAGE)), ServiceType.PIIS)) .thenReturn(ErrorHolder .builder(ErrorType.AIS_400) .tppMessages(TppMessageInformation.of(MessageErrorCode.FORMAT_ERROR)) .build()); UpdateConsentPsuDataResponse actualResponse = commonDecoupledPiisService.proceedDecoupledApproach(CONSENT_ID, AUTHORISATION_ID, spiPiisConsent, AUTHENTICATION_METHOD_ID, PSU_ID_DATA); assertThat(actualResponse).isNotNull(); assertThat(actualResponse.getScaStatus()).isEqualTo(FAILED_SCA_STATUS); assertThat(actualResponse.getErrorHolder().getErrorType()).isEqualTo(ErrorType.AIS_400); }