From 308bbde2bb3b1bd1a3a9fc80b84875ab2c3bbfa2 Mon Sep 17 00:00:00 2001 From: Arun Kumar Madesh <56151567+arunkumar461@users.noreply.github.com> Date: Wed, 15 May 2024 12:04:48 +0100 Subject: [PATCH 1/2] fix tax year specific api 1944 --- .../IntegrationFrameworkConnector.scala | 12 ++++++--- conf/application.conf | 1 + .../IntegrationFrameworkConnectorISpec.scala | 25 ++++++++++++++++--- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/app/connectors/IntegrationFrameworkConnector.scala b/app/connectors/IntegrationFrameworkConnector.scala index 8f5d6bc..e2c2cfe 100644 --- a/app/connectors/IntegrationFrameworkConnector.scala +++ b/app/connectors/IntegrationFrameworkConnector.scala @@ -21,7 +21,7 @@ import connectors.errors.ApiError import connectors.responses._ import models.api.{AddStateBenefit, AllStateBenefitsData, StateBenefitDetailOverride, UpdateStateBenefit} import services.PagerDutyLoggerService -import uk.gov.hmrc.http.{HeaderCarrier, HttpClient} +import uk.gov.hmrc.http.{HeaderCarrier, HttpClient, StringContextOps} import java.net.URL import java.util.UUID @@ -43,6 +43,7 @@ class IntegrationFrameworkConnector @Inject()(httpClient: HttpClient, private val deleteApiVersion = "1678" private val deleteApi2324Version = "1796" private val ignoreApiVersion = "1679" + private val ignoreApi2324Version = "1944" private val unIgnoreApiVersion = "1700" override protected[connectors] val appConfig: AppConfig = appConf @@ -130,8 +131,13 @@ class IntegrationFrameworkConnector @Inject()(httpClient: HttpClient, nino: String, benefitId: UUID) (implicit hc: HeaderCarrier): Future[Either[ApiError, Unit]] = { - val url = new URL(s"$baseUrl/income-tax/income/state-benefits/$nino/${toTaxYearParam(taxYear)}/ignore/$benefitId") - val eventualResponse = callIgnoreStateBenefit(url)(ifHeaderCarrier(url, ignoreApiVersion)) + + val (url, apiVersion) = if (isAfter2324Api(taxYear)) { + (url"$baseUrl/income-tax/${asTys(taxYear)}/income/state-benefits/$nino/ignore/$benefitId", ignoreApi2324Version) + } else { + (url"$baseUrl/income-tax/income/state-benefits/$nino/${toTaxYearParam(taxYear)}/ignore/$benefitId", ignoreApiVersion) + } + val eventualResponse = callIgnoreStateBenefit(url)(ifHeaderCarrier(url, apiVersion)) eventualResponse.map { apiResponse: IgnoreStateBenefitResponse => if (apiResponse.result.isLeft) pagerDutyLoggerService.pagerDutyLog(apiResponse.httpResponse, apiResponse.getClass.getSimpleName) diff --git a/conf/application.conf b/conf/application.conf index 65ae93e..41012ca 100644 --- a/conf/application.conf +++ b/conf/application.conf @@ -96,6 +96,7 @@ microservice { 1796 = "secret" 1938 = "secret" 1937 = "secret" + 1944 = "secret" } port = 9303 #This is the port for the income-tax-submission-stub diff --git a/it/test/connectors/IntegrationFrameworkConnectorISpec.scala b/it/test/connectors/IntegrationFrameworkConnectorISpec.scala index 11e06c7..4861920 100644 --- a/it/test/connectors/IntegrationFrameworkConnectorISpec.scala +++ b/it/test/connectors/IntegrationFrameworkConnectorISpec.scala @@ -232,10 +232,10 @@ class IntegrationFrameworkConnectorISpec extends ConnectorIntegrationTest } ".ignoreStateBenefit" should { + val taxYearBefore24 = 2023 "return correct IF response when correct parameters are passed" in { val httpResponse = HttpResponse(CREATED, "") - - stubPutHttpClientCall(s"/if/income-tax/income/state-benefits/$nino/${toTaxYearParameter(taxYear)}/ignore/$benefitId", "{}", httpResponse) + stubPutHttpClientCall(s"/if/income-tax/${asTys(taxYear)}/income/state-benefits/$nino/ignore/$benefitId", "{}", httpResponse) await(underTest.ignoreStateBenefit(taxYear, nino, benefitId)(hc)) shouldBe Right(()) } @@ -245,11 +245,30 @@ class IntegrationFrameworkConnectorISpec extends ConnectorIntegrationTest (pagerDutyLoggerService.pagerDutyLog _).expects(*, "IgnoreStateBenefitResponse") - stubPutHttpClientCall(s"/if/income-tax/income/state-benefits/$nino/${toTaxYearParameter(taxYear)}/ignore/$benefitId", "{}", httpResponse) + stubPutHttpClientCall(s"/if/income-tax/${asTys(taxYear)}/income/state-benefits/$nino/ignore/$benefitId", "{}", httpResponse) await(underTest.ignoreStateBenefit(taxYear, nino, benefitId)(hc)) shouldBe Left(ApiError(INTERNAL_SERVER_ERROR, SingleErrorBody("some-code", "some-reason"))) } + + "return correct IF response when correct parameters are passed before 23-24" in { + val httpResponse = HttpResponse(CREATED, "") + + stubPutHttpClientCall(s"/if/income-tax/income/state-benefits/$nino/${toTaxYearParameter(taxYearBefore24)}/ignore/$benefitId", "{}", httpResponse) + + await(underTest.ignoreStateBenefit(taxYearBefore24, nino, benefitId)(hc)) shouldBe Right(()) + } + + "return IF error and perform a pagerDutyLog when Left is returned before 23-24" in { + val httpResponse = HttpResponse(INTERNAL_SERVER_ERROR, Json.toJson(SingleErrorBody("some-code", "some-reason")).toString()) + + (pagerDutyLoggerService.pagerDutyLog _).expects(*, "IgnoreStateBenefitResponse") + + stubPutHttpClientCall(s"/if/income-tax/income/state-benefits/$nino/${toTaxYearParameter(taxYearBefore24)}/ignore/$benefitId", "{}", httpResponse) + + await(underTest.ignoreStateBenefit(taxYearBefore24, nino, benefitId)(hc)) shouldBe + Left(ApiError(INTERNAL_SERVER_ERROR, SingleErrorBody("some-code", "some-reason"))) + } } ".unIgnoreStateBenefit" should { From e6f7b14ddf6a7b3fcfa3d1bc1f7eb11ef1301fa0 Mon Sep 17 00:00:00 2001 From: Arun Kumar Madesh <56151567+arunkumar461@users.noreply.github.com> Date: Wed, 15 May 2024 13:08:16 +0100 Subject: [PATCH 2/2] fix tax year specific api 1945 --- .../IntegrationFrameworkConnector.scala | 10 ++++++-- conf/application.conf | 1 + .../IntegrationFrameworkConnectorISpec.scala | 24 +++++++++++++++++-- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/app/connectors/IntegrationFrameworkConnector.scala b/app/connectors/IntegrationFrameworkConnector.scala index e2c2cfe..195ccb7 100644 --- a/app/connectors/IntegrationFrameworkConnector.scala +++ b/app/connectors/IntegrationFrameworkConnector.scala @@ -45,6 +45,7 @@ class IntegrationFrameworkConnector @Inject()(httpClient: HttpClient, private val ignoreApiVersion = "1679" private val ignoreApi2324Version = "1944" private val unIgnoreApiVersion = "1700" + private val unIgnoreApi2324Version = "1945" override protected[connectors] val appConfig: AppConfig = appConf @@ -149,8 +150,13 @@ class IntegrationFrameworkConnector @Inject()(httpClient: HttpClient, nino: String, benefitId: UUID) (implicit hc: HeaderCarrier): Future[Either[ApiError, Unit]] = { - val url = new URL(s"$baseUrl/income-tax/state-benefits/$nino/${toTaxYearParam(taxYear)}/ignore/$benefitId") - val eventualResponse = callUnIgnoreStateBenefit(url)(ifHeaderCarrier(url, unIgnoreApiVersion)) + + val (url, apiVersion) = if (isAfter2324Api(taxYear)) { + (url"$baseUrl/income-tax/${asTys(taxYear)}/state-benefits/$nino/ignore/$benefitId", unIgnoreApi2324Version) + } else { + (url"$baseUrl/income-tax/state-benefits/$nino/${toTaxYearParam(taxYear)}/ignore/$benefitId", unIgnoreApiVersion) + } + val eventualResponse = callUnIgnoreStateBenefit(url)(ifHeaderCarrier(url, apiVersion)) eventualResponse.map { apiResponse: UnIgnoreStateBenefitResponse => if (apiResponse.result.isLeft) pagerDutyLoggerService.pagerDutyLog(apiResponse.httpResponse, apiResponse.getClass.getSimpleName) diff --git a/conf/application.conf b/conf/application.conf index 41012ca..f179149 100644 --- a/conf/application.conf +++ b/conf/application.conf @@ -97,6 +97,7 @@ microservice { 1938 = "secret" 1937 = "secret" 1944 = "secret" + 1945 = "secret" } port = 9303 #This is the port for the income-tax-submission-stub diff --git a/it/test/connectors/IntegrationFrameworkConnectorISpec.scala b/it/test/connectors/IntegrationFrameworkConnectorISpec.scala index 4861920..916060a 100644 --- a/it/test/connectors/IntegrationFrameworkConnectorISpec.scala +++ b/it/test/connectors/IntegrationFrameworkConnectorISpec.scala @@ -272,10 +272,11 @@ class IntegrationFrameworkConnectorISpec extends ConnectorIntegrationTest } ".unIgnoreStateBenefit" should { + val taxYearBefore24 = 2023 "return correct IF response when correct parameters are passed" in { val httpResponse = HttpResponse(NO_CONTENT, "") - stubDeleteHttpClientCall(s"/if/income-tax/state-benefits/$nino/${toTaxYearParameter(taxYear)}/ignore/$benefitId", httpResponse) + stubDeleteHttpClientCall(s"/if/income-tax/${asTys(taxYear)}/state-benefits/$nino/ignore/$benefitId", httpResponse) await(underTest.unIgnoreStateBenefit(taxYear, nino, benefitId)(hc)) shouldBe Right(()) } @@ -285,10 +286,29 @@ class IntegrationFrameworkConnectorISpec extends ConnectorIntegrationTest (pagerDutyLoggerService.pagerDutyLog _).expects(*, "UnIgnoreStateBenefitResponse") - stubDeleteHttpClientCall(s"/if/income-tax/state-benefits/$nino/${toTaxYearParameter(taxYear)}/ignore/$benefitId", httpResponse) + stubDeleteHttpClientCall(s"/if/income-tax/${asTys(taxYear)}/state-benefits/$nino/ignore/$benefitId", httpResponse) await(underTest.unIgnoreStateBenefit(taxYear, nino, benefitId)(hc)) shouldBe Left(ApiError(INTERNAL_SERVER_ERROR, SingleErrorBody("some-code", "some-reason"))) } + + "return correct IF response when correct parameters are passed before 23-24" in { + val httpResponse = HttpResponse(NO_CONTENT, "") + + stubDeleteHttpClientCall(s"/if/income-tax/state-benefits/$nino/${toTaxYearParameter(taxYearBefore24)}/ignore/$benefitId", httpResponse) + + await(underTest.unIgnoreStateBenefit(taxYearBefore24, nino, benefitId)(hc)) shouldBe Right(()) + } + + "return IF error and perform a pagerDutyLog when Left is returned before 23-24" in { + val httpResponse = HttpResponse(INTERNAL_SERVER_ERROR, Json.toJson(SingleErrorBody("some-code", "some-reason")).toString()) + + (pagerDutyLoggerService.pagerDutyLog _).expects(*, "UnIgnoreStateBenefitResponse") + + stubDeleteHttpClientCall(s"/if/income-tax/state-benefits/$nino/${toTaxYearParameter(taxYearBefore24)}/ignore/$benefitId", httpResponse) + + await(underTest.unIgnoreStateBenefit(taxYearBefore24, nino, benefitId)(hc)) shouldBe + Left(ApiError(INTERNAL_SERVER_ERROR, SingleErrorBody("some-code", "some-reason"))) + } } }