Skip to content

Commit

Permalink
SASS-9589: Fix an empty income page when select NOs (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastymo authored Aug 23, 2024
1 parent 1ee625f commit 0da2dbf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
9 changes: 6 additions & 3 deletions app/connectors/IFSConnector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,12 @@ class IFSConnectorImpl @Inject() (http: HttpClient, appConfig: AppConfig) extend
}

def getAnnualSummaries(ctx: JourneyContextWithNino)(implicit hc: HeaderCarrier, ec: ExecutionContext): Future[Api1803Response] = {
val url = annualSummariesUrl(ctx.nino, ctx.businessId, ctx.taxYear)
val context = appConfig.mkMetadata(IFSApiName.Api1803, url)
get[Api1803Response](http, context)
val url = annualSummariesUrl(ctx.nino, ctx.businessId, ctx.taxYear)
val context = appConfig.mkMetadata(IFSApiName.Api1803, url)
implicit val reads: HttpReads[ApiResponse[Option[api_1803.SuccessResponseSchema]]] = commonGetReads[api_1803.SuccessResponseSchema]

val result = EitherT(get[ApiResponseOption[api_1803.SuccessResponseSchema]](http, context))
result.map(_.getOrElse(api_1803.SuccessResponseSchema.empty)).value
}

def getDisclosuresSubmission(
Expand Down
12 changes: 2 additions & 10 deletions app/services/journeyAnswers/NICsAnswersService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ import cats.data.EitherT
import cats.implicits.toFunctorOps
import connectors.{IFSBusinessDetailsConnector, IFSConnector}
import models.common._
import models.connector.api_1171
import models.connector.api_1638.RequestSchemaAPI1638
import models.connector.api_1802.request.CreateAmendSEAnnualSubmissionRequestData
import models.connector.{api_1171, api_1803}
import models.database.nics.NICsStorageAnswers
import models.domain.ApiResultT
import models.error.ServiceError
import models.error.ServiceError.BusinessNotFoundError
import models.frontend.nics.{NICsAnswers, NICsClass2Answers, NICsClass4Answers}
import play.api.http.Status.NOT_FOUND
import play.api.libs.json.Json
import repositories.JourneyAnswersRepository
import uk.gov.hmrc.http.HeaderCarrier
Expand Down Expand Up @@ -67,7 +66,7 @@ class NICsAnswersServiceImpl @Inject() (connector: IFSConnector,
def saveClass4SingleBusiness(ctx: JourneyContextWithNino, answers: NICsClass4Answers)(implicit hc: HeaderCarrier): ApiResultT[Unit] =
for {
updatedContext <- updateJourneyContextWithSingleBusinessId(ctx)
existingAnswers <- getBusinessAnnualSummaryOrMakeNew(updatedContext)
existingAnswers <- EitherT(connector.getAnnualSummaries(updatedContext))
requestBody = CreateAmendSEAnnualSubmissionRequestData.mkNicsClassFourSingleBusinessRequestBody(answers, existingAnswers)
upsertRequest = CreateAmendSEAnnualSubmissionRequestData(ctx.taxYear, ctx.nino, updatedContext.businessId, requestBody)
_ <- EitherT[Future, ServiceError, Unit](connector.createAmendSEAnnualSubmission(upsertRequest))
Expand All @@ -83,13 +82,6 @@ class NICsAnswersServiceImpl @Inject() (connector: IFSConnector,
case Left(error) => Left(error)
})

private def getBusinessAnnualSummaryOrMakeNew(updatedContext: JourneyContextWithNino)(implicit
hc: HeaderCarrier): ApiResultT[api_1803.SuccessResponseSchema] =
EitherT(connector.getAnnualSummaries(updatedContext).map {
case Left(error) if error.status == NOT_FOUND => Right(api_1803.SuccessResponseSchema.empty)
case otherResult => otherResult
})

// TODO SASS-9573 save multiple businesses
// Class 4 MULTIPLE - Save data and Clear changed data
// def saveClass4MultipleBusinesses(ctx: JourneyContextWithNino, answers: NICsClass4Answers)(implicit hc: HeaderCarrier): ApiResultT[Unit] = {
Expand Down
13 changes: 12 additions & 1 deletion it/connectors/IFSConnectorImplISpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ import models.common.TaxYear.{asTys, endDate, startDate}
import models.connector.api_1638.{RequestSchemaAPI1638, RequestSchemaAPI1638Class2Nics}
import models.connector.api_1639.{SuccessResponseAPI1639, SuccessResponseAPI1639Class2Nics}
import models.connector.api_1802.request.{CreateAmendSEAnnualSubmissionRequestBody, CreateAmendSEAnnualSubmissionRequestData}
import models.connector.api_1803.SuccessResponseSchema
import models.connector.api_1894.request._
import models.connector.api_1895.request.{AmendSEPeriodSummaryRequestBody, AmendSEPeriodSummaryRequestData, Incomes}
import models.connector.api_1965.{ListSEPeriodSummariesResponse, PeriodDetails}
import org.scalatest.EitherValues._
import org.scalatest.matchers.should.Matchers.convertToAnyShouldWrapper
import play.api.http.Status.{CREATED, OK}
import play.api.http.Status.{CREATED, NOT_FOUND, OK}
import play.api.libs.json.Json

class IFSConnectorImplISpec extends WiremockSpec with IntegrationBaseSpec {
Expand Down Expand Up @@ -71,6 +72,16 @@ class IFSConnectorImplISpec extends WiremockSpec with IntegrationBaseSpec {

connector.getAnnualSummaries(ctx).futureValue shouldBe successResponse.asRight
}

"return an empty annual summary if not found" in new Api1803Test {
stubGetWithResponseBody(
url = downstreamUrl,
expectedResponse = "{}",
expectedStatus = NOT_FOUND
)

connector.getAnnualSummaries(ctx).futureValue shouldBe SuccessResponseSchema(None, None, None).asRight
}
}

"createSEPeriodSummary" must {
Expand Down

0 comments on commit 0da2dbf

Please sign in to comment.