Skip to content

Commit

Permalink
Merge pull request #47 from hmrc/SASS-8260
Browse files Browse the repository at this point in the history
SASS-8260:  Create Tax Year specific implementation for 1700 => 1945 state-benefits
  • Loading branch information
vivekhmrc authored May 15, 2024
2 parents 060066d + e6f7b14 commit 1e7befe
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 10 deletions.
22 changes: 17 additions & 5 deletions app/connectors/IntegrationFrameworkConnector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -43,7 +43,9 @@ 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"
private val unIgnoreApi2324Version = "1945"

override protected[connectors] val appConfig: AppConfig = appConf

Expand Down Expand Up @@ -130,8 +132,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)
Expand All @@ -143,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)
Expand Down
2 changes: 2 additions & 0 deletions conf/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ microservice {
1796 = "secret"
1938 = "secret"
1937 = "secret"
1944 = "secret"
1945 = "secret"
}
port = 9303
#This is the port for the income-tax-submission-stub
Expand Down
49 changes: 44 additions & 5 deletions it/test/connectors/IntegrationFrameworkConnectorISpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand All @@ -245,18 +245,38 @@ 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 {
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(())
}
Expand All @@ -266,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")))
}
}
}

0 comments on commit 1e7befe

Please sign in to comment.