From 42847da839fc69f3bd7e0ac795cff4ee93f2bbe5 Mon Sep 17 00:00:00 2001 From: Yuriy Tumakha Date: Wed, 23 Oct 2024 16:33:20 +0100 Subject: [PATCH] BST-109988 6048 - Added page "Occupation and accounting CYA". Used new model `TurnoverSection6048` in accounting info controllers (#1056) * BST-109988 6048 - Add page "Occupation and accounting CYA". Used new model `TurnoverSection6048` in accounting info controllers. * BST-109988 6048 - Add page "Occupation and accounting CYA". Used new model `TurnoverSection6048` in accounting info controllers. * BST-109988 6048 - Add page "Occupation and accounting CYA". Used new model `TurnoverSection6048` in accounting info controllers. * BST-109988 6048 - Add page "Occupation and accounting CYA". Used new model `TurnoverSection6048` in accounting info controllers. * BST-109988 6048 - Add page "Occupation and accounting CYA". Used new model `TurnoverSection6048` in accounting info controllers. --- .../AboutYourTradingHistoryController.scala | 3 +- .../EditFinancialYearEndDateController.scala | 42 ++++++++++++++++ .../FinancialYearEndController.scala | 12 +++++ ...nancialYearEndDatesSummaryController.scala | 5 ++ app/models/Session.scala | 5 ++ .../AboutTheTradingHistoryPartOne.scala | 1 + .../TurnoverSection6048.scala | 35 +++++++++++++ .../AboutTheTradingHistoryNavigator.scala | 25 +++++----- app/util/AccountingInformationUtil.scala | 45 +++++++++++++++++ .../financialYearEndDatesSummary.scala.html | 1 + .../financialYears.scala.html | 3 +- .../answersAboutYourTradingHistory.scala.html | 14 ++++-- ...boutYourTradingHistoryControllerSpec.scala | 39 +++++++++++++-- ...AboutTheTradingHistoryControllerSpec.scala | 13 +++++ ...itFinancialYearEndDateControllerSpec.scala | 39 +++++++++++++++ .../FinancialYearEndControllerSpec.scala | 22 +++++++++ ...ialYearEndDatesSummaryControllerSpec.scala | 48 ++++++++++++++++++ .../FinancialYearsControllerSpec.scala | 49 +++++++++++++++++++ test/utils/FakeObjects.scala | 49 +++++++++++++++++-- test/utils/TestBaseSpec.scala | 9 ++++ 20 files changed, 434 insertions(+), 25 deletions(-) create mode 100644 app/models/submissions/aboutthetradinghistory/TurnoverSection6048.scala diff --git a/app/controllers/aboutthetradinghistory/AboutYourTradingHistoryController.scala b/app/controllers/aboutthetradinghistory/AboutYourTradingHistoryController.scala index 4f8aaceb9..fad068982 100644 --- a/app/controllers/aboutthetradinghistory/AboutYourTradingHistoryController.scala +++ b/app/controllers/aboutthetradinghistory/AboutYourTradingHistoryController.scala @@ -84,7 +84,8 @@ class AboutYourTradingHistoryController @Inject() ( && ( newFinancialYears(occupationAndAccounting) == previousFinancialYears || newFinancialYears(occupationAndAccounting) == previousFinancialYears6076 || - newFinancialYears(occupationAndAccounting) == previousFinancialYears6045 + newFinancialYears(occupationAndAccounting) == previousFinancialYears6045 || + newFinancialYears(occupationAndAccounting) == previousFinancialYears6048 ) ) .getOrElse(navigator.nextPage(AboutYourTradingHistoryPageId, updatedData).apply(updatedData)) diff --git a/app/controllers/aboutthetradinghistory/EditFinancialYearEndDateController.scala b/app/controllers/aboutthetradinghistory/EditFinancialYearEndDateController.scala index b6e16a28c..08f262e4f 100644 --- a/app/controllers/aboutthetradinghistory/EditFinancialYearEndDateController.scala +++ b/app/controllers/aboutthetradinghistory/EditFinancialYearEndDateController.scala @@ -58,6 +58,10 @@ class EditFinancialYearEndDateController @Inject() ( request.sessionData.aboutTheTradingHistoryPartOne .flatMap(_.turnoverSections6045) .fold(Seq.empty[LocalDate])(_.map(_.financialYearEnd)) + case FOR6048 => + request.sessionData.aboutTheTradingHistoryPartOne + .flatMap(_.turnoverSections6048) + .fold(Seq.empty[LocalDate])(_.map(_.financialYearEnd)) case FOR6076 => request.sessionData.aboutTheTradingHistoryPartOne .flatMap(_.turnoverSections6076) @@ -82,6 +86,8 @@ class EditFinancialYearEndDateController @Inject() ( case FOR6030 => aboutTheTradingHistory.turnoverSections6030.nonEmpty case FOR6045 | FOR6046 => request.sessionData.aboutTheTradingHistoryPartOne.flatMap(_.turnoverSections6045).exists(_.nonEmpty) + case FOR6048 => + request.sessionData.aboutTheTradingHistoryPartOne.flatMap(_.turnoverSections6048).exists(_.nonEmpty) case FOR6076 => request.sessionData.aboutTheTradingHistoryPartOne.flatMap(_.turnoverSections6076).exists(_.nonEmpty) case _ => aboutTheTradingHistory.turnoverSections.nonEmpty @@ -99,6 +105,10 @@ class EditFinancialYearEndDateController @Inject() ( request.sessionData.aboutTheTradingHistoryPartOne .flatMap(_.turnoverSections6045) .fold(Seq.empty[LocalDate])(_.map(_.financialYearEnd)) + case FOR6048 => + request.sessionData.aboutTheTradingHistoryPartOne + .flatMap(_.turnoverSections6048) + .fold(Seq.empty[LocalDate])(_.map(_.financialYearEnd)) case FOR6076 => request.sessionData.aboutTheTradingHistoryPartOne .flatMap(_.turnoverSections6076) @@ -136,6 +146,7 @@ class EditFinancialYearEndDateController @Inject() ( case FOR6030 => buildUpdateData6030(aboutTheTradingHistory, index, data, newOccupationAndAccounting) case FOR6045 | FOR6046 => buildUpdatedData6045(index, data, newOccupationAndAccounting) + case FOR6048 => buildUpdatedData6048(index, data, newOccupationAndAccounting) case FOR6076 => buildUpdatedData6076(index, data, newOccupationAndAccounting) case _ => buildUpdateData(aboutTheTradingHistory, index, data, newOccupationAndAccounting) } @@ -166,6 +177,11 @@ class EditFinancialYearEndDateController @Inject() ( .flatMap(_.turnoverSections6045) .flatMap(_.headOption) .exists(_.grossReceiptsCaravanFleetHire.isDefined) + case FOR6048 => + request.sessionData.aboutTheTradingHistoryPartOne + .flatMap(_.turnoverSections6048) + .flatMap(_.headOption) + .exists(_.income.isDefined) case FOR6076 => request.sessionData.aboutTheTradingHistoryPartOne .flatMap(_.turnoverSections6076) @@ -267,6 +283,32 @@ class EditFinancialYearEndDateController @Inject() ( ) } + private def buildUpdatedData6048( + index: Int, + data: LocalDate, + newOccupationAndAccounting: OccupationalAndAccountingInformation + )(implicit request: SessionRequest[AnyContent]): Session = { + val turnoverSections6048 = + request.sessionData.aboutTheTradingHistoryPartOne.flatMap(_.turnoverSections6048).getOrElse(Seq.empty) + val updatedTurnoverSections = turnoverSections6048.updated( + index, + turnoverSections6048(index).copy(financialYearEnd = data) + ) + + val updatedData = updateAboutTheTradingHistory( + _.copy( + occupationAndAccountingInformation = Some(newOccupationAndAccounting) + ) + ) + updatedData.copy( + aboutTheTradingHistoryPartOne = Some( + updatedData.aboutTheTradingHistoryPartOne + .getOrElse(AboutTheTradingHistoryPartOne()) + .copy(turnoverSections6048 = Some(updatedTurnoverSections)) + ) + ) + } + private def buildUpdatedData6076( index: Int, data: LocalDate, diff --git a/app/controllers/aboutthetradinghistory/FinancialYearEndController.scala b/app/controllers/aboutthetradinghistory/FinancialYearEndController.scala index 8f6b01756..f095ecf82 100644 --- a/app/controllers/aboutthetradinghistory/FinancialYearEndController.scala +++ b/app/controllers/aboutthetradinghistory/FinancialYearEndController.scala @@ -107,6 +107,12 @@ class FinancialYearEndController @Inject() ( newOccupationAndAccounting, isFinancialYearEndDayUnchanged ) + case FOR6048 => + buildUpdatedData6048( + aboutTheTradingHistory, + newOccupationAndAccounting, + isFinancialYearEndDayUnchanged + ) case FOR6076 => buildUpdatedData6076( aboutTheTradingHistory, @@ -140,6 +146,12 @@ class FinancialYearEndController @Inject() ( .flatMap(_.turnoverSections6045) .flatMap(_.headOption) .exists(_.grossReceiptsCaravanFleetHire.isDefined) + ) || ( + request.sessionData.forType == FOR6048 && + request.sessionData.aboutTheTradingHistoryPartOne + .flatMap(_.turnoverSections6048) + .flatMap(_.headOption) + .exists(_.income.isDefined) )) ) .getOrElse(navigator.nextPage(FinancialYearEndPageId, updatedData).apply(updatedData)) diff --git a/app/controllers/aboutthetradinghistory/FinancialYearEndDatesSummaryController.scala b/app/controllers/aboutthetradinghistory/FinancialYearEndDatesSummaryController.scala index cf83a5314..d1650fec3 100644 --- a/app/controllers/aboutthetradinghistory/FinancialYearEndDatesSummaryController.scala +++ b/app/controllers/aboutthetradinghistory/FinancialYearEndDatesSummaryController.scala @@ -106,6 +106,11 @@ class FinancialYearEndDatesSummaryController @Inject() ( .flatMap(_.turnoverSections6045) .flatMap(_.headOption) .exists(_.grossReceiptsCaravanFleetHire.isDefined) + case FOR6048 => + request.sessionData.aboutTheTradingHistoryPartOne + .flatMap(_.turnoverSections6048) + .flatMap(_.headOption) + .exists(_.income.isDefined) case FOR6076 => request.sessionData.aboutTheTradingHistoryPartOne .flatMap(_.turnoverSections6076) diff --git a/app/models/Session.scala b/app/models/Session.scala index d77f2e451..2cf6dfdbf 100644 --- a/app/models/Session.scala +++ b/app/models/Session.scala @@ -81,6 +81,11 @@ case class Session( .flatMap(_.turnoverSections6045) .fold(Seq.empty[(LocalDate, Int)])(_.map(_.financialYearEnd).zipWithIndex) + def financialYearEndDates6048: Seq[(LocalDate, Int)] = + aboutTheTradingHistoryPartOne + .flatMap(_.turnoverSections6048) + .fold(Seq.empty[(LocalDate, Int)])(_.map(_.financialYearEnd).zipWithIndex) + def financialYearEndDates6076: Seq[(LocalDate, Int)] = aboutTheTradingHistoryPartOne .flatMap(_.turnoverSections6076) diff --git a/app/models/submissions/aboutthetradinghistory/AboutTheTradingHistoryPartOne.scala b/app/models/submissions/aboutthetradinghistory/AboutTheTradingHistoryPartOne.scala index 83332f1a9..74877fe79 100644 --- a/app/models/submissions/aboutthetradinghistory/AboutTheTradingHistoryPartOne.scala +++ b/app/models/submissions/aboutthetradinghistory/AboutTheTradingHistoryPartOne.scala @@ -41,6 +41,7 @@ case class AboutTheTradingHistoryPartOne( additionalMiscDetails: Option[AdditionalMiscDetails] = None, fromCYA: Option[Boolean] = None, // 6048 + turnoverSections6048: Option[Seq[TurnoverSection6048]] = None, areYouVATRegistered: Option[AnswersYesNo] = None ) diff --git a/app/models/submissions/aboutthetradinghistory/TurnoverSection6048.scala b/app/models/submissions/aboutthetradinghistory/TurnoverSection6048.scala new file mode 100644 index 000000000..535ad12a5 --- /dev/null +++ b/app/models/submissions/aboutthetradinghistory/TurnoverSection6048.scala @@ -0,0 +1,35 @@ +/* + * Copyright 2024 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package models.submissions.aboutthetradinghistory + +import play.api.libs.json.{Json, OFormat} + +import java.time.LocalDate + +/** + * 6048 Trading history. + * + * @author Yuriy Tumakha + */ +case class TurnoverSection6048( + financialYearEnd: LocalDate, + income: Option[BigDecimal] = None // TODO: replace with income: Option[Income6048] = None +) + +object TurnoverSection6048 { + implicit val format: OFormat[TurnoverSection6048] = Json.format +} diff --git a/app/navigation/AboutTheTradingHistoryNavigator.scala b/app/navigation/AboutTheTradingHistoryNavigator.scala index db17944e0..9bded7e12 100644 --- a/app/navigation/AboutTheTradingHistoryNavigator.scala +++ b/app/navigation/AboutTheTradingHistoryNavigator.scala @@ -88,18 +88,18 @@ class AboutTheTradingHistoryNavigator @Inject() (audit: Audit) extends Navigator s.aboutTheTradingHistory.flatMap(_.occupationAndAccountingInformation.flatMap(_.yearEndChanged)) match { case Some(true) => s.forType match { - case FOR6020 | FOR6045 | FOR6046 | FOR6076 => + case FOR6020 | FOR6045 | FOR6046 | FOR6048 | FOR6076 => aboutthetradinghistory.routes.FinancialYearEndDatesSummaryController.show() - case _ => aboutthetradinghistory.routes.FinancialYearEndDatesController.show() + case _ => aboutthetradinghistory.routes.FinancialYearEndDatesController.show() } case _ => s.forType match { - case FOR6020 => aboutthetradinghistory.routes.TotalFuelSoldController.show() - case FOR6030 => aboutthetradinghistory.routes.Turnover6030Controller.show() - case FOR6045 | FOR6046 => aboutthetradinghistory.routes.FinancialYearsController.show - case FOR6076 => aboutthetradinghistory.routes.ElectricityGeneratedController.show() - case _ => aboutthetradinghistory.routes.TurnoverController.show() + case FOR6020 => aboutthetradinghistory.routes.TotalFuelSoldController.show() + case FOR6030 => aboutthetradinghistory.routes.Turnover6030Controller.show() + case FOR6045 | FOR6046 | FOR6048 => aboutthetradinghistory.routes.FinancialYearsController.show + case FOR6076 => aboutthetradinghistory.routes.ElectricityGeneratedController.show() + case _ => aboutthetradinghistory.routes.TurnoverController.show() } } } @@ -117,11 +117,11 @@ class AboutTheTradingHistoryNavigator @Inject() (audit: Audit) extends Navigator private def financialYearEndDatesRouting: Session => Call = _.forType match { - case FOR6020 => aboutthetradinghistory.routes.TotalFuelSoldController.show() - case FOR6030 => aboutthetradinghistory.routes.Turnover6030Controller.show() - case FOR6045 | FOR6046 => aboutthetradinghistory.routes.FinancialYearsController.show - case FOR6076 => aboutthetradinghistory.routes.ElectricityGeneratedController.show() - case _ => aboutthetradinghistory.routes.TurnoverController.show() + case FOR6020 => aboutthetradinghistory.routes.TotalFuelSoldController.show() + case FOR6030 => aboutthetradinghistory.routes.Turnover6030Controller.show() + case FOR6045 | FOR6046 | FOR6048 => aboutthetradinghistory.routes.FinancialYearsController.show + case FOR6076 => aboutthetradinghistory.routes.ElectricityGeneratedController.show() + case _ => aboutthetradinghistory.routes.TurnoverController.show() } private def financialYearsRouting: Session => Call = @@ -129,6 +129,7 @@ class AboutTheTradingHistoryNavigator @Inject() (audit: Audit) extends Navigator case FOR6020 => aboutthetradinghistory.routes.TotalFuelSoldController.show() case FOR6030 => aboutthetradinghistory.routes.Turnover6030Controller.show() case FOR6045 | FOR6046 => aboutthetradinghistory.routes.StaticCaravansController.show() + case FOR6048 => aboutthetradinghistory.routes.StaticCaravansController.show() // TODO: Income6048Controller case FOR6076 => aboutthetradinghistory.routes.ElectricityGeneratedController.show() case _ => aboutthetradinghistory.routes.TurnoverController.show() } diff --git a/app/util/AccountingInformationUtil.scala b/app/util/AccountingInformationUtil.scala index a74b32c30..97e47708c 100644 --- a/app/util/AccountingInformationUtil.scala +++ b/app/util/AccountingInformationUtil.scala @@ -64,6 +64,11 @@ object AccountingInformationUtil { .flatMap(_.turnoverSections6045) .fold(Seq.empty[Int])(_.map(_.financialYearEnd.getYear)) + def previousFinancialYears6048(implicit request: SessionRequest[AnyContent]): Seq[Int] = + request.sessionData.aboutTheTradingHistoryPartOne + .flatMap(_.turnoverSections6048) + .fold(Seq.empty[Int])(_.map(_.financialYearEnd.getYear)) + def previousFinancialYears6076(implicit request: SessionRequest[AnyContent]): Seq[Int] = request.sessionData.aboutTheTradingHistoryPartOne .flatMap(_.turnoverSections6076) @@ -113,6 +118,46 @@ object AccountingInformationUtil { ) } + def buildUpdatedData6048( + aboutTheTradingHistory: AboutTheTradingHistory, + newOccupationAndAccounting: OccupationalAndAccountingInformation, + isFinancialYearEndDayUnchanged: Boolean + )(implicit request: SessionRequest[AnyContent]): Session = { + + val firstOccupy = newOccupationAndAccounting.firstOccupy + val financialYear = newOccupationAndAccounting.financialYear.get + val originalTurnoverSections6048 = + request.sessionData.aboutTheTradingHistoryPartOne.flatMap(_.turnoverSections6048).getOrElse(Seq.empty) + val isFinancialYearsListUnchanged = newFinancialYears(newOccupationAndAccounting) == previousFinancialYears6048 + + val turnoverSections6048 = + if isFinancialYearEndDayUnchanged && isFinancialYearsListUnchanged then originalTurnoverSections6048 + else if isFinancialYearsListUnchanged then + (originalTurnoverSections6048 zip financialYearsRequired(firstOccupy, financialYear)).map { + case (turnoverSection, finYearEnd) => turnoverSection.copy(financialYearEnd = finYearEnd) + } + else + financialYearsRequired(firstOccupy, financialYear).map { finYearEnd => + TurnoverSection6048(financialYearEnd = finYearEnd) + } + + val updatedData = updateAboutTheTradingHistory( + _.copy( + occupationAndAccountingInformation = Some(newOccupationAndAccounting), + checkYourAnswersAboutTheTradingHistory = sectionCompleted(isFinancialYearsListUnchanged, aboutTheTradingHistory) + ) + ) + updatedData.copy( + aboutTheTradingHistoryPartOne = Some( + updatedData.aboutTheTradingHistoryPartOne + .getOrElse(AboutTheTradingHistoryPartOne()) + .copy( + turnoverSections6048 = Some(turnoverSections6048) + ) + ) + ) + } + def buildUpdatedData6076( aboutTheTradingHistory: AboutTheTradingHistory, newOccupationAndAccounting: OccupationalAndAccountingInformation, diff --git a/app/views/aboutthetradinghistory/financialYearEndDatesSummary.scala.html b/app/views/aboutthetradinghistory/financialYearEndDatesSummary.scala.html index 838ea9724..b957fa437 100644 --- a/app/views/aboutthetradinghistory/financialYearEndDatesSummary.scala.html +++ b/app/views/aboutthetradinghistory/financialYearEndDatesSummary.scala.html @@ -45,6 +45,7 @@ case FOR6020 => aboutTheTradingHistory.turnoverSections6020.getOrElse(Seq.empty).map(_.financialYearEnd) case FOR6030 => aboutTheTradingHistory.turnoverSections6030.map(_.financialYearEnd) case FOR6045 | FOR6046 => request.sessionData.aboutTheTradingHistoryPartOne.flatMap(_.turnoverSections6045).fold(Seq.empty[LocalDate])(_.map(_.financialYearEnd)) + case FOR6048 => request.sessionData.aboutTheTradingHistoryPartOne.flatMap(_.turnoverSections6048).fold(Seq.empty[LocalDate])(_.map(_.financialYearEnd)) case FOR6076 => request.sessionData.aboutTheTradingHistoryPartOne.flatMap(_.turnoverSections6076).fold(Seq.empty[LocalDate])(_.map(_.financialYearEnd)) case _ => aboutTheTradingHistory.turnoverSections.map(_.financialYearEnd) } diff --git a/app/views/aboutthetradinghistory/financialYears.scala.html b/app/views/aboutthetradinghistory/financialYears.scala.html index 93f300f23..58542ce29 100644 --- a/app/views/aboutthetradinghistory/financialYears.scala.html +++ b/app/views/aboutthetradinghistory/financialYears.scala.html @@ -69,6 +69,7 @@ case FOR6020 => aboutTheTradingHistory.turnoverSections6020.getOrElse(Seq.empty).map(_.financialYearEnd) case FOR6030 => aboutTheTradingHistory.turnoverSections6030.map(_.financialYearEnd) case FOR6045 | FOR6046 => request.sessionData.financialYearEndDates6045.map(_._1) + case FOR6048 => request.sessionData.financialYearEndDates6048.map(_._1) case FOR6076 => request.sessionData.financialYearEndDates6076.map(_._1) case _ => aboutTheTradingHistory.turnoverSections.map(_.financialYearEnd) } @@ -144,7 +145,7 @@ Seq( ActionItem( href = forType match { - case FOR6020 | FOR6045 | FOR6046 | FOR6076 => + case FOR6020 | FOR6045 | FOR6046 | FOR6048 | FOR6076 => aboutthetradinghistory.routes.FinancialYearEndDatesSummaryController.show().url case _ => aboutthetradinghistory.routes.FinancialYearEndDatesController.show().url }, diff --git a/app/views/answers/answersAboutYourTradingHistory.scala.html b/app/views/answers/answersAboutYourTradingHistory.scala.html index 20f93900f..55e34f2a6 100644 --- a/app/views/answers/answersAboutYourTradingHistory.scala.html +++ b/app/views/answers/answersAboutYourTradingHistory.scala.html @@ -28,6 +28,7 @@ @import models.submissions.aboutthetradinghistory.TurnoverSection6020 @import models.submissions.aboutthetradinghistory.TurnoverSection6030 @import models.submissions.aboutthetradinghistory.TurnoverSection6045 +@import models.submissions.aboutthetradinghistory.TurnoverSection6048 @import models.submissions.aboutthetradinghistory.TurnoverSection6076 @import models.submissions.aboutthetradinghistory.VariableOperatingExpensesSections @import util.DateUtilLocalised @@ -112,6 +113,7 @@ case FOR6020 => aboutTheTradingHistory.turnoverSections6020.getOrElse(Seq.empty).map(_.financialYearEnd) case FOR6030 => aboutTheTradingHistory.turnoverSections6030.map(_.financialYearEnd) case FOR6045 | FOR6046 => request.sessionData.financialYearEndDates6045.map(_._1) + case FOR6048 => request.sessionData.financialYearEndDates6048.map(_._1) case FOR6076 => request.sessionData.financialYearEndDates6076.map(_._1) case _ => aboutTheTradingHistory.turnoverSections.map(_.financialYearEnd) } @@ -487,6 +489,12 @@

@messages(pageHeadingKey)

additionalParagraph) } +@answer6048(valueLabelKey: String, getAnswer: TurnoverSection6048 => String, additionalParagraph: Option[String] = None) = @{ + answer(valueLabelKey, + sectionAnswers1.answers.flatMap(_.turnoverSections6048).getOrElse(Seq.empty).map(getAnswer), + additionalParagraph) +} + @answer6076(valueLabelKey: String, getAnswer: TurnoverSection6076 => String, additionalParagraph: Option[String] = None) = @{ answer(valueLabelKey, sectionAnswers1.answers.flatMap(_.turnoverSections6076).getOrElse(Seq.empty).map(getAnswer), @@ -496,7 +504,7 @@

@messages(pageHeadingKey)

@messages("aboutYourTradingHistory.heading")

-@if(Seq(FOR6045, FOR6046) contains forType) { +@if(Seq(FOR6045, FOR6046, FOR6048) contains forType) { @govukSummaryList(SummaryList(rows = sectionAnswers.row("checkYourAnswersAboutTheTradingHistory.occupationDate", _.occupationAndAccountingInformation.map(_.firstOccupy.toYearMonth).map(dateUtil.formatYearMonth), @@ -522,7 +530,7 @@

@messages("aboutYourTradingHistory.heading")

sectionAnswers.row("checkYourAnswersAboutTheTradingHistory.financialYearEndUpdates", _.fold("")(t => financialYearEndDatesTable(financialYearEndDates(t))), forType match { - case FOR6020 | FOR6045 | FOR6046 | FOR6076 => + case FOR6020 | FOR6045 | FOR6046 | FOR6048 | FOR6076 => aboutthetradinghistory.routes.FinancialYearEndDatesSummaryController.show() case _ => aboutthetradinghistory.routes.FinancialYearEndDatesController.show() }, @@ -531,7 +539,7 @@

@messages("aboutYourTradingHistory.heading")

} -@if(!(Seq(FOR6020, FOR6045, FOR6046, FOR6076) contains forType)) { +@if(!(Seq(FOR6020, FOR6045, FOR6046, FOR6048, FOR6076) contains forType)) {

@messages("turnover.heading")

@govukSummaryList(SummaryList(rows = diff --git a/test/controllers/aboutthetradinghistory/AboutYourTradingHistoryControllerSpec.scala b/test/controllers/aboutthetradinghistory/AboutYourTradingHistoryControllerSpec.scala index 03a1af8dd..edd400c8f 100644 --- a/test/controllers/aboutthetradinghistory/AboutYourTradingHistoryControllerSpec.scala +++ b/test/controllers/aboutthetradinghistory/AboutYourTradingHistoryControllerSpec.scala @@ -16,13 +16,18 @@ package controllers.aboutthetradinghistory +import actions.SessionRequest +import controllers.aboutthetradinghistory import form.aboutthetradinghistory.OccupationalInformationForm.occupationalInformationForm +import models.ForType +import models.ForType.* import models.submissions.aboutthetradinghistory.AboutTheTradingHistory import play.api.http.Status import play.api.test.FakeRequest -import play.api.test.Helpers._ +import play.api.test.Helpers.* import utils.TestBaseSpec import utils.FormBindingTestAssertions.mustContainError + import scala.language.reflectiveCalls class AboutYourTradingHistoryControllerSpec extends TestBaseSpec { @@ -30,12 +35,16 @@ class AboutYourTradingHistoryControllerSpec extends TestBaseSpec { import TestData.{baseFormData, errorKey} def aboutYourTradingHistoryController( - aboutTheTradingHistory: Option[AboutTheTradingHistory] = Some(prefilledAboutYourTradingHistory) + aboutTheTradingHistory: Option[AboutTheTradingHistory] = Some(prefilledAboutYourTradingHistory), + forType: ForType = FOR6010 ) = new AboutYourTradingHistoryController( stubMessagesControllerComponents(), aboutYourTradingHistoryNavigator, aboutYourTradingHistoryView, - preEnrichedActionRefiner(aboutTheTradingHistory = aboutTheTradingHistory), + preEnrichedActionRefiner( + aboutTheTradingHistory = aboutTheTradingHistory, + forType = forType + ), mockSessionRepo ) @@ -45,6 +54,15 @@ class AboutYourTradingHistoryControllerSpec extends TestBaseSpec { status(result) shouldBe Status.OK } + "return 200 for 6048" in { + val session6048 = aboutYourTradingHistory6048YesSession + val sessionRequest = SessionRequest(session6048, FakeRequest()) + + val result = + aboutYourTradingHistoryController(session6048.aboutTheTradingHistory, session6048.forType).show(sessionRequest) + status(result) shouldBe Status.OK + } + "return HTML" in { val result = aboutYourTradingHistoryController().show(fakeRequest) contentType(result) shouldBe Some("text/html") @@ -62,6 +80,21 @@ class AboutYourTradingHistoryControllerSpec extends TestBaseSpec { val res = aboutYourTradingHistoryController().submit(FakeRequest().withFormUrlEncodedBody(Seq.empty*)) status(res) shouldBe BAD_REQUEST } + + "redirect to the next page for 6048" in { + val requestWithForm = FakeRequest(POST, "/path-to-form-handler") + .withFormUrlEncodedBody(baseFormData.toSeq*) + + val sessionRequest = + SessionRequest( + aboutYourTradingHistory6048YesSession, + requestWithForm + ) + + val result = aboutYourTradingHistoryController().submit(sessionRequest) + status(result) shouldBe SEE_OTHER + redirectLocation(result) shouldBe Some(aboutthetradinghistory.routes.FinancialYearEndController.show().url) + } } "About your trading history form" should { diff --git a/test/controllers/aboutthetradinghistory/CheckYourAnswersAboutTheTradingHistoryControllerSpec.scala b/test/controllers/aboutthetradinghistory/CheckYourAnswersAboutTheTradingHistoryControllerSpec.scala index 56add7421..b13b4323b 100644 --- a/test/controllers/aboutthetradinghistory/CheckYourAnswersAboutTheTradingHistoryControllerSpec.scala +++ b/test/controllers/aboutthetradinghistory/CheckYourAnswersAboutTheTradingHistoryControllerSpec.scala @@ -65,6 +65,14 @@ class CheckYourAnswersAboutTheTradingHistoryControllerSpec extends TestBaseSpec mockSessionRepo ) + val checkYourAnswersAboutTradingHistoryController6048 = new CheckYourAnswersAboutTheTradingHistoryController( + stubMessagesControllerComponents(), + mockAboutTheTradingHistoryNavigator, + checkYourAnswersAboutTheTradingHistoryView, + preFilledSession6048, + mockSessionRepo + ) + val checkYourAnswersAboutTradingHistoryController6076 = new CheckYourAnswersAboutTheTradingHistoryController( stubMessagesControllerComponents(), mockAboutTheTradingHistoryNavigator, @@ -118,6 +126,11 @@ class CheckYourAnswersAboutTheTradingHistoryControllerSpec extends TestBaseSpec charset(result) shouldBe Some("utf-8") } + "return 200 6048" in { + val result = checkYourAnswersAboutTradingHistoryController6048.show(fakeRequest) + status(result) shouldBe Status.OK + } + "return 200 6076" in { val result = checkYourAnswersAboutTradingHistoryController6076.show(fakeRequest) status(result) shouldBe Status.OK diff --git a/test/controllers/aboutthetradinghistory/EditFinancialYearEndDateControllerSpec.scala b/test/controllers/aboutthetradinghistory/EditFinancialYearEndDateControllerSpec.scala index e9f62f8c0..004550e24 100644 --- a/test/controllers/aboutthetradinghistory/EditFinancialYearEndDateControllerSpec.scala +++ b/test/controllers/aboutthetradinghistory/EditFinancialYearEndDateControllerSpec.scala @@ -262,6 +262,45 @@ class EditFinancialYearEndDateControllerSpec extends TestBaseSpec { ) } + "redirect to the next page for 6048" in { + val index = 0 + val requestWithForm = FakeRequest(POST, "/") + .withFormUrlEncodedBody( + "financialYearEnd.day" -> "22", + "financialYearEnd.month" -> "2", + "financialYearEnd.year" -> "2022" + ) + val session6048 = aboutYourTradingHistory6048YesSession + val sessionRequest = SessionRequest(session6048, requestWithForm) + + val result = editFinancialYearEndDateController(session6048).submit(index)(sessionRequest) + + status(result) shouldBe SEE_OTHER + redirectLocation(result) shouldBe Some( + aboutthetradinghistory.routes.FinancialYearEndDatesSummaryController.show().url + ) + } + + "redirect to CYA for 6048" in { + val index = 0 + val requestWithForm = FakeRequest(POST, "/") + .withFormUrlEncodedBody( + "financialYearEnd.day" -> "22", + "financialYearEnd.month" -> "2", + "financialYearEnd.year" -> "2022", + "from" -> "CYA" + ) + val session6048 = aboutYourTradingHistory6048YesSession + val sessionRequest = SessionRequest(session6048, requestWithForm) + + val result = editFinancialYearEndDateController(session6048).submit(index)(sessionRequest) + + status(result) shouldBe SEE_OTHER + redirectLocation(result) shouldBe Some( + aboutthetradinghistory.routes.CheckYourAnswersAboutTheTradingHistoryController.show().url + ) + } + "redirect to the next page for 6076" in { val index = 0 val requestWithForm = FakeRequest(POST, "/") diff --git a/test/controllers/aboutthetradinghistory/FinancialYearEndControllerSpec.scala b/test/controllers/aboutthetradinghistory/FinancialYearEndControllerSpec.scala index 8cf9bd347..bed4834ca 100644 --- a/test/controllers/aboutthetradinghistory/FinancialYearEndControllerSpec.scala +++ b/test/controllers/aboutthetradinghistory/FinancialYearEndControllerSpec.scala @@ -196,6 +196,28 @@ class FinancialYearEndControllerSpec extends TestBaseSpec { ) } + "redirect to the next page when valid 6048 data is submitted" in { + val validFormData = Map( + "financialYear.day" -> "25", + "financialYear.month" -> "4", + "yearEndChanged" -> "true" + ) + val session6048 = aboutYourTradingHistory6048YesSession + val request = FakeRequest(POST, "/").withFormUrlEncodedBody(validFormData.toSeq*) + val sessionRequest = SessionRequest(session6048, request) + + when(mockSessionRepo.saveOrUpdate(any[Session])(any[Writes[Session]], any[HeaderCarrier])) + .thenReturn(Future.unit) + + val result = + financialYearEndController(session6048.forType, session6048.aboutTheTradingHistory).submit(sessionRequest) + + status(result) shouldBe SEE_OTHER + redirectLocation(result) shouldBe Some( + aboutthetradinghistory.routes.FinancialYearEndDatesSummaryController.show().url + ) + } + "redirect to the next page when valid 6076 data is submitted" in { val validFormData = Map( "financialYear.day" -> "6", diff --git a/test/controllers/aboutthetradinghistory/FinancialYearEndDatesSummaryControllerSpec.scala b/test/controllers/aboutthetradinghistory/FinancialYearEndDatesSummaryControllerSpec.scala index 40cbab0cc..33e894b2d 100644 --- a/test/controllers/aboutthetradinghistory/FinancialYearEndDatesSummaryControllerSpec.scala +++ b/test/controllers/aboutthetradinghistory/FinancialYearEndDatesSummaryControllerSpec.scala @@ -50,6 +50,15 @@ class FinancialYearEndDatesSummaryControllerSpec extends TestBaseSpec { status(result) shouldBe Status.OK } + "return 200 for 6048" in { + val session6048 = aboutYourTradingHistory6048YesSession + val sessionRequest = SessionRequest(session6048, FakeRequest()) + + val result = financialYearEndDatesSummaryController(session6048.aboutTheTradingHistory, session6048.forType) + .show()(sessionRequest) + status(result) shouldBe Status.OK + } + "return HTML" in { val result = financialYearEndDatesSummaryController().show()(FakeRequest()) contentType(result) shouldBe Some("text/html") @@ -213,6 +222,45 @@ class FinancialYearEndDatesSummaryControllerSpec extends TestBaseSpec { ) } + "redirect to the next page for 6048 " in { + val requestWithForm = FakeRequest(POST, "/") + .withFormUrlEncodedBody( + "isFinancialYearEndDatesCorrect" -> "true" + ) + val session6048 = aboutYourTradingHistory6048YesSession + val sessionRequest = SessionRequest(session6048, requestWithForm) + + val result = + financialYearEndDatesSummaryController(session6048.aboutTheTradingHistory, session6048.forType).submit()( + sessionRequest + ) + + status(result) shouldBe SEE_OTHER + redirectLocation(result) shouldBe Some( + aboutthetradinghistory.routes.FinancialYearsController.show.url + ) + } + + "redirect to CYA for 6048 " in { + val requestWithForm = FakeRequest(POST, "/") + .withFormUrlEncodedBody( + "isFinancialYearEndDatesCorrect" -> "true", + "from" -> "CYA" + ) + val session6048 = aboutYourTradingHistory6048YesSession + val sessionRequest = SessionRequest(session6048, requestWithForm) + + val result = + financialYearEndDatesSummaryController(session6048.aboutTheTradingHistory, session6048.forType).submit()( + sessionRequest + ) + + status(result) shouldBe SEE_OTHER + redirectLocation(result) shouldBe Some( + aboutthetradinghistory.routes.CheckYourAnswersAboutTheTradingHistoryController.show().url + ) + } + "redirect to the next page for 6076 " in { val requestWithForm = FakeRequest(POST, "/") .withFormUrlEncodedBody( diff --git a/test/controllers/aboutthetradinghistory/FinancialYearsControllerSpec.scala b/test/controllers/aboutthetradinghistory/FinancialYearsControllerSpec.scala index d5e30525d..503c17c23 100644 --- a/test/controllers/aboutthetradinghistory/FinancialYearsControllerSpec.scala +++ b/test/controllers/aboutthetradinghistory/FinancialYearsControllerSpec.scala @@ -50,6 +50,16 @@ class FinancialYearsControllerSpec extends TestBaseSpec { status(result) shouldBe Status.OK } + "return 200 for 6048" in { + val session6048 = aboutYourTradingHistory6048YesSession + val sessionRequest = SessionRequest(session6048, FakeRequest()) + + val result = financialYearsController(session6048.aboutTheTradingHistory, session6048.forType).show()( + sessionRequest + ) + status(result) shouldBe Status.OK + } + "return HTML" in { val result = financialYearsController().show()(FakeRequest()) contentType(result) shouldBe Some("text/html") @@ -143,6 +153,45 @@ class FinancialYearsControllerSpec extends TestBaseSpec { ) } + "redirect to the next page for 6048 " in { + val requestWithForm = FakeRequest(POST, "/") + .withFormUrlEncodedBody( + "isFinancialYearsCorrect" -> "true" + ) + val session6048 = aboutYourTradingHistory6048YesSession + val sessionRequest = SessionRequest(session6048, requestWithForm) + + val result = + financialYearsController(session6048.aboutTheTradingHistory, session6048.forType).submit()( + sessionRequest + ) + + status(result) shouldBe SEE_OTHER + redirectLocation(result) shouldBe Some( + aboutthetradinghistory.routes.StaticCaravansController.show().url // TODO: Income6048Controller + ) + } + + "redirect to CYA for 6048 " in { + val requestWithForm = FakeRequest(POST, "/") + .withFormUrlEncodedBody( + "isFinancialYearsCorrect" -> "true", + "from" -> "CYA" + ) + val session6048 = aboutYourTradingHistory6048YesSession + val sessionRequest = SessionRequest(session6048, requestWithForm) + + val result = + financialYearsController(session6048.aboutTheTradingHistory, session6048.forType).submit()( + sessionRequest + ) + + status(result) shouldBe SEE_OTHER + redirectLocation(result) shouldBe Some( + aboutthetradinghistory.routes.CheckYourAnswersAboutTheTradingHistoryController.show().url + ) + } + } } diff --git a/test/utils/FakeObjects.scala b/test/utils/FakeObjects.scala index 3ef13dae4..a01809380 100644 --- a/test/utils/FakeObjects.scala +++ b/test/utils/FakeObjects.scala @@ -255,7 +255,12 @@ trait FakeObjects { val stillConnectedDetails6045NoSession: Session = baseFilled6045Session.copy(stillConnectedDetails = Some(prefilledStillConnectedDetailsNo)) -// Not connected sessions + val stillConnectedDetails6048YesSession: Session = + baseFilled6048Session.copy(stillConnectedDetails = Some(prefilledStillConnectedDetailsYes)) + val stillConnectedDetails6048NoSession: Session = + baseFilled6048Session.copy(stillConnectedDetails = Some(prefilledStillConnectedDetailsNo)) + + // Not connected sessions val prefilledNotConnectedYes: RemoveConnectionDetails = RemoveConnectionDetails( Some( RemoveConnectionsDetails( @@ -373,7 +378,8 @@ trait FakeObjects { val prefilledAboutYouAndThePropertyPartTwo6045: AboutYouAndThePropertyPartTwo = prefilledAboutYouAndThePropertyPartTwo.copy(propertyCurrentlyUsed = prefilledPropertyCurrentlyInUsed) - val prefilledPropertyCurrentlyInUsed = + + val prefilledPropertyCurrentlyInUsed = PropertyCurrentlyUsed(List("fleetCaravanPark", "chaletPark", "other"), Some("another use details")) val prefilledProvideContactDetails: ProvideContactDetails = ProvideContactDetails( @@ -417,6 +423,9 @@ trait FakeObjects { Some(prefilledAboutYouAndThePropertyPartTwo6045) ) + val aboutYouAndTheProperty6048YesSession: Session = + stillConnectedDetails6048YesSession + val aboutYouAndTheProperty6045NoSession: Session = stillConnectedDetails6045NoSession.copy(aboutYouAndThePropertyPartTwo = Some(prefilledAboutYouAndThePropertyPartTwo6045) @@ -713,21 +722,51 @@ trait FakeObjects { ) ) + val prefilledTurnoverSections6048: AboutTheTradingHistoryPartOne = AboutTheTradingHistoryPartOne( + isFinancialYearEndDatesCorrect = true, + isFinancialYearsCorrect = true, + turnoverSections6048 = Seq( + TurnoverSection6048( + today, + income = 111 + ), + TurnoverSection6048( + today.minusYears(1), + income = 222 + ), + TurnoverSection6048( + today.minusYears(2), + income = 333 + ) + ) + ) + val aboutYourTradingHistory6045YesSession: Session = aboutYouAndTheProperty6045YesSession.copy( aboutTheTradingHistory = Some(prefilledAboutYourTradingHistory6045), aboutTheTradingHistoryPartOne = Some(prefilledTurnoverSections6045) ) - val aboutYourTradingHistory6045CYAOtherHolidayAccommodationSession: Session = + val aboutYourTradingHistory6048YesSession: Session = + aboutYouAndTheProperty6048YesSession.copy( + aboutTheTradingHistory = Some(prefilledAboutYourTradingHistory6048), + aboutTheTradingHistoryPartOne = Some(prefilledTurnoverSections6048) + ) + + val aboutYourTradingHistory6045CYAOtherHolidayAccommodationSession: Session = aboutYourTradingHistory6045YesSession.copy(aboutTheTradingHistoryPartOne = prefilledAboutTheTradingHistoryPartOneCYA6045 ) + val prefilledAboutTheTradingHistoryPartOneCYA6045: AboutTheTradingHistoryPartOne = prefilledTurnoverSections6045.copy(otherHolidayAccommodation = Some(OtherHolidayAccommodation(Some(AnswerNo), None)) ) - val prefilledAboutTheTradingHistoryPartOneCYA6045All = prefilledAboutTheTradingHistoryPartOneCYA6045.copy( + + val prefilledAboutTheTradingHistoryPartOneCYA6048: AboutTheTradingHistoryPartOne = + prefilledTurnoverSections6048 + + val prefilledAboutTheTradingHistoryPartOneCYA6045All = prefilledAboutTheTradingHistoryPartOneCYA6045.copy( otherHolidayAccommodation = Some( OtherHolidayAccommodation( Some(AnswerYes), @@ -737,7 +776,7 @@ trait FakeObjects { ) ) ) - val aboutYourTradingHistory6045CYAOtherHolidayAccommodationSessionYes: Session = + val aboutYourTradingHistory6045CYAOtherHolidayAccommodationSessionYes: Session = aboutYourTradingHistory6045YesSession.copy(aboutTheTradingHistoryPartOne = prefilledAboutTheTradingHistoryPartOneCYA6045All ) diff --git a/test/utils/TestBaseSpec.scala b/test/utils/TestBaseSpec.scala index f2ebba5f6..7f67c67f6 100644 --- a/test/utils/TestBaseSpec.scala +++ b/test/utils/TestBaseSpec.scala @@ -158,6 +158,15 @@ trait TestBaseSpec aboutTheTradingHistoryPartOne = prefilledAboutTheTradingHistoryPartOneCYA6045, forType = FOR6045 ) + + val preFilledSession6048: WithSessionRefiner = + preEnrichedActionRefiner( + referenceNumber = "99996048004", + aboutTheTradingHistory = prefilledAboutYourTradingHistory6048, + aboutTheTradingHistoryPartOne = prefilledAboutTheTradingHistoryPartOneCYA6048, + forType = FOR6048 + ) + def preEnrichedActionRefiner( referenceNumber: String = "99996010004", forType: ForType = FOR6010,