From 94ccfdf347d2a65b303d644b91fb8e09bd909aac Mon Sep 17 00:00:00 2001 From: sini-george Date: Fri, 22 Nov 2024 17:09:32 +0000 Subject: [PATCH 1/3] ADR-1425 duty suspended improved formatters with tests --- .../DutySuspendedBeerController.scala | 10 +- .../DutySuspendedCiderController.scala | 10 +- ...utySuspendedOtherFermentedController.scala | 9 +- .../DutySuspendedSpiritsController.scala | 10 +- .../DutySuspendedWineController.scala | 10 +- .../DutySuspendedBeerFormProvider.scala | 58 ------- .../DutySuspendedCiderFormProvider.scala | 58 ------- .../DutySuspendedFormProvider.scala | 41 +++++ ...ySuspendedOtherFermentedFormProvider.scala | 64 ------- .../DutySuspendedSpiritsFormProvider.scala | 64 ------- .../DutySuspendedWineFormProvider.scala | 58 ------- .../DutySuspendedVolumesFormatter.scala | 132 ++++++++++++++ app/forms/mappings/Mappings.scala | 28 +++ .../dutySuspended/DutySuspendedCider.scala | 25 --- .../DutySuspendedOtherFermented.scala | 25 --- .../dutySuspended/DutySuspendedSpirits.scala | 25 --- ...edBeer.scala => DutySuspendedVolume.scala} | 6 +- .../dutySuspended/DutySuspendedWine.scala | 25 --- .../dutySuspended/DutySuspendedBeerPage.scala | 4 +- .../DutySuspendedCiderPage.scala | 4 +- .../DutySuspendedOtherFermentedPage.scala | 4 +- .../DutySuspendedSpiritsPage.scala | 4 +- .../dutySuspended/DutySuspendedWinePage.scala | 4 +- .../AdrReturnSubmissionService.scala | 20 +-- .../DutySuspendedBeerSummary.scala | 4 +- .../DutySuspendedCiderSummary.scala | 4 +- .../DutySuspendedOtherFermentedSummary.scala | 4 +- .../DutySuspendedSpiritsSummary.scala | 4 +- .../DutySuspendedWineSummary.scala | 4 +- .../CheckYourAnswersSummaryListHelper.scala | 4 +- .../spiritsQuestions/SpiritTypeSummary.scala | 35 ++-- .../DutySuspendedBeerView.scala.html | 11 +- .../DutySuspendedCiderView.scala.html | 14 +- ...DutySuspendedOtherFermentedView.scala.html | 15 +- .../DutySuspendedSpiritsView.scala.html | 10 +- .../DutySuspendedWineView.scala.html | 10 +- conf/messages.en | 66 ++----- test-utils/common/TestData.scala | 20 +-- test-utils/common/TestPages.scala | 12 +- test-utils/generators/ModelGenerators.scala | 36 +--- ...utySuspendedDeliveriesControllerSpec.scala | 24 +-- .../DutySuspendedBeerControllerSpec.scala | 26 +-- .../DutySuspendedCiderControllerSpec.scala | 28 +-- ...uspendedOtherFermentedControllerSpec.scala | 26 +-- .../DutySuspendedSpiritsControllerSpec.scala | 26 +-- .../DutySuspendedWineControllerSpec.scala | 28 +-- .../DutySuspendedBeerFormProviderSpec.scala | 120 ------------- .../DutySuspendedCiderFormProviderSpec.scala | 121 ------------- .../DutySuspendedFormProviderSpec.scala | 161 ++++++++++++++++++ ...pendedOtherFermentedFormProviderSpec.scala | 131 -------------- ...DutySuspendedSpiritsFormProviderSpec.scala | 120 ------------- .../DutySuspendedWineFormProviderSpec.scala | 121 ------------- .../tasklist/ReturnTaskListCreatorSpec.scala | 56 +++--- 53 files changed, 630 insertions(+), 1309 deletions(-) delete mode 100644 app/forms/dutySuspended/DutySuspendedBeerFormProvider.scala delete mode 100644 app/forms/dutySuspended/DutySuspendedCiderFormProvider.scala create mode 100644 app/forms/dutySuspended/DutySuspendedFormProvider.scala delete mode 100644 app/forms/dutySuspended/DutySuspendedOtherFermentedFormProvider.scala delete mode 100644 app/forms/dutySuspended/DutySuspendedSpiritsFormProvider.scala delete mode 100644 app/forms/dutySuspended/DutySuspendedWineFormProvider.scala create mode 100644 app/forms/mappings/DutySuspendedVolumesFormatter.scala delete mode 100644 app/models/dutySuspended/DutySuspendedCider.scala delete mode 100644 app/models/dutySuspended/DutySuspendedOtherFermented.scala delete mode 100644 app/models/dutySuspended/DutySuspendedSpirits.scala rename app/models/dutySuspended/{DutySuspendedBeer.scala => DutySuspendedVolume.scala} (76%) delete mode 100644 app/models/dutySuspended/DutySuspendedWine.scala delete mode 100644 test/forms/dutySuspended/DutySuspendedBeerFormProviderSpec.scala delete mode 100644 test/forms/dutySuspended/DutySuspendedCiderFormProviderSpec.scala create mode 100644 test/forms/dutySuspended/DutySuspendedFormProviderSpec.scala delete mode 100644 test/forms/dutySuspended/DutySuspendedOtherFermentedFormProviderSpec.scala delete mode 100644 test/forms/dutySuspended/DutySuspendedSpiritsFormProviderSpec.scala delete mode 100644 test/forms/dutySuspended/DutySuspendedWineFormProviderSpec.scala diff --git a/app/controllers/dutySuspended/DutySuspendedBeerController.scala b/app/controllers/dutySuspended/DutySuspendedBeerController.scala index 5b43a865..f343701d 100644 --- a/app/controllers/dutySuspended/DutySuspendedBeerController.scala +++ b/app/controllers/dutySuspended/DutySuspendedBeerController.scala @@ -17,7 +17,8 @@ package controllers.dutySuspended import controllers.actions._ -import forms.dutySuspended.DutySuspendedBeerFormProvider +import forms.dutySuspended.DutySuspendedFormProvider + import javax.inject.Inject import models.Mode import navigation.DeclareDutySuspendedDeliveriesNavigator @@ -25,6 +26,7 @@ import pages.dutySuspended.DutySuspendedBeerPage import play.api.i18n.{I18nSupport, MessagesApi} import play.api.mvc.{Action, AnyContent, MessagesControllerComponents} import connectors.UserAnswersConnector +import models.AlcoholRegime.Beer import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController import views.html.dutySuspended.DutySuspendedBeerView @@ -38,17 +40,16 @@ class DutySuspendedBeerController @Inject() ( getData: DataRetrievalAction, requireData: DataRequiredAction, checkRegime: CheckBeerRegimeAction, - formProvider: DutySuspendedBeerFormProvider, + formProvider: DutySuspendedFormProvider, val controllerComponents: MessagesControllerComponents, view: DutySuspendedBeerView )(implicit ec: ExecutionContext) extends FrontendBaseController with I18nSupport { - val form = formProvider() - def onPageLoad(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData andThen checkRegime) { implicit request => + val form = formProvider(Beer) val preparedForm = request.userAnswers.get(DutySuspendedBeerPage) match { case None => form case Some(value) => form.fill(value) @@ -59,6 +60,7 @@ class DutySuspendedBeerController @Inject() ( def onSubmit(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData andThen checkRegime).async { implicit request => + val form = formProvider(Beer) form .bindFromRequest() .fold( diff --git a/app/controllers/dutySuspended/DutySuspendedCiderController.scala b/app/controllers/dutySuspended/DutySuspendedCiderController.scala index db19bed1..714e850f 100644 --- a/app/controllers/dutySuspended/DutySuspendedCiderController.scala +++ b/app/controllers/dutySuspended/DutySuspendedCiderController.scala @@ -17,7 +17,8 @@ package controllers.dutySuspended import controllers.actions._ -import forms.dutySuspended.DutySuspendedCiderFormProvider +import forms.dutySuspended.DutySuspendedFormProvider + import javax.inject.Inject import models.Mode import navigation.DeclareDutySuspendedDeliveriesNavigator @@ -25,6 +26,7 @@ import pages.dutySuspended.DutySuspendedCiderPage import play.api.i18n.{I18nSupport, MessagesApi} import play.api.mvc.{Action, AnyContent, MessagesControllerComponents} import connectors.UserAnswersConnector +import models.AlcoholRegime.Cider import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController import views.html.dutySuspended.DutySuspendedCiderView @@ -38,17 +40,16 @@ class DutySuspendedCiderController @Inject() ( getData: DataRetrievalAction, requireData: DataRequiredAction, checkRegime: CheckCiderRegimeAction, - formProvider: DutySuspendedCiderFormProvider, + formProvider: DutySuspendedFormProvider, val controllerComponents: MessagesControllerComponents, view: DutySuspendedCiderView )(implicit ec: ExecutionContext) extends FrontendBaseController with I18nSupport { - val form = formProvider() - def onPageLoad(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData andThen checkRegime) { implicit request => + val form = formProvider(Cider) val preparedForm = request.userAnswers.get(DutySuspendedCiderPage) match { case None => form case Some(value) => form.fill(value) @@ -59,6 +60,7 @@ class DutySuspendedCiderController @Inject() ( def onSubmit(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData andThen checkRegime).async { implicit request => + val form = formProvider(Cider) form .bindFromRequest() .fold( diff --git a/app/controllers/dutySuspended/DutySuspendedOtherFermentedController.scala b/app/controllers/dutySuspended/DutySuspendedOtherFermentedController.scala index e1db5f63..06d2f6e4 100644 --- a/app/controllers/dutySuspended/DutySuspendedOtherFermentedController.scala +++ b/app/controllers/dutySuspended/DutySuspendedOtherFermentedController.scala @@ -17,7 +17,7 @@ package controllers.dutySuspended import controllers.actions._ -import forms.dutySuspended.DutySuspendedOtherFermentedFormProvider +import forms.dutySuspended.DutySuspendedFormProvider import javax.inject.Inject import models.Mode @@ -26,6 +26,7 @@ import pages.dutySuspended.DutySuspendedOtherFermentedPage import play.api.i18n.{I18nSupport, MessagesApi} import play.api.mvc.{Action, AnyContent, MessagesControllerComponents} import connectors.UserAnswersConnector +import models.AlcoholRegime.OtherFermentedProduct import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController import views.html.dutySuspended.DutySuspendedOtherFermentedView @@ -39,17 +40,16 @@ class DutySuspendedOtherFermentedController @Inject() ( getData: DataRetrievalAction, requireData: DataRequiredAction, checkRegime: CheckOtherFermentedRegimeAction, - formProvider: DutySuspendedOtherFermentedFormProvider, + formProvider: DutySuspendedFormProvider, val controllerComponents: MessagesControllerComponents, view: DutySuspendedOtherFermentedView )(implicit ec: ExecutionContext) extends FrontendBaseController with I18nSupport { - val form = formProvider() - def onPageLoad(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData andThen checkRegime) { implicit request => + val form = formProvider(OtherFermentedProduct) val preparedForm = request.userAnswers.get(DutySuspendedOtherFermentedPage) match { case None => form case Some(value) => form.fill(value) @@ -60,6 +60,7 @@ class DutySuspendedOtherFermentedController @Inject() ( def onSubmit(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData andThen checkRegime).async { implicit request => + val form = formProvider(OtherFermentedProduct) form .bindFromRequest() .fold( diff --git a/app/controllers/dutySuspended/DutySuspendedSpiritsController.scala b/app/controllers/dutySuspended/DutySuspendedSpiritsController.scala index 3ad3e433..0989b56e 100644 --- a/app/controllers/dutySuspended/DutySuspendedSpiritsController.scala +++ b/app/controllers/dutySuspended/DutySuspendedSpiritsController.scala @@ -17,7 +17,8 @@ package controllers.dutySuspended import controllers.actions._ -import forms.dutySuspended.DutySuspendedSpiritsFormProvider +import forms.dutySuspended.DutySuspendedFormProvider + import javax.inject.Inject import models.Mode import navigation.DeclareDutySuspendedDeliveriesNavigator @@ -25,6 +26,7 @@ import pages.dutySuspended.DutySuspendedSpiritsPage import play.api.i18n.{I18nSupport, MessagesApi} import play.api.mvc.{Action, AnyContent, MessagesControllerComponents} import connectors.UserAnswersConnector +import models.AlcoholRegime.Spirits import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController import views.html.dutySuspended.DutySuspendedSpiritsView @@ -38,17 +40,16 @@ class DutySuspendedSpiritsController @Inject() ( getData: DataRetrievalAction, requireData: DataRequiredAction, checkRegime: CheckSpiritsRegimeAction, - formProvider: DutySuspendedSpiritsFormProvider, + formProvider: DutySuspendedFormProvider, val controllerComponents: MessagesControllerComponents, view: DutySuspendedSpiritsView )(implicit ec: ExecutionContext) extends FrontendBaseController with I18nSupport { - val form = formProvider() - def onPageLoad(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData andThen checkRegime) { implicit request => + val form = formProvider(Spirits) val preparedForm = request.userAnswers.get(DutySuspendedSpiritsPage) match { case None => form case Some(value) => form.fill(value) @@ -59,6 +60,7 @@ class DutySuspendedSpiritsController @Inject() ( def onSubmit(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData andThen checkRegime).async { implicit request => + val form = formProvider(Spirits) form .bindFromRequest() .fold( diff --git a/app/controllers/dutySuspended/DutySuspendedWineController.scala b/app/controllers/dutySuspended/DutySuspendedWineController.scala index 11aa1fee..46776f87 100644 --- a/app/controllers/dutySuspended/DutySuspendedWineController.scala +++ b/app/controllers/dutySuspended/DutySuspendedWineController.scala @@ -17,7 +17,8 @@ package controllers.dutySuspended import controllers.actions._ -import forms.dutySuspended.DutySuspendedWineFormProvider +import forms.dutySuspended.DutySuspendedFormProvider + import javax.inject.Inject import models.Mode import navigation.DeclareDutySuspendedDeliveriesNavigator @@ -25,6 +26,7 @@ import pages.dutySuspended.DutySuspendedWinePage import play.api.i18n.{I18nSupport, MessagesApi} import play.api.mvc.{Action, AnyContent, MessagesControllerComponents} import connectors.UserAnswersConnector +import models.AlcoholRegime.Wine import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController import views.html.dutySuspended.DutySuspendedWineView @@ -38,17 +40,16 @@ class DutySuspendedWineController @Inject() ( getData: DataRetrievalAction, requireData: DataRequiredAction, checkRegime: CheckWineRegimeAction, - formProvider: DutySuspendedWineFormProvider, + formProvider: DutySuspendedFormProvider, val controllerComponents: MessagesControllerComponents, view: DutySuspendedWineView )(implicit ec: ExecutionContext) extends FrontendBaseController with I18nSupport { - val form = formProvider() - def onPageLoad(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData andThen checkRegime) { implicit request => + val form = formProvider(Wine) val preparedForm = request.userAnswers.get(DutySuspendedWinePage) match { case None => form case Some(value) => form.fill(value) @@ -59,6 +60,7 @@ class DutySuspendedWineController @Inject() ( def onSubmit(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData andThen checkRegime).async { implicit request => + val form = formProvider(Wine) form .bindFromRequest() .fold( diff --git a/app/forms/dutySuspended/DutySuspendedBeerFormProvider.scala b/app/forms/dutySuspended/DutySuspendedBeerFormProvider.scala deleted file mode 100644 index a4305314..00000000 --- a/app/forms/dutySuspended/DutySuspendedBeerFormProvider.scala +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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 forms.dutySuspended - -import config.Constants - -import javax.inject.Inject -import forms.mappings.Mappings -import play.api.data.Form -import play.api.data.Forms._ -import models.dutySuspended.DutySuspendedBeer - -class DutySuspendedBeerFormProvider @Inject() extends Mappings { - def apply(): Form[DutySuspendedBeer] = Form( - mapping( - "totalBeer" -> bigDecimal( - Constants.maximumDecimalPlaces, - "dutySuspendedBeer.error.totalBeer.required", - "dutySuspendedBeer.error.totalBeer.nonNumeric", - "dutySuspendedBeer.error.totalBeer.decimalPlaces" - ).verifying( - minimumValue(Constants.dutySuspendedVolumeMinimumValue, "dutySuspendedBeer.error.totalBeer.minimumRequired") - ).verifying( - maximumValue(Constants.dutySuspendedVolumeMaximumValue, "dutySuspendedBeer.error.totalBeer.maximumRequired") - ), - "pureAlcoholInBeer" -> bigDecimal( - Constants.lpaMaximumDecimalPlaces, - "dutySuspendedBeer.error.pureAlcoholInBeer.required", - "dutySuspendedBeer.error.pureAlcoholInBeer.nonNumeric", - "dutySuspendedBeer.error.pureAlcoholInBeer.decimalPlaces" - ).verifying( - minimumValue( - Constants.dutySuspendedLpaMinimumValue, - "dutySuspendedBeer.error.pureAlcoholInBeer.minimumRequired" - ) - ).verifying( - maximumValue( - Constants.dutySuspendedLpaMaximumValue, - "dutySuspendedBeer.error.pureAlcoholInBeer.maximumRequired" - ) - ) - )(DutySuspendedBeer.apply)(DutySuspendedBeer.unapply) - ) -} diff --git a/app/forms/dutySuspended/DutySuspendedCiderFormProvider.scala b/app/forms/dutySuspended/DutySuspendedCiderFormProvider.scala deleted file mode 100644 index 5f0c5c1e..00000000 --- a/app/forms/dutySuspended/DutySuspendedCiderFormProvider.scala +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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 forms.dutySuspended - -import config.Constants - -import javax.inject.Inject -import forms.mappings.Mappings -import play.api.data.Form -import play.api.data.Forms._ -import models.dutySuspended.DutySuspendedCider - -class DutySuspendedCiderFormProvider @Inject() extends Mappings { - def apply(): Form[DutySuspendedCider] = Form( - mapping( - "totalCider" -> bigDecimal( - Constants.maximumDecimalPlaces, - "dutySuspendedCider.error.totalCider.required", - "dutySuspendedCider.error.totalCider.nonNumeric", - "dutySuspendedCider.error.totalCider.decimalPlaces" - ).verifying( - minimumValue(Constants.dutySuspendedVolumeMinimumValue, "dutySuspendedCider.error.totalCider.minimumRequired") - ).verifying( - maximumValue(Constants.dutySuspendedVolumeMaximumValue, "dutySuspendedCider.error.totalCider.maximumRequired") - ), - "pureAlcoholInCider" -> bigDecimal( - Constants.lpaMaximumDecimalPlaces, - "dutySuspendedCider.error.pureAlcoholInCider.required", - "dutySuspendedCider.error.pureAlcoholInCider.nonNumeric", - "dutySuspendedCider.error.pureAlcoholInCider.decimalPlaces" - ).verifying( - minimumValue( - Constants.dutySuspendedLpaMinimumValue, - "dutySuspendedCider.error.pureAlcoholInCider.minimumRequired" - ) - ).verifying( - maximumValue( - Constants.dutySuspendedLpaMaximumValue, - "dutySuspendedCider.error.pureAlcoholInCider.maximumRequired" - ) - ) - )(DutySuspendedCider.apply)(DutySuspendedCider.unapply) - ) -} diff --git a/app/forms/dutySuspended/DutySuspendedFormProvider.scala b/app/forms/dutySuspended/DutySuspendedFormProvider.scala new file mode 100644 index 00000000..59990eec --- /dev/null +++ b/app/forms/dutySuspended/DutySuspendedFormProvider.scala @@ -0,0 +1,41 @@ +/* + * 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 forms.dutySuspended + +import javax.inject.Inject +import forms.mappings.Mappings +import models.AlcoholRegime +import play.api.data.Form +import models.dutySuspended.DutySuspendedVolume +import play.api.i18n.Messages + +class DutySuspendedFormProvider @Inject() extends Mappings { + def apply(regime: AlcoholRegime)(implicit messages: Messages): Form[DutySuspendedVolume] = Form( + "volumes" -> dutySuspendedVolumes( + "dutySuspendedVolume.error.invalid", + "dutySuspendedVolume.error.noValue", + "dutySuspendedVolume.error.decimalPlaces", + "dutySuspendedVolume.error.minimumValue", + "dutySuspendedVolume.error.maximumValue", + "dutySuspendedVolume.error.lessThanExpected", + "dutySuspendedVolume.error.incorrectSign", + "dutySuspendedVolume.error.zeroTotalLitres", + "dutySuspendedVolume.error.zeroLPA", + Seq(messages(s"return.regime.$regime")) + ) + ) +} diff --git a/app/forms/dutySuspended/DutySuspendedOtherFermentedFormProvider.scala b/app/forms/dutySuspended/DutySuspendedOtherFermentedFormProvider.scala deleted file mode 100644 index ce9f3cde..00000000 --- a/app/forms/dutySuspended/DutySuspendedOtherFermentedFormProvider.scala +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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 forms.dutySuspended - -import config.Constants - -import javax.inject.Inject -import forms.mappings.Mappings -import play.api.data.Form -import play.api.data.Forms._ -import models.dutySuspended.DutySuspendedOtherFermented - -class DutySuspendedOtherFermentedFormProvider @Inject() extends Mappings { - def apply(): Form[DutySuspendedOtherFermented] = Form( - mapping( - "totalOtherFermented" -> bigDecimal( - Constants.maximumDecimalPlaces, - "dutySuspendedOtherFermented.error.totalOtherFermented.required", - "dutySuspendedOtherFermented.error.totalOtherFermented.nonNumeric", - "dutySuspendedOtherFermented.error.totalOtherFermented.decimalPlaces" - ).verifying( - minimumValue( - Constants.dutySuspendedVolumeMinimumValue, - "dutySuspendedOtherFermented.error.totalOtherFermented.minimumRequired" - ) - ).verifying( - maximumValue( - Constants.dutySuspendedVolumeMaximumValue, - "dutySuspendedOtherFermented.error.totalOtherFermented.maximumRequired" - ) - ), - "pureAlcoholInOtherFermented" -> bigDecimal( - Constants.lpaMaximumDecimalPlaces, - "dutySuspendedOtherFermented.error.pureAlcoholInOtherFermented.required", - "dutySuspendedOtherFermented.error.pureAlcoholInOtherFermented.nonNumeric", - "dutySuspendedOtherFermented.error.pureAlcoholInOtherFermented.decimalPlaces" - ).verifying( - minimumValue( - Constants.dutySuspendedLpaMinimumValue, - "dutySuspendedOtherFermented.error.pureAlcoholInOtherFermented.minimumRequired" - ) - ).verifying( - maximumValue( - Constants.dutySuspendedLpaMaximumValue, - "dutySuspendedOtherFermented.error.pureAlcoholInOtherFermented.maximumRequired" - ) - ) - )(DutySuspendedOtherFermented.apply)(DutySuspendedOtherFermented.unapply) - ) -} diff --git a/app/forms/dutySuspended/DutySuspendedSpiritsFormProvider.scala b/app/forms/dutySuspended/DutySuspendedSpiritsFormProvider.scala deleted file mode 100644 index b5c45815..00000000 --- a/app/forms/dutySuspended/DutySuspendedSpiritsFormProvider.scala +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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 forms.dutySuspended - -import config.Constants - -import javax.inject.Inject -import forms.mappings.Mappings -import play.api.data.Form -import play.api.data.Forms._ -import models.dutySuspended.DutySuspendedSpirits - -class DutySuspendedSpiritsFormProvider @Inject() extends Mappings { - def apply(): Form[DutySuspendedSpirits] = Form( - mapping( - "totalSpirits" -> bigDecimal( - Constants.maximumDecimalPlaces, - "dutySuspendedSpirits.error.totalSpirits.required", - "dutySuspendedSpirits.error.totalSpirits.nonNumeric", - "dutySuspendedSpirits.error.totalSpirits.decimalPlaces" - ).verifying( - minimumValue( - Constants.dutySuspendedVolumeMinimumValue, - "dutySuspendedSpirits.error.totalSpirits.minimumRequired" - ) - ).verifying( - maximumValue( - Constants.dutySuspendedVolumeMaximumValue, - "dutySuspendedSpirits.error.totalSpirits.maximumRequired" - ) - ), - "pureAlcoholInSpirits" -> bigDecimal( - Constants.lpaMaximumDecimalPlaces, - "dutySuspendedSpirits.error.pureAlcoholInSpirits.required", - "dutySuspendedSpirits.error.pureAlcoholInSpirits.nonNumeric", - "dutySuspendedSpirits.error.pureAlcoholInSpirits.decimalPlaces" - ).verifying( - minimumValue( - Constants.dutySuspendedLpaMinimumValue, - "dutySuspendedSpirits.error.pureAlcoholInSpirits.minimumRequired" - ) - ).verifying( - maximumValue( - Constants.dutySuspendedLpaMaximumValue, - "dutySuspendedSpirits.error.pureAlcoholInSpirits.maximumRequired" - ) - ) - )(DutySuspendedSpirits.apply)(DutySuspendedSpirits.unapply) - ) -} diff --git a/app/forms/dutySuspended/DutySuspendedWineFormProvider.scala b/app/forms/dutySuspended/DutySuspendedWineFormProvider.scala deleted file mode 100644 index dd7a58c1..00000000 --- a/app/forms/dutySuspended/DutySuspendedWineFormProvider.scala +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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 forms.dutySuspended - -import config.Constants - -import javax.inject.Inject -import forms.mappings.Mappings -import play.api.data.Form -import play.api.data.Forms._ -import models.dutySuspended.DutySuspendedWine - -class DutySuspendedWineFormProvider @Inject() extends Mappings { - def apply(): Form[DutySuspendedWine] = Form( - mapping( - "totalWine" -> bigDecimal( - Constants.maximumDecimalPlaces, - "dutySuspendedWine.error.totalWine.required", - "dutySuspendedWine.error.totalWine.nonNumeric", - "dutySuspendedWine.error.totalWine.decimalPlaces" - ).verifying( - minimumValue(Constants.dutySuspendedVolumeMinimumValue, "dutySuspendedWine.error.totalWine.minimumRequired") - ).verifying( - maximumValue(Constants.dutySuspendedVolumeMaximumValue, "dutySuspendedWine.error.totalWine.maximumRequired") - ), - "pureAlcoholInWine" -> bigDecimal( - Constants.lpaMaximumDecimalPlaces, - "dutySuspendedWine.error.pureAlcoholInWine.required", - "dutySuspendedWine.error.pureAlcoholInWine.nonNumeric", - "dutySuspendedWine.error.pureAlcoholInWine.decimalPlaces" - ).verifying( - minimumValue( - Constants.dutySuspendedLpaMinimumValue, - "dutySuspendedWine.error.pureAlcoholInWine.minimumRequired" - ) - ).verifying( - maximumValue( - Constants.dutySuspendedLpaMaximumValue, - "dutySuspendedWine.error.pureAlcoholInWine.maximumRequired" - ) - ) - )(DutySuspendedWine.apply)(DutySuspendedWine.unapply) - ) -} diff --git a/app/forms/mappings/DutySuspendedVolumesFormatter.scala b/app/forms/mappings/DutySuspendedVolumesFormatter.scala new file mode 100644 index 00000000..f60593a7 --- /dev/null +++ b/app/forms/mappings/DutySuspendedVolumesFormatter.scala @@ -0,0 +1,132 @@ +/* + * 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 forms.mappings + +import config.Constants +import models.dutySuspended.DutySuspendedVolume +import play.api.data.FormError +import play.api.data.format.Formatter + +class DutySuspendedVolumesFormatter( + invalidKey: String, + requiredKey: String, + decimalPlacesKey: String, + minimumValueKey: String, + maximumValueKey: String, + inconsistentKey: String, + inconsistentSignKey: String, + zeroTotalLitresKey: String, + zeroLPAKey: String, + args: Seq[String] +) extends Formatter[DutySuspendedVolume] + with Formatters { + + private def volumeFormatter(fieldKey: String) = new BigDecimalFieldFormatter( + requiredKey, + invalidKey, + decimalPlacesKey, + minimumValueKey, + maximumValueKey, + fieldKey, + maximumValue = Constants.dutySuspendedVolumeMaximumValue, + minimumValue = Constants.dutySuspendedVolumeMinimumValue, + args = args + ) + + private def pureAlcoholBigDecimalFormatter(fieldKey: String) = new BigDecimalFieldFormatter( + requiredKey, + invalidKey, + decimalPlacesKey, + minimumValueKey, + maximumValueKey, + fieldKey, + decimalPlaces = Constants.lpaMaximumDecimalPlaces, + maximumValue = Constants.dutySuspendedLpaMaximumValue, + minimumValue = Constants.dutySuspendedLpaMinimumValue, + args = args + ) + + private val NUMBER_OF_FIELDS = 2 + private val totalVolumeKey = "totalLitresVolume" + private val pureAlcoholKey = "pureAlcoholVolume" + private val fieldKeys: List[String] = List(totalVolumeKey, pureAlcoholKey) + + private def requiredFieldFormError(key: String, field: String): FormError = + FormError(nameToId(s"${key}_$field"), s"$requiredKey.$field", args) + + private def formatVolume(key: String, data: Map[String, String]): Either[Seq[FormError], DutySuspendedVolume] = { + val totalLitres = volumeFormatter(totalVolumeKey).bind(s"$key.$totalVolumeKey", data) + val pureAlcohol = pureAlcoholBigDecimalFormatter(pureAlcoholKey).bind(s"$key.$pureAlcoholKey", data) + + (totalLitres, pureAlcohol) match { + case (Right(totalLitresValue), Right(pureAlcoholValue)) => + Right(DutySuspendedVolume(totalLitresValue, pureAlcoholValue)) + case (totalLitresError, pureAlcoholError) => + Left( + totalLitresError.left.getOrElse(Seq.empty) + ++ pureAlcoholError.left.getOrElse(Seq.empty) + ) + } + } + + private def checkValues(key: String, data: Map[String, String]): Either[Seq[FormError], DutySuspendedVolume] = + formatVolume(key, data).fold( + errors => Left(errors), + volumes => + if (volumes.totalLitresVolume < volumes.pureAlcoholVolume) { + Left(Seq(FormError(nameToId(s"$key.$pureAlcoholKey"), inconsistentKey, args))) + } + else if ((volumes.totalLitresVolume > 0) && (volumes.pureAlcoholVolume < 0)) { + Left(Seq(FormError(nameToId(s"$key.$pureAlcoholKey"), inconsistentSignKey, args))) + } + else if (volumes.totalLitresVolume != 0 && volumes.pureAlcoholVolume == 0) { + Left(Seq(FormError(nameToId(s"$key.$pureAlcoholKey"), zeroLPAKey, args))) + } else if (volumes.totalLitresVolume == 0 && volumes.pureAlcoholVolume < 0) { + Left(Seq(FormError(nameToId(s"$key.$pureAlcoholKey"), zeroTotalLitresKey, args))) + } else { + Right(volumes) + } + ) + + override def bind(key: String, data: Map[String, String]): Either[Seq[FormError], DutySuspendedVolume] = { + val fields = fieldKeys.map { field => + field -> data.get(s"$key.$field").filter(_.nonEmpty) + }.toMap + + lazy val missingFields = fields + .withFilter(_._2.isEmpty) + .map(_._1) + .toList + + fields.count(_._2.isDefined) match { + case NUMBER_OF_FIELDS => + checkValues(key, data) + case _ => + Left( + missingFields.map { field => + requiredFieldFormError(key, field) + } + ) + } + } + + override def unbind(key: String, value: DutySuspendedVolume): Map[String, String] = + Map( + s"$key.$totalVolumeKey" -> value.totalLitresVolume.toString, + s"$key.$pureAlcoholKey" -> value.pureAlcoholVolume.toString + ) +} diff --git a/app/forms/mappings/Mappings.scala b/app/forms/mappings/Mappings.scala index 1982f5ea..0da9f658 100644 --- a/app/forms/mappings/Mappings.scala +++ b/app/forms/mappings/Mappings.scala @@ -23,6 +23,7 @@ import play.api.data.FieldMapping import play.api.data.Forms.of import models.Enumerable import models.adjustment.{AdjustmentVolume, AdjustmentVolumeWithSPR, SpoiltVolumeWithDuty} +import models.dutySuspended.DutySuspendedVolume trait Mappings extends Formatters with Constraints { @@ -190,4 +191,31 @@ trait Mappings extends Formatters with Constraints { args ) ) + + protected def dutySuspendedVolumes( + invalidKey: String, + requiredKey: String, + decimalPlacesKey: String, + minimumValueKey: String, + maximumValueKey: String, + inconsistentKey: String, + inconsistentSignKey: String, + zeroTotalLitresKey: String, + zeroLPAKey: String, + args: Seq[String] = Seq.empty + ): FieldMapping[DutySuspendedVolume] = + of( + new DutySuspendedVolumesFormatter( + invalidKey, + requiredKey, + decimalPlacesKey, + minimumValueKey, + maximumValueKey, + inconsistentKey, + inconsistentSignKey, + zeroTotalLitresKey, + zeroLPAKey, + args + ) + ) } diff --git a/app/models/dutySuspended/DutySuspendedCider.scala b/app/models/dutySuspended/DutySuspendedCider.scala deleted file mode 100644 index d8447e4b..00000000 --- a/app/models/dutySuspended/DutySuspendedCider.scala +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.dutySuspended - -import play.api.libs.json._ - -case class DutySuspendedCider(totalCider: BigDecimal, pureAlcoholInCider: BigDecimal) - -object DutySuspendedCider { - implicit val format: OFormat[DutySuspendedCider] = Json.format[DutySuspendedCider] -} diff --git a/app/models/dutySuspended/DutySuspendedOtherFermented.scala b/app/models/dutySuspended/DutySuspendedOtherFermented.scala deleted file mode 100644 index a8261cda..00000000 --- a/app/models/dutySuspended/DutySuspendedOtherFermented.scala +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.dutySuspended - -import play.api.libs.json._ - -case class DutySuspendedOtherFermented(totalOtherFermented: BigDecimal, pureAlcoholInOtherFermented: BigDecimal) - -object DutySuspendedOtherFermented { - implicit val format: OFormat[DutySuspendedOtherFermented] = Json.format[DutySuspendedOtherFermented] -} diff --git a/app/models/dutySuspended/DutySuspendedSpirits.scala b/app/models/dutySuspended/DutySuspendedSpirits.scala deleted file mode 100644 index 079bd807..00000000 --- a/app/models/dutySuspended/DutySuspendedSpirits.scala +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.dutySuspended - -import play.api.libs.json._ - -case class DutySuspendedSpirits(totalSpirits: BigDecimal, pureAlcoholInSpirits: BigDecimal) - -object DutySuspendedSpirits { - implicit val format: OFormat[DutySuspendedSpirits] = Json.format[DutySuspendedSpirits] -} diff --git a/app/models/dutySuspended/DutySuspendedBeer.scala b/app/models/dutySuspended/DutySuspendedVolume.scala similarity index 76% rename from app/models/dutySuspended/DutySuspendedBeer.scala rename to app/models/dutySuspended/DutySuspendedVolume.scala index 5c70164e..37c9fa05 100644 --- a/app/models/dutySuspended/DutySuspendedBeer.scala +++ b/app/models/dutySuspended/DutySuspendedVolume.scala @@ -18,8 +18,8 @@ package models.dutySuspended import play.api.libs.json._ -case class DutySuspendedBeer(totalBeer: BigDecimal, pureAlcoholInBeer: BigDecimal) +case class DutySuspendedVolume(totalLitresVolume: BigDecimal, pureAlcoholVolume: BigDecimal) -object DutySuspendedBeer { - implicit val format: OFormat[DutySuspendedBeer] = Json.format[DutySuspendedBeer] +object DutySuspendedVolume { + implicit val format: OFormat[DutySuspendedVolume] = Json.format[DutySuspendedVolume] } diff --git a/app/models/dutySuspended/DutySuspendedWine.scala b/app/models/dutySuspended/DutySuspendedWine.scala deleted file mode 100644 index 801c8114..00000000 --- a/app/models/dutySuspended/DutySuspendedWine.scala +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.dutySuspended - -import play.api.libs.json._ - -case class DutySuspendedWine(totalWine: BigDecimal, pureAlcoholInWine: BigDecimal) - -object DutySuspendedWine { - implicit val format: OFormat[DutySuspendedWine] = Json.format[DutySuspendedWine] -} diff --git a/app/pages/dutySuspended/DutySuspendedBeerPage.scala b/app/pages/dutySuspended/DutySuspendedBeerPage.scala index b172de81..39e571f1 100644 --- a/app/pages/dutySuspended/DutySuspendedBeerPage.scala +++ b/app/pages/dutySuspended/DutySuspendedBeerPage.scala @@ -16,11 +16,11 @@ package pages.dutySuspended -import models.dutySuspended.DutySuspendedBeer +import models.dutySuspended.DutySuspendedVolume import pages.QuestionPage import play.api.libs.json.JsPath -case object DutySuspendedBeerPage extends QuestionPage[DutySuspendedBeer] { +case object DutySuspendedBeerPage extends QuestionPage[DutySuspendedVolume] { override def path: JsPath = JsPath \ toString diff --git a/app/pages/dutySuspended/DutySuspendedCiderPage.scala b/app/pages/dutySuspended/DutySuspendedCiderPage.scala index b1a98356..c122d6d5 100644 --- a/app/pages/dutySuspended/DutySuspendedCiderPage.scala +++ b/app/pages/dutySuspended/DutySuspendedCiderPage.scala @@ -16,11 +16,11 @@ package pages.dutySuspended -import models.dutySuspended.DutySuspendedCider +import models.dutySuspended.DutySuspendedVolume import pages.QuestionPage import play.api.libs.json.JsPath -case object DutySuspendedCiderPage extends QuestionPage[DutySuspendedCider] { +case object DutySuspendedCiderPage extends QuestionPage[DutySuspendedVolume] { override def path: JsPath = JsPath \ toString diff --git a/app/pages/dutySuspended/DutySuspendedOtherFermentedPage.scala b/app/pages/dutySuspended/DutySuspendedOtherFermentedPage.scala index fb8e69ad..ea13795e 100644 --- a/app/pages/dutySuspended/DutySuspendedOtherFermentedPage.scala +++ b/app/pages/dutySuspended/DutySuspendedOtherFermentedPage.scala @@ -16,11 +16,11 @@ package pages.dutySuspended -import models.dutySuspended.DutySuspendedOtherFermented +import models.dutySuspended.DutySuspendedVolume import pages.QuestionPage import play.api.libs.json.JsPath -case object DutySuspendedOtherFermentedPage extends QuestionPage[DutySuspendedOtherFermented] { +case object DutySuspendedOtherFermentedPage extends QuestionPage[DutySuspendedVolume] { override def path: JsPath = JsPath \ toString diff --git a/app/pages/dutySuspended/DutySuspendedSpiritsPage.scala b/app/pages/dutySuspended/DutySuspendedSpiritsPage.scala index 79aa64cf..4cc0ce25 100644 --- a/app/pages/dutySuspended/DutySuspendedSpiritsPage.scala +++ b/app/pages/dutySuspended/DutySuspendedSpiritsPage.scala @@ -16,11 +16,11 @@ package pages.dutySuspended -import models.dutySuspended.DutySuspendedSpirits +import models.dutySuspended.DutySuspendedVolume import pages.QuestionPage import play.api.libs.json.JsPath -case object DutySuspendedSpiritsPage extends QuestionPage[DutySuspendedSpirits] { +case object DutySuspendedSpiritsPage extends QuestionPage[DutySuspendedVolume] { override def path: JsPath = JsPath \ toString diff --git a/app/pages/dutySuspended/DutySuspendedWinePage.scala b/app/pages/dutySuspended/DutySuspendedWinePage.scala index 6e9289d3..9530381e 100644 --- a/app/pages/dutySuspended/DutySuspendedWinePage.scala +++ b/app/pages/dutySuspended/DutySuspendedWinePage.scala @@ -16,11 +16,11 @@ package pages.dutySuspended -import models.dutySuspended.DutySuspendedWine +import models.dutySuspended.DutySuspendedVolume import pages.QuestionPage import play.api.libs.json.JsPath -case object DutySuspendedWinePage extends QuestionPage[DutySuspendedWine] { +case object DutySuspendedWinePage extends QuestionPage[DutySuspendedVolume] { override def path: JsPath = JsPath \ toString diff --git a/app/services/checkAndSubmit/AdrReturnSubmissionService.scala b/app/services/checkAndSubmit/AdrReturnSubmissionService.scala index 4f50d0b3..e9c4211f 100644 --- a/app/services/checkAndSubmit/AdrReturnSubmissionService.scala +++ b/app/services/checkAndSubmit/AdrReturnSubmissionService.scala @@ -255,8 +255,8 @@ class AdrReturnSubmissionServiceImpl @Inject() ( AdrDutySuspendedProduct( regime = AdrDutySuspendedAlcoholRegime.Beer, suspendedQuantity = AdrAlcoholQuantity( - dutySuspendedBeer.totalBeer, - dutySuspendedBeer.pureAlcoholInBeer + dutySuspendedBeer.totalLitresVolume, + dutySuspendedBeer.pureAlcoholVolume ) ) ) @@ -269,8 +269,8 @@ class AdrReturnSubmissionServiceImpl @Inject() ( AdrDutySuspendedProduct( regime = AdrDutySuspendedAlcoholRegime.Cider, suspendedQuantity = AdrAlcoholQuantity( - dutySuspendedCider.totalCider, - dutySuspendedCider.pureAlcoholInCider + dutySuspendedCider.totalLitresVolume, + dutySuspendedCider.pureAlcoholVolume ) ) ) @@ -283,8 +283,8 @@ class AdrReturnSubmissionServiceImpl @Inject() ( AdrDutySuspendedProduct( regime = AdrDutySuspendedAlcoholRegime.Spirits, suspendedQuantity = AdrAlcoholQuantity( - dutySuspendedSpirits.totalSpirits, - dutySuspendedSpirits.pureAlcoholInSpirits + dutySuspendedSpirits.totalLitresVolume, + dutySuspendedSpirits.pureAlcoholVolume ) ) ) @@ -297,8 +297,8 @@ class AdrReturnSubmissionServiceImpl @Inject() ( AdrDutySuspendedProduct( regime = AdrDutySuspendedAlcoholRegime.Wine, suspendedQuantity = AdrAlcoholQuantity( - dutySuspendedWine.totalWine, - dutySuspendedWine.pureAlcoholInWine + dutySuspendedWine.totalLitresVolume, + dutySuspendedWine.pureAlcoholVolume ) ) ) @@ -311,8 +311,8 @@ class AdrReturnSubmissionServiceImpl @Inject() ( AdrDutySuspendedProduct( regime = AdrDutySuspendedAlcoholRegime.OtherFermentedProduct, suspendedQuantity = AdrAlcoholQuantity( - dutySuspendedOtherFermentedProducts.totalOtherFermented, - dutySuspendedOtherFermentedProducts.pureAlcoholInOtherFermented + dutySuspendedOtherFermentedProducts.totalLitresVolume, + dutySuspendedOtherFermentedProducts.pureAlcoholVolume ) ) ) diff --git a/app/viewmodels/checkAnswers/dutySuspended/DutySuspendedBeerSummary.scala b/app/viewmodels/checkAnswers/dutySuspended/DutySuspendedBeerSummary.scala index ac63751e..0d70077b 100644 --- a/app/viewmodels/checkAnswers/dutySuspended/DutySuspendedBeerSummary.scala +++ b/app/viewmodels/checkAnswers/dutySuspended/DutySuspendedBeerSummary.scala @@ -30,7 +30,7 @@ object DutySuspendedBeerSummary { answers.get(DutySuspendedBeerPage).map { answer => SummaryListRowViewModel( key = "dutySuspendedBeer.totalBeer.checkYourAnswersLabel", - value = ValueViewModel(s"${messages("site.2DP", answer.totalBeer)} ${messages("site.unit.litres")}"), + value = ValueViewModel(s"${messages("site.2DP", answer.totalLitresVolume)} ${messages("site.unit.litres")}"), actions = Seq( ActionItemViewModel("site.change", routes.DutySuspendedBeerController.onPageLoad(CheckMode).url) .withVisuallyHiddenText(messages("dutySuspendedBeer.totalBeer.change.hidden")) @@ -44,7 +44,7 @@ object DutySuspendedBeerSummary { SummaryListRowViewModel( key = "dutySuspendedBeer.pureAlcoholInBeer.checkYourAnswersLabel", value = ValueViewModel( - s"${messages("site.4DP", answer.pureAlcoholInBeer)} ${messages("site.unit.litres")}" + s"${messages("site.4DP", answer.pureAlcoholVolume)} ${messages("site.unit.litres")}" ), actions = Seq( ActionItemViewModel("site.change", routes.DutySuspendedBeerController.onPageLoad(CheckMode).url) diff --git a/app/viewmodels/checkAnswers/dutySuspended/DutySuspendedCiderSummary.scala b/app/viewmodels/checkAnswers/dutySuspended/DutySuspendedCiderSummary.scala index 5cd40047..627efa28 100644 --- a/app/viewmodels/checkAnswers/dutySuspended/DutySuspendedCiderSummary.scala +++ b/app/viewmodels/checkAnswers/dutySuspended/DutySuspendedCiderSummary.scala @@ -30,7 +30,7 @@ object DutySuspendedCiderSummary { answers.get(DutySuspendedCiderPage).map { answer => SummaryListRowViewModel( key = "dutySuspendedCider.totalCider.checkYourAnswersLabel", - value = ValueViewModel(s"${messages("site.2DP", answer.totalCider)} ${messages("site.unit.litres")}"), + value = ValueViewModel(s"${messages("site.2DP", answer.totalLitresVolume)} ${messages("site.unit.litres")}"), actions = Seq( ActionItemViewModel("site.change", routes.DutySuspendedCiderController.onPageLoad(CheckMode).url) .withVisuallyHiddenText(messages("dutySuspendedCider.totalCider.change.hidden")) @@ -43,7 +43,7 @@ object DutySuspendedCiderSummary { SummaryListRowViewModel( key = "dutySuspendedCider.pureAlcoholInCider.checkYourAnswersLabel", value = ValueViewModel( - s"${messages("site.4DP", answer.pureAlcoholInCider)} ${messages("site.unit.litres")}" + s"${messages("site.4DP", answer.pureAlcoholVolume)} ${messages("site.unit.litres")}" ), actions = Seq( ActionItemViewModel("site.change", routes.DutySuspendedCiderController.onPageLoad(CheckMode).url) diff --git a/app/viewmodels/checkAnswers/dutySuspended/DutySuspendedOtherFermentedSummary.scala b/app/viewmodels/checkAnswers/dutySuspended/DutySuspendedOtherFermentedSummary.scala index bd2311b0..b8a0defd 100644 --- a/app/viewmodels/checkAnswers/dutySuspended/DutySuspendedOtherFermentedSummary.scala +++ b/app/viewmodels/checkAnswers/dutySuspended/DutySuspendedOtherFermentedSummary.scala @@ -31,7 +31,7 @@ object DutySuspendedOtherFermentedSummary { SummaryListRowViewModel( key = "dutySuspendedOtherFermented.totalOtherFermented.checkYourAnswersLabel", value = ValueViewModel( - s"${messages("site.2DP", answer.totalOtherFermented)} ${messages("site.unit.litres")}" + s"${messages("site.2DP", answer.totalLitresVolume)} ${messages("site.unit.litres")}" ), actions = Seq( ActionItemViewModel("site.change", routes.DutySuspendedOtherFermentedController.onPageLoad(CheckMode).url) @@ -45,7 +45,7 @@ object DutySuspendedOtherFermentedSummary { SummaryListRowViewModel( key = "dutySuspendedOtherFermented.pureAlcoholInOtherFermented.checkYourAnswersLabel", value = ValueViewModel( - s"${messages("site.4DP", answer.pureAlcoholInOtherFermented)} ${messages("site.unit.litres")}" + s"${messages("site.4DP", answer.pureAlcoholVolume)} ${messages("site.unit.litres")}" ), actions = Seq( ActionItemViewModel("site.change", routes.DutySuspendedOtherFermentedController.onPageLoad(CheckMode).url) diff --git a/app/viewmodels/checkAnswers/dutySuspended/DutySuspendedSpiritsSummary.scala b/app/viewmodels/checkAnswers/dutySuspended/DutySuspendedSpiritsSummary.scala index 29e09ffd..f4e746ee 100644 --- a/app/viewmodels/checkAnswers/dutySuspended/DutySuspendedSpiritsSummary.scala +++ b/app/viewmodels/checkAnswers/dutySuspended/DutySuspendedSpiritsSummary.scala @@ -30,7 +30,7 @@ object DutySuspendedSpiritsSummary { answers.get(DutySuspendedSpiritsPage).map { answer => SummaryListRowViewModel( key = "dutySuspendedSpirits.totalSpirits.checkYourAnswersLabel", - value = ValueViewModel(s"${messages("site.2DP", answer.totalSpirits)} ${messages("site.unit.litres")}"), + value = ValueViewModel(s"${messages("site.2DP", answer.totalLitresVolume)} ${messages("site.unit.litres")}"), actions = Seq( ActionItemViewModel("site.change", routes.DutySuspendedSpiritsController.onPageLoad(CheckMode).url) .withVisuallyHiddenText(messages("dutySuspendedSpirits.totalSpirits.change.hidden")) @@ -43,7 +43,7 @@ object DutySuspendedSpiritsSummary { SummaryListRowViewModel( key = "dutySuspendedSpirits.pureAlcoholInSpirits.checkYourAnswersLabel", value = ValueViewModel( - s"${messages("site.4DP", answer.pureAlcoholInSpirits)} ${messages("site.unit.litres")}" + s"${messages("site.4DP", answer.pureAlcoholVolume)} ${messages("site.unit.litres")}" ), actions = Seq( ActionItemViewModel("site.change", routes.DutySuspendedSpiritsController.onPageLoad(CheckMode).url) diff --git a/app/viewmodels/checkAnswers/dutySuspended/DutySuspendedWineSummary.scala b/app/viewmodels/checkAnswers/dutySuspended/DutySuspendedWineSummary.scala index 52b03679..d3e5727e 100644 --- a/app/viewmodels/checkAnswers/dutySuspended/DutySuspendedWineSummary.scala +++ b/app/viewmodels/checkAnswers/dutySuspended/DutySuspendedWineSummary.scala @@ -30,7 +30,7 @@ object DutySuspendedWineSummary { answers.get(DutySuspendedWinePage).map { answer => SummaryListRowViewModel( key = "dutySuspendedWine.totalWine.checkYourAnswersLabel", - value = ValueViewModel(s"${messages("site.2DP", answer.totalWine)} ${messages("site.unit.litres")}"), + value = ValueViewModel(s"${messages("site.2DP", answer.totalLitresVolume)} ${messages("site.unit.litres")}"), actions = Seq( ActionItemViewModel("site.change", routes.DutySuspendedWineController.onPageLoad(CheckMode).url) .withVisuallyHiddenText(messages("dutySuspendedWine.totalWine.change.hidden")) @@ -43,7 +43,7 @@ object DutySuspendedWineSummary { SummaryListRowViewModel( key = "dutySuspendedWine.pureAlcoholInWine.checkYourAnswersLabel", value = ValueViewModel( - s"${messages("site.4DP", answer.pureAlcoholInWine)} ${messages("site.unit.litres")}" + s"${messages("site.4DP", answer.pureAlcoholVolume)} ${messages("site.unit.litres")}" ), actions = Seq( ActionItemViewModel("site.change", routes.DutySuspendedWineController.onPageLoad(CheckMode).url) diff --git a/app/viewmodels/checkAnswers/spiritsQuestions/CheckYourAnswersSummaryListHelper.scala b/app/viewmodels/checkAnswers/spiritsQuestions/CheckYourAnswersSummaryListHelper.scala index 669e9942..694a9593 100644 --- a/app/viewmodels/checkAnswers/spiritsQuestions/CheckYourAnswersSummaryListHelper.scala +++ b/app/viewmodels/checkAnswers/spiritsQuestions/CheckYourAnswersSummaryListHelper.scala @@ -25,16 +25,16 @@ import viewmodels.govuk.summarylist.SummaryListViewModel object CheckYourAnswersSummaryListHelper { def spiritsSummaryList(userAnswers: UserAnswers)(implicit messages: Messages): Option[SummaryList] = { val otherSpiritSummaryRow = getOptionalRow(OtherSpiritsProducedSummary.row(userAnswers)) - val spiritTypeSummaryRow = getOptionalRow(SpiritTypeSummary.row(userAnswers)) for { totalSpiritsSummaryRow <- DeclareSpiritsTotalSummary.row(userAnswers) scotchWhiskySummaryRow <- WhiskySummary.scotchWhiskyRow(userAnswers) irishWhiskySummaryRow <- WhiskySummary.irishWhiskeyRow(userAnswers) + spiritTypeSummaryRow <- SpiritTypeSummary.row(userAnswers) } yield SummaryListViewModel( Seq(totalSpiritsSummaryRow) ++ Seq(scotchWhiskySummaryRow) ++ Seq(irishWhiskySummaryRow) ++ - spiritTypeSummaryRow ++ + Seq(spiritTypeSummaryRow) ++ otherSpiritSummaryRow ).copy(card = Some(Card(title = Some(CardTitle(content = Text(messages("spiritsQuestions.checkYourAnswersLabel.card1")))))) diff --git a/app/viewmodels/checkAnswers/spiritsQuestions/SpiritTypeSummary.scala b/app/viewmodels/checkAnswers/spiritsQuestions/SpiritTypeSummary.scala index fbb11848..2a6c0dee 100644 --- a/app/viewmodels/checkAnswers/spiritsQuestions/SpiritTypeSummary.scala +++ b/app/viewmodels/checkAnswers/spiritsQuestions/SpiritTypeSummary.scala @@ -30,29 +30,24 @@ object SpiritTypeSummary { def row(answers: UserAnswers)(implicit messages: Messages): Option[SummaryListRow] = answers.get(SpiritTypePage).flatMap { answers => - val rowValue = answers.collect { - case answer if answer != SpiritType.Other => HtmlFormat.escape(messages(s"spiritType.$answer")).toString - } - if (rowValue.isEmpty) - None - else { - val value = ValueViewModel( - HtmlContent( - s"""${rowValue - .mkString(",
")}
""" - ) + val value = ValueViewModel( + HtmlContent( + s"""${HtmlFormat + .escape(messages(s"spiritType.$answers")) + .toString + .mkString(",
")}
""" ) + ) - Some( - SummaryListRowViewModel( - key = "spiritType.checkYourAnswersLabel", - value = value, - actions = Seq( - ActionItemViewModel("site.change", routes.SpiritTypeController.onPageLoad(CheckMode).url) - .withVisuallyHiddenText(messages("spiritType.change.hidden")) - ) + Some( + SummaryListRowViewModel( + key = "spiritType.checkYourAnswersLabel", + value = value, + actions = Seq( + ActionItemViewModel("site.change", routes.SpiritTypeController.onPageLoad(CheckMode).url) + .withVisuallyHiddenText(messages("spiritType.change.hidden")) ) ) - } + ) } } diff --git a/app/views/dutySuspended/DutySuspendedBeerView.scala.html b/app/views/dutySuspended/DutySuspendedBeerView.scala.html index faf458b9..8bf60454 100644 --- a/app/views/dutySuspended/DutySuspendedBeerView.scala.html +++ b/app/views/dutySuspended/DutySuspendedBeerView.scala.html @@ -50,8 +50,11 @@ @govukInput( InputViewModel( - field = form("totalBeer"), + field = form("volumes"), + key="totalLitresVolume", label = LabelViewModel(messages("dutySuspendedBeer.subheading1")).asSubheading, + errorMessageField = form("volumes_totalLitresVolume"), + value = form("volumes.totalLitresVolume").value ) .asNumeric() .withWidth(Fixed10) @@ -61,9 +64,11 @@ @govukInput( InputViewModel( - field = form("pureAlcoholInBeer"), + field = form("volumes"), + key="pureAlcoholVolume", label = LabelViewModel(messages("dutySuspendedBeer.subheading2")).asSubheading, - ) + errorMessageField = form("volumes_pureAlcoholVolume"), + value = form("volumes.pureAlcoholVolume").value) .asNumeric() .withWidth(Fixed10) .withSuffix(PrefixOrSuffix(content = messages("site.unit.litres"))) diff --git a/app/views/dutySuspended/DutySuspendedCiderView.scala.html b/app/views/dutySuspended/DutySuspendedCiderView.scala.html index 87ff4d05..857cd299 100644 --- a/app/views/dutySuspended/DutySuspendedCiderView.scala.html +++ b/app/views/dutySuspended/DutySuspendedCiderView.scala.html @@ -51,8 +51,11 @@ @govukInput( InputViewModel( - field = form("totalCider"), - label = LabelViewModel(messages("dutySuspendedCider.subheading1")).asSubheading + field = form("volumes"), + key="totalLitresVolume", + label = LabelViewModel(messages("dutySuspendedCider.subheading1")).asSubheading, + errorMessageField = form("volumes_totalLitresVolume"), + value = form("volumes.totalLitresVolume").value ) .asNumeric() .withWidth(Fixed10) @@ -62,8 +65,11 @@ @govukInput( InputViewModel( - field = form("pureAlcoholInCider"), - label = LabelViewModel(messages("dutySuspendedCider.subheading2")).asSubheading + field = form("volumes"), + key="pureAlcoholVolume", + label = LabelViewModel(messages("dutySuspendedCider.subheading2")).asSubheading, + errorMessageField = form("volumes_pureAlcoholVolume"), + value = form("volumes.pureAlcoholVolume").value ) .asNumeric() .withWidth(Fixed10) diff --git a/app/views/dutySuspended/DutySuspendedOtherFermentedView.scala.html b/app/views/dutySuspended/DutySuspendedOtherFermentedView.scala.html index bfc5fae5..311e3746 100644 --- a/app/views/dutySuspended/DutySuspendedOtherFermentedView.scala.html +++ b/app/views/dutySuspended/DutySuspendedOtherFermentedView.scala.html @@ -50,9 +50,11 @@ @govukInput( InputViewModel( - field = form("totalOtherFermented"), - label = LabelViewModel(messages("dutySuspendedOtherFermented.subheading1")).asSubheading - ) + field = form("volumes"), + key="totalLitresVolume", + label = LabelViewModel(messages("dutySuspendedOtherFermented.subheading1")).asSubheading, + errorMessageField = form("volumes_totalLitresVolume"), + value = form("volumes.totalLitresVolume").value) .asNumeric() .withWidth(Fixed10) .withSuffix(PrefixOrSuffix(content = messages("site.unit.litres"))) @@ -61,8 +63,11 @@ @govukInput( InputViewModel( - field = form("pureAlcoholInOtherFermented"), - label = LabelViewModel(messages("dutySuspendedOtherFermented.subheading2")).asSubheading + field = form("volumes"), + key="pureAlcoholVolume", + label = LabelViewModel(messages("dutySuspendedOtherFermented.subheading2")).asSubheading, + errorMessageField = form("volumes_pureAlcoholVolume"), + value = form("volumes.pureAlcoholVolume").value ) .asNumeric() .withWidth(Fixed10) diff --git a/app/views/dutySuspended/DutySuspendedSpiritsView.scala.html b/app/views/dutySuspended/DutySuspendedSpiritsView.scala.html index e436f188..1bd6500a 100644 --- a/app/views/dutySuspended/DutySuspendedSpiritsView.scala.html +++ b/app/views/dutySuspended/DutySuspendedSpiritsView.scala.html @@ -50,8 +50,11 @@ @govukInput( InputViewModel( - field = form("totalSpirits"), + field = form("volumes"), + key="totalLitresVolume", label = LabelViewModel(messages("dutySuspendedSpirits.subheading1")).asSubheading, + errorMessageField = form("volumes_totalLitresVolume"), + value = form("volumes.totalLitresVolume").value ) .asNumeric() .withWidth(Fixed10) @@ -61,8 +64,11 @@ @govukInput( InputViewModel( - field = form("pureAlcoholInSpirits"), + field = form("volumes"), + key="pureAlcoholVolume", label = LabelViewModel(messages("dutySuspendedSpirits.subheading2")).asSubheading, + errorMessageField = form("volumes_pureAlcoholVolume"), + value = form("volumes.pureAlcoholVolume").value ) .asNumeric() .withWidth(Fixed10) diff --git a/app/views/dutySuspended/DutySuspendedWineView.scala.html b/app/views/dutySuspended/DutySuspendedWineView.scala.html index 80532164..15debb91 100644 --- a/app/views/dutySuspended/DutySuspendedWineView.scala.html +++ b/app/views/dutySuspended/DutySuspendedWineView.scala.html @@ -50,8 +50,11 @@ @govukInput( InputViewModel( - field = form("totalWine"), + field = form("volumes"), + key="totalLitresVolume", label = LabelViewModel(messages("dutySuspendedWine.subheading1")).asSubheading, + errorMessageField = form("volumes_totalLitresVolume"), + value = form("volumes.totalLitresVolume").value ) .asNumeric() .withWidth(Fixed10) @@ -61,8 +64,11 @@ @govukInput( InputViewModel( - field = form("pureAlcoholInWine"), + field = form("volumes"), + key="pureAlcoholVolume", label = LabelViewModel(messages("dutySuspendedWine.subheading2")).asSubheading, + errorMessageField = form("volumes_pureAlcoholVolume"), + value = form("volumes.pureAlcoholVolume").value ) .asNumeric() .withWidth(Fixed10) diff --git a/conf/messages.en b/conf/messages.en index f338655b..1f55c9af 100644 --- a/conf/messages.en +++ b/conf/messages.en @@ -511,18 +511,23 @@ dutySuspendedBeer.subheading2 = What is the total net quantity of pure alcohol i dutySuspendedBeer.hint.2 = In litres, up to 4 decimal places dutySuspendedBeer.totalBeer.checkYourAnswersLabel = Total net quantity of duty suspended beer dutySuspendedBeer.pureAlcoholInBeer.checkYourAnswersLabel = Total net quantity of pure alcohol in this beer -dutySuspendedBeer.error.totalBeer.required = Enter the volume of beer in litres -dutySuspendedBeer.error.pureAlcoholInBeer.required = Enter the volume of pure alcohol in beer in litres dutySuspendedBeer.totalBeer.change.hidden = total net quantity of duty suspended beer dutySuspendedBeer.pureAlcoholInBeer.change.hidden = total net quantity of pure alcohol in this beer -dutySuspendedBeer.error.totalBeer.nonNumeric = The volume of beer must be a number -dutySuspendedBeer.error.totalBeer.maximumRequired = The volume of beer must be less than 100 million litres -dutySuspendedBeer.error.totalBeer.minimumRequired = The volume of beer must be more than -100 million litres -dutySuspendedBeer.error.totalBeer.decimalPlaces = The volume of beer must be up to 2 decimal places -dutySuspendedBeer.error.pureAlcoholInBeer.nonNumeric = The volume of pure alcohol in beer must be a number -dutySuspendedBeer.error.pureAlcoholInBeer.maximumRequired = The volume of pure alcohol in beer must be less than 100 million litres -dutySuspendedBeer.error.pureAlcoholInBeer.minimumRequired = The volume of pure alcohol in beer must be more than -100 million litres -dutySuspendedBeer.error.pureAlcoholInBeer.decimalPlaces = The volume of pure alcohol in beer must be up to 4 decimal places + +dutySuspendedVolume.error.noValue.totalLitresVolume = Enter the total net quantity of {0} +dutySuspendedVolume.error.noValue.pureAlcoholVolume = Enter the total net quantity of pure alcohol in {0} +dutySuspendedVolume.error.invalid.totalLitresVolume = Total net quantity of {0} must be a number +dutySuspendedVolume.error.invalid.pureAlcoholVolume = Total net quantity of pure alcohol must be a number up to 4 decimal places +dutySuspendedVolume.error.maximumValue.totalLitresVolume = Total net quantity of {0} must be less than 100 million litres +dutySuspendedVolume.error.minimumValue.totalLitresVolume = Total net quantity of {0} must be more than -100 million litres +dutySuspendedVolume.error.decimalPlaces.totalLitresVolume = Total net quantity of {0} must be a number up to 2 decimal places +dutySuspendedVolume.error.maximumValue.pureAlcoholVolume = Total net quantity of pure alcohol must be less than 100 million litres +dutySuspendedVolume.error.minimumValue.pureAlcoholVolume = Total net quantity of pure alcohol must be more than -100 million litres +dutySuspendedVolume.error.decimalPlaces.pureAlcoholVolume = Total net quantity of pure alcohol must be a number up to 4 decimal places +dutySuspendedVolume.error.incorrectSign = Total net quantity of pure alcohol must be more than 0.0000 +dutySuspendedVolume.error.zeroTotalLitres = Total net quantity of pure alcohol must be zero if {0} is also zero +dutySuspendedVolume.error.zeroLPA = Total net quantity of pure alcohol must be more or less than zero if {0} is more or less than 0.00 +dutySuspendedVolume.error.lessThanExpected = Total net quantity of pure alcohol must be the same or less than the total net quantity of {0} dutySuspendedCider.title = Tell us about your duty suspended cider dutySuspendedCider.heading = Tell us about your duty suspended cider @@ -533,18 +538,8 @@ dutySuspendedCider.subheading2 = What is the total net quantity of pure alcohol dutySuspendedCider.hint.2 = In litres, up to 4 decimal places dutySuspendedCider.totalCider.checkYourAnswersLabel = Total net quantity of duty suspended cider dutySuspendedCider.pureAlcoholInCider.checkYourAnswersLabel = Total net quantity of pure alcohol in this cider -dutySuspendedCider.error.totalCider.required = Enter the volume of cider in litres -dutySuspendedCider.error.pureAlcoholInCider.required = Enter the volume of pure alcohol in cider in litres dutySuspendedCider.totalCider.change.hidden = total net quantity of duty suspended cider dutySuspendedCider.pureAlcoholInCider.change.hidden = total net quantity of pure alcohol in this cider -dutySuspendedCider.error.totalCider.nonNumeric = The volume of cider must be a number -dutySuspendedCider.error.totalCider.maximumRequired = The volume of cider must be less than 100 million litres -dutySuspendedCider.error.totalCider.minimumRequired = The volume of cider must be more than -100 million litres -dutySuspendedCider.error.totalCider.decimalPlaces = The volume of cider must be up to 2 decimal places -dutySuspendedCider.error.pureAlcoholInCider.nonNumeric = The volume of pure alcohol in cider must be a number -dutySuspendedCider.error.pureAlcoholInCider.maximumRequired = The volume of pure alcohol in cider must be less than 100 million litres -dutySuspendedCider.error.pureAlcoholInCider.minimumRequired = The volume of pure alcohol in cider must be more than -100 million litres -dutySuspendedCider.error.pureAlcoholInCider.decimalPlaces = The volume of pure alcohol in cider must be up to 4 decimal places dutySuspendedWine.title = Tell us about your duty suspended wine dutySuspendedWine.heading = Tell us about your duty suspended wine @@ -555,18 +550,8 @@ dutySuspendedWine.hint.1 = In litres, up to 2 decimal places. dutySuspendedWine.hint.2 = In litres, up to 4 decimal places dutySuspendedWine.totalWine.checkYourAnswersLabel = Total net quantity of duty suspended wine dutySuspendedWine.pureAlcoholInWine.checkYourAnswersLabel = Total net quantity of pure alcohol in this wine -dutySuspendedWine.error.totalWine.required = Enter the volume of wine in litres -dutySuspendedWine.error.pureAlcoholInWine.required = Enter the volume of pure alcohol in wine in litres dutySuspendedWine.totalWine.change.hidden = total net quantity of duty suspended wine dutySuspendedWine.pureAlcoholInWine.change.hidden = total net quantity of pure alcohol in this wine -dutySuspendedWine.error.totalWine.nonNumeric = The volume of wine must be a number -dutySuspendedWine.error.totalWine.maximumRequired = The volume of wine must be less than 100 million litres -dutySuspendedWine.error.totalWine.minimumRequired = The volume of wine must be more than -100 million litres -dutySuspendedWine.error.totalWine.decimalPlaces = The volume of wine must be up to 2 decimal places -dutySuspendedWine.error.pureAlcoholInWine.nonNumeric = The volume of pure alcohol in wine must be a number -dutySuspendedWine.error.pureAlcoholInWine.maximumRequired = The volume of pure alcohol in wine must be less than 100 million litres -dutySuspendedWine.error.pureAlcoholInWine.minimumRequired = The volume of pure alcohol in wine must be must be more than -100 million litres -dutySuspendedWine.error.pureAlcoholInWine.decimalPlaces = The volume of pure alcohol in wine must be up to 4 decimal places dutySuspendedSpirits.title = Tell us about your duty suspended spirits dutySuspendedSpirits.heading = Tell us about your duty suspended spirits @@ -579,18 +564,8 @@ dutySuspendedSpirits.pureAlcoholInSpirits = pureAlcoholInSpirits dutySuspendedSpirits.totalSpirits.checkYourAnswersLabel = Total net quantity of duty suspended spirits dutySuspendedSpirits.pureAlcoholInSpirits.checkYourAnswersLabel = Total net quantity of pure alcohol in these spirits dutySuspendedSpirits.hint.2 = In litres, up to 4 decimal places -dutySuspendedSpirits.error.totalSpirits.required = Enter the volume of spirits in litres -dutySuspendedSpirits.error.pureAlcoholInSpirits.required = Enter the volume of pure alcohol in spirits in litres dutySuspendedSpirits.totalSpirits.change.hidden = total net quantity of duty suspended spirits dutySuspendedSpirits.pureAlcoholInSpirits.change.hidden = total net quantity of pure alcohol in these spirits -dutySuspendedSpirits.error.totalSpirits.nonNumeric = The volume of spirits must be a number -dutySuspendedSpirits.error.totalSpirits.maximumRequired = The volume of spirits must be less than 100 million litres -dutySuspendedSpirits.error.totalSpirits.minimumRequired = The volume of spirits must be more than -100 million litres -dutySuspendedSpirits.error.totalSpirits.decimalPlaces = The volume of spirits must be up to 2 decimal places -dutySuspendedSpirits.error.pureAlcoholInSpirits.nonNumeric = The volume of pure alcohol in spirits must be a number -dutySuspendedSpirits.error.pureAlcoholInSpirits.maximumRequired = The volume of pure alcohol in spirits must be less than 100 million litres -dutySuspendedSpirits.error.pureAlcoholInSpirits.minimumRequired = The volume of pure alcohol in spirits must be more than -100 million litres -dutySuspendedSpirits.error.pureAlcoholInSpirits.decimalPlaces = The volume of pure alcohol in spirits must be up to 4 decimal places dutySuspendedOtherFermented.title = Tell us about your other fermented products with duty suspended dutySuspendedOtherFermented.heading = Tell us about your other fermented products with duty suspended @@ -603,19 +578,8 @@ dutySuspendedOtherFermented.totalOtherFermented = totalOtherFermented dutySuspendedOtherFermented.pureAlcoholInOtherFermented = pureAlcoholInOtherFermented dutySuspendedOtherFermented.totalOtherFermented.checkYourAnswersLabel = Total net quantity of duty suspended other fermented products dutySuspendedOtherFermented.pureAlcoholInOtherFermented.checkYourAnswersLabel = Total net quantity of pure alcohol in these other fermented products -dutySuspendedOtherFermented.error.totalOtherFermented.required = Enter the volume of other fermented products in litres -dutySuspendedOtherFermented.error.pureAlcoholInOtherFermented.required = Enter the volume of pure alcohol in other fermented products in litres dutySuspendedOtherFermented.totalOtherFermented.change.hidden = total net quantity of duty suspended other fermented products dutySuspendedOtherFermented.pureAlcoholInOtherFermented.change.hidden = total net quantity of pure alcohol in these other fermented products -dutySuspendedOtherFermented.error.totalOtherFermented.nonNumeric = The volume of other fermented products must be a number -dutySuspendedOtherFermented.error.totalOtherFermented.maximumRequired = The volume of other fermented products must be less than 100 million litres -dutySuspendedOtherFermented.error.totalOtherFermented.minimumRequired = The volume of other fermented products must be more than -100 million litres -dutySuspendedOtherFermented.error.totalOtherFermented.decimalPlaces = The volume of other fermented products must be up to 2 decimal places -dutySuspendedOtherFermented.error.pureAlcoholInOtherFermented.nonNumeric = The volume of pure alcohol in other fermented products must be a number -dutySuspendedOtherFermented.error.pureAlcoholInOtherFermented.maximumRequired = The volume of pure alcohol in other fermented products must be less than 100 million litres -dutySuspendedOtherFermented.error.pureAlcoholInOtherFermented.minimumRequired = The volume of pure alcohol in other fermented products must be must be more than -100 million litres -dutySuspendedOtherFermented.error.pureAlcoholInOtherFermented.decimalPlaces = The volume of pure alcohol in other fermented products must be up to 4 decimal places - checkYourAnswersDutySuspendedDeliveries.heading = Duty suspended deliveries # End of of duty suspended deliveries sub-journey diff --git a/test-utils/common/TestData.scala b/test-utils/common/TestData.scala index 9df58bad..caf0a0dd 100644 --- a/test-utils/common/TestData.scala +++ b/test-utils/common/TestData.scala @@ -802,24 +802,24 @@ trait TestData extends ModelGenerators { OverDeclarationReasonPage.toString -> "Reason for over declaration", DeclareDutySuspendedDeliveriesQuestionPage.toString -> true, DutySuspendedBeerPage.toString -> Json.obj( - "totalBeer" -> 1000, - "pureAlcoholInBeer" -> 100 + "totalLitresVolume" -> 1000, + "pureAlcoholVolume" -> 100 ), DutySuspendedCiderPage.toString -> Json.obj( - "totalCider" -> 2000, - "pureAlcoholInCider" -> 200 + "totalLitresVolume" -> 2000, + "pureAlcoholVolume" -> 200 ), DutySuspendedSpiritsPage.toString -> Json.obj( - "totalSpirits" -> 1000, - "pureAlcoholInSpirits" -> 100 + "totalLitresVolume" -> 1000, + "pureAlcoholVolume" -> 100 ), DutySuspendedWinePage.toString -> Json.obj( - "totalWine" -> 1000, - "pureAlcoholInWine" -> 100 + "totalLitresVolume" -> 1000, + "pureAlcoholVolume" -> 100 ), DutySuspendedOtherFermentedPage.toString -> Json.obj( - "totalOtherFermented" -> 1000, - "pureAlcoholInOtherFermented" -> 100 + "totalLitresVolume" -> 1000, + "pureAlcoholVolume" -> 100 ), DeclareQuarterlySpiritsPage.toString -> true, DeclareSpiritsTotalPage.toString -> 1234, diff --git a/test-utils/common/TestPages.scala b/test-utils/common/TestPages.scala index 809ea0e2..2bd92ff9 100644 --- a/test-utils/common/TestPages.scala +++ b/test-utils/common/TestPages.scala @@ -17,7 +17,7 @@ package common import models.AlcoholRegime._ -import models.dutySuspended.{DutySuspendedBeer, DutySuspendedCider, DutySuspendedOtherFermented, DutySuspendedSpirits, DutySuspendedWine} +import models.dutySuspended.DutySuspendedVolume import models.{AlcoholRegime, RateBand, UserAnswers} import models.declareDuty.{AlcoholDuty, DutyByTaxType, VolumeAndRateByTaxType} import pages.adjustment.{AdjustmentTotalPage, DeclareAdjustmentQuestionPage} @@ -200,21 +200,21 @@ trait TestPages extends TestData { def specifyAllMultipleSPRListUnsorted(userAnswers: UserAnswers, regime: AlcoholRegime): UserAnswers = multipleSPRListPage(userAnswers, regime, allVolumeAndRateByTaxTypeUnsorted) - def dutySuspendedBeerPage(userAnswers: UserAnswers, dutySuspendedBeer: DutySuspendedBeer): UserAnswers = + def dutySuspendedBeerPage(userAnswers: UserAnswers, dutySuspendedBeer: DutySuspendedVolume): UserAnswers = userAnswers.set(DutySuspendedBeerPage, dutySuspendedBeer).get - def dutySuspendedCiderPage(userAnswers: UserAnswers, dutySuspendedCider: DutySuspendedCider): UserAnswers = + def dutySuspendedCiderPage(userAnswers: UserAnswers, dutySuspendedCider: DutySuspendedVolume): UserAnswers = userAnswers.set(DutySuspendedCiderPage, dutySuspendedCider).get - def dutySuspendedWinePage(userAnswers: UserAnswers, dutySuspendedWine: DutySuspendedWine): UserAnswers = + def dutySuspendedWinePage(userAnswers: UserAnswers, dutySuspendedWine: DutySuspendedVolume): UserAnswers = userAnswers.set(DutySuspendedWinePage, dutySuspendedWine).get - def dutySuspendedSpiritsPage(userAnswers: UserAnswers, dutySuspendedSpirits: DutySuspendedSpirits): UserAnswers = + def dutySuspendedSpiritsPage(userAnswers: UserAnswers, dutySuspendedSpirits: DutySuspendedVolume): UserAnswers = userAnswers.set(DutySuspendedSpiritsPage, dutySuspendedSpirits).get def dutySuspendedOtherFermentedPage( userAnswers: UserAnswers, - dutySuspendedOtherFermented: DutySuspendedOtherFermented + dutySuspendedOtherFermented: DutySuspendedVolume ): UserAnswers = userAnswers.set(DutySuspendedOtherFermentedPage, dutySuspendedOtherFermented).get } diff --git a/test-utils/generators/ModelGenerators.scala b/test-utils/generators/ModelGenerators.scala index 5c4f7e4c..db1b4935 100644 --- a/test-utils/generators/ModelGenerators.scala +++ b/test-utils/generators/ModelGenerators.scala @@ -112,44 +112,12 @@ trait ModelGenerators { } yield spiritsQuestions.AlcoholUsed(beer, wine, madeWine, ciderOrPerry) } - implicit lazy val arbitraryDutySuspendedBeer: Arbitrary[dutySuspended.DutySuspendedBeer] = + implicit lazy val arbitraryDutySuspendedVolume: Arbitrary[dutySuspended.DutySuspendedVolume] = Arbitrary { for { totalBeer <- arbitrary[BigDecimal] pureAlcoholInBeer <- arbitrary[BigDecimal] - } yield dutySuspended.DutySuspendedBeer(totalBeer, pureAlcoholInBeer) - } - - implicit lazy val arbitraryDutySuspendedCider: Arbitrary[dutySuspended.DutySuspendedCider] = - Arbitrary { - for { - totalCider <- arbitrary[BigDecimal] - pureAlcoholInCider <- arbitrary[BigDecimal] - } yield dutySuspended.DutySuspendedCider(totalCider, pureAlcoholInCider) - } - - implicit lazy val arbitraryDutySuspendedWine: Arbitrary[dutySuspended.DutySuspendedWine] = - Arbitrary { - for { - totalWine <- arbitrary[BigDecimal] - pureAlcoholInWine <- arbitrary[BigDecimal] - } yield dutySuspended.DutySuspendedWine(totalWine, pureAlcoholInWine) - } - - implicit lazy val arbitraryDutySuspendedSpirits: Arbitrary[dutySuspended.DutySuspendedSpirits] = - Arbitrary { - for { - totalSpirits <- arbitrary[BigDecimal] - pureAlcoholInSpirits <- arbitrary[BigDecimal] - } yield dutySuspended.DutySuspendedSpirits(totalSpirits, pureAlcoholInSpirits) - } - - implicit lazy val arbitraryDutySuspendedOtherFermented: Arbitrary[dutySuspended.DutySuspendedOtherFermented] = - Arbitrary { - for { - totalOtherFermented <- arbitrary[BigDecimal] - pureAlcoholInOtherFermented <- arbitrary[BigDecimal] - } yield dutySuspended.DutySuspendedOtherFermented(totalOtherFermented, pureAlcoholInOtherFermented) + } yield dutySuspended.DutySuspendedVolume(totalBeer, pureAlcoholInBeer) } implicit lazy val arbitraryAdjustmentType: Arbitrary[adjustment.AdjustmentType] = diff --git a/test/controllers/dutySuspended/CheckYourAnswersDutySuspendedDeliveriesControllerSpec.scala b/test/controllers/dutySuspended/CheckYourAnswersDutySuspendedDeliveriesControllerSpec.scala index 652c0410..7ecc4758 100644 --- a/test/controllers/dutySuspended/CheckYourAnswersDutySuspendedDeliveriesControllerSpec.scala +++ b/test/controllers/dutySuspended/CheckYourAnswersDutySuspendedDeliveriesControllerSpec.scala @@ -34,24 +34,24 @@ class CheckYourAnswersDutySuspendedDeliveriesControllerSpec extends SpecBase wit Json.obj( AlcoholRegimePage.toString -> Json.toJson(AlcoholRegime.values), DutySuspendedBeerPage.toString -> Json.obj( - "totalBeer" -> validTotal, - "pureAlcoholInBeer" -> validPureAlcohol + "totalLitresVolume" -> validTotal, + "pureAlcoholVolume" -> validPureAlcohol ), DutySuspendedCiderPage.toString -> Json.obj( - "totalCider" -> validTotal, - "pureAlcoholInCider" -> validPureAlcohol + "totalLitresVolume" -> validTotal, + "pureAlcoholVolume" -> validPureAlcohol ), DutySuspendedSpiritsPage.toString -> Json.obj( - "totalSpirits" -> validTotal, - "pureAlcoholInSpirits" -> validPureAlcohol + "totalLitresVolume" -> validTotal, + "pureAlcoholVolume" -> validPureAlcohol ), DutySuspendedWinePage.toString -> Json.obj( - "totalWine" -> validTotal, - "pureAlcoholInWine" -> validPureAlcohol + "totalLitresVolume" -> validTotal, + "pureAlcoholVolume" -> validPureAlcohol ), DutySuspendedOtherFermentedPage.toString -> Json.obj( - "totalOtherFermented" -> validTotal, - "pureAlcoholInOtherFermented" -> validPureAlcohol + "totalLitresVolume" -> validTotal, + "pureAlcoholVolume" -> validPureAlcohol ) ) ) @@ -91,8 +91,8 @@ class CheckYourAnswersDutySuspendedDeliveriesControllerSpec extends SpecBase wit regimes = AlcoholRegimes(Set(regime)), data = Json.obj( page.toString -> Json.obj( - s"total${regime.entryName}" -> validTotal, - s"pureAlcoholIn${regime.entryName}" -> validPureAlcohol + "totalLitresVolume" -> validTotal, + "pureAlcoholVolume" -> validPureAlcohol ) ) ) diff --git a/test/controllers/dutySuspended/DutySuspendedBeerControllerSpec.scala b/test/controllers/dutySuspended/DutySuspendedBeerControllerSpec.scala index 7605be3a..96b7e08f 100644 --- a/test/controllers/dutySuspended/DutySuspendedBeerControllerSpec.scala +++ b/test/controllers/dutySuspended/DutySuspendedBeerControllerSpec.scala @@ -17,9 +17,9 @@ package controllers.dutySuspended import base.SpecBase -import forms.dutySuspended.DutySuspendedBeerFormProvider +import forms.dutySuspended.DutySuspendedFormProvider import models.NormalMode -import models.dutySuspended.DutySuspendedBeer +import models.dutySuspended.DutySuspendedVolume import navigation.{DeclareDutySuspendedDeliveriesNavigator, FakeDeclareDutySuspendedDeliveriesNavigator} import org.mockito.ArgumentMatchers.any import pages.dutySuspended.DutySuspendedBeerPage @@ -28,6 +28,7 @@ import play.api.libs.json.Json import play.api.mvc.Call import play.api.test.Helpers._ import connectors.UserAnswersConnector +import models.AlcoholRegime.Beer import uk.gov.hmrc.http.HttpResponse import views.html.dutySuspended.DutySuspendedBeerView @@ -36,8 +37,9 @@ import scala.concurrent.Future class DutySuspendedBeerControllerSpec extends SpecBase { def onwardRoute = Call("GET", "/foo") - val formProvider = new DutySuspendedBeerFormProvider() - val form = formProvider() + val formProvider = new DutySuspendedFormProvider() + val regime = Beer + val form = formProvider(regime)(getMessages(app)) lazy val dutySuspendedBeerRoute = routes.DutySuspendedBeerController.onPageLoad(NormalMode).url @@ -47,8 +49,8 @@ class DutySuspendedBeerControllerSpec extends SpecBase { val userAnswers = userAnswersWithBeer.copy(data = Json.obj( DutySuspendedBeerPage.toString -> Json.obj( - "totalBeer" -> validTotalBeer, - "pureAlcoholInBeer" -> validPureAlcoholInBeer + "totalLitresVolume" -> validTotalBeer, + "pureAlcoholVolume" -> validPureAlcoholInBeer ) ) ) @@ -81,7 +83,7 @@ class DutySuspendedBeerControllerSpec extends SpecBase { status(result) mustEqual OK contentAsString(result) mustEqual view( - form.fill(DutySuspendedBeer(validTotalBeer, validPureAlcoholInBeer)), + form.fill(DutySuspendedVolume(validTotalBeer, validPureAlcoholInBeer)), NormalMode )( request, @@ -108,8 +110,8 @@ class DutySuspendedBeerControllerSpec extends SpecBase { val request = FakeRequest(POST, dutySuspendedBeerRoute) .withFormUrlEncodedBody( - ("totalBeer", validTotalBeer.toString), - ("pureAlcoholInBeer", validPureAlcoholInBeer.toString) + ("volumes.totalLitresVolume", validTotalBeer.toString), + ("volumes.pureAlcoholVolume", validPureAlcoholInBeer.toString) ) val result = route(application, request).value @@ -170,7 +172,7 @@ class DutySuspendedBeerControllerSpec extends SpecBase { running(application) { val request = FakeRequest(POST, dutySuspendedBeerRoute) - .withFormUrlEncodedBody(("totalBeer", "5.6"), ("pureAlcoholInBeer", "47.5")) + .withFormUrlEncodedBody(("volumes.totalLitresVolume", "5.6"), ("volumes.pureAlcoholVolume", "47.5")) val result = route(application, request).value @@ -186,8 +188,8 @@ class DutySuspendedBeerControllerSpec extends SpecBase { val request = FakeRequest(POST, dutySuspendedBeerRoute) .withFormUrlEncodedBody( - ("totalBeer", validTotalBeer.toString), - ("pureAlcoholInBeer", validPureAlcoholInBeer.toString) + ("volumes.totalLitresVolume", validTotalBeer.toString), + ("volumes.pureAlcoholVolume", validPureAlcoholInBeer.toString) ) val result = route(application, request).value diff --git a/test/controllers/dutySuspended/DutySuspendedCiderControllerSpec.scala b/test/controllers/dutySuspended/DutySuspendedCiderControllerSpec.scala index 99a668ee..1a3fdef7 100644 --- a/test/controllers/dutySuspended/DutySuspendedCiderControllerSpec.scala +++ b/test/controllers/dutySuspended/DutySuspendedCiderControllerSpec.scala @@ -17,9 +17,8 @@ package controllers.dutySuspended import base.SpecBase -import forms.dutySuspended.DutySuspendedCiderFormProvider import models.NormalMode -import models.dutySuspended.DutySuspendedCider +import models.dutySuspended.DutySuspendedVolume import navigation.{DeclareDutySuspendedDeliveriesNavigator, FakeDeclareDutySuspendedDeliveriesNavigator} import org.mockito.ArgumentMatchers.any import pages.dutySuspended.DutySuspendedCiderPage @@ -28,6 +27,8 @@ import play.api.libs.json.Json import play.api.mvc.Call import play.api.test.Helpers._ import connectors.UserAnswersConnector +import forms.dutySuspended.DutySuspendedFormProvider +import models.AlcoholRegime.Cider import uk.gov.hmrc.http.HttpResponse import views.html.dutySuspended.DutySuspendedCiderView @@ -36,8 +37,9 @@ import scala.concurrent.Future class DutySuspendedCiderControllerSpec extends SpecBase { def onwardRoute = Call("GET", "/foo") - val formProvider = new DutySuspendedCiderFormProvider() - val form = formProvider() + val formProvider = new DutySuspendedFormProvider() + val regime = Cider + val form = formProvider(regime)(getMessages(app)) val validTotalCider = 45.67 val validPureAlcoholInCider = 23.45 @@ -46,8 +48,8 @@ class DutySuspendedCiderControllerSpec extends SpecBase { val userAnswers = userAnswersWithCider.copy(data = Json.obj( DutySuspendedCiderPage.toString -> Json.obj( - "totalCider" -> validTotalCider, - "pureAlcoholInCider" -> validPureAlcoholInCider + "totalLitresVolume" -> validTotalCider, + "pureAlcoholVolume" -> validPureAlcoholInCider ) ) ) @@ -80,7 +82,7 @@ class DutySuspendedCiderControllerSpec extends SpecBase { status(result) mustEqual OK contentAsString(result) mustEqual view( - form.fill(DutySuspendedCider(validTotalCider, validPureAlcoholInCider)), + form.fill(DutySuspendedVolume(validTotalCider, validPureAlcoholInCider)), NormalMode )(request, getMessages(application)).toString } @@ -104,8 +106,8 @@ class DutySuspendedCiderControllerSpec extends SpecBase { val request = FakeRequest(POST, dutySuspendedCiderRoute) .withFormUrlEncodedBody( - ("totalCider", validTotalCider.toString), - ("pureAlcoholInCider", validPureAlcoholInCider.toString) + ("volumes.totalLitresVolume", validTotalCider.toString), + ("volumes.pureAlcoholVolume", validPureAlcoholInCider.toString) ) val result = route(application, request).value @@ -167,8 +169,8 @@ class DutySuspendedCiderControllerSpec extends SpecBase { val request = FakeRequest(POST, dutySuspendedCiderRoute) .withFormUrlEncodedBody( - ("totalCider", validTotalCider.toString), - ("pureAlcoholInCider", validPureAlcoholInCider.toString) + ("volumes.totalLitresVolume", validTotalCider.toString), + ("volumes.pureAlcoholVolume", validPureAlcoholInCider.toString) ) val result = route(application, request).value @@ -185,8 +187,8 @@ class DutySuspendedCiderControllerSpec extends SpecBase { val request = FakeRequest(POST, dutySuspendedCiderRoute) .withFormUrlEncodedBody( - ("totalCider", validTotalCider.toString), - ("pureAlcoholInCider", validPureAlcoholInCider.toString) + ("volumes.totalLitresVolume", validTotalCider.toString), + ("volumes.pureAlcoholVolume", validPureAlcoholInCider.toString) ) val result = route(application, request).value diff --git a/test/controllers/dutySuspended/DutySuspendedOtherFermentedControllerSpec.scala b/test/controllers/dutySuspended/DutySuspendedOtherFermentedControllerSpec.scala index 5b3102ea..ea492f72 100644 --- a/test/controllers/dutySuspended/DutySuspendedOtherFermentedControllerSpec.scala +++ b/test/controllers/dutySuspended/DutySuspendedOtherFermentedControllerSpec.scala @@ -17,9 +17,8 @@ package controllers.dutySuspended import base.SpecBase -import forms.dutySuspended.DutySuspendedOtherFermentedFormProvider import models.NormalMode -import models.dutySuspended.DutySuspendedOtherFermented +import models.dutySuspended.DutySuspendedVolume import navigation.{DeclareDutySuspendedDeliveriesNavigator, FakeDeclareDutySuspendedDeliveriesNavigator} import org.mockito.ArgumentMatchers.any import pages.dutySuspended.DutySuspendedOtherFermentedPage @@ -28,6 +27,8 @@ import play.api.libs.json.Json import play.api.mvc.Call import play.api.test.Helpers._ import connectors.UserAnswersConnector +import forms.dutySuspended.DutySuspendedFormProvider +import models.AlcoholRegime.OtherFermentedProduct import uk.gov.hmrc.http.HttpResponse import views.html.dutySuspended.DutySuspendedOtherFermentedView @@ -36,8 +37,9 @@ import scala.concurrent.Future class DutySuspendedOtherFermentedControllerSpec extends SpecBase { def onwardRoute = Call("GET", "/foo") - val formProvider = new DutySuspendedOtherFermentedFormProvider() - val form = formProvider() + val formProvider = new DutySuspendedFormProvider() + val regime = OtherFermentedProduct + val form = formProvider(regime)(getMessages(app)) val validTotalOtherFermented = 45.67 val validPureAlcoholInOtherFermented = 23.45 @@ -46,8 +48,8 @@ class DutySuspendedOtherFermentedControllerSpec extends SpecBase { val userAnswers = userAnswersWithOtherFermentedProduct.copy(data = Json.obj( DutySuspendedOtherFermentedPage.toString -> Json.obj( - "totalOtherFermented" -> validTotalOtherFermented, - "pureAlcoholInOtherFermented" -> validPureAlcoholInOtherFermented + "totalLitresVolume" -> validTotalOtherFermented, + "pureAlcoholVolume" -> validPureAlcoholInOtherFermented ) ) ) @@ -80,7 +82,7 @@ class DutySuspendedOtherFermentedControllerSpec extends SpecBase { status(result) mustEqual OK contentAsString(result) mustEqual view( - form.fill(DutySuspendedOtherFermented(validTotalOtherFermented, validPureAlcoholInOtherFermented)), + form.fill(DutySuspendedVolume(validTotalOtherFermented, validPureAlcoholInOtherFermented)), NormalMode )(request, getMessages(application)).toString } @@ -104,8 +106,8 @@ class DutySuspendedOtherFermentedControllerSpec extends SpecBase { val request = FakeRequest(POST, dutySuspendedOtherFermentedRoute) .withFormUrlEncodedBody( - ("totalOtherFermented", validTotalOtherFermented.toString), - ("pureAlcoholInOtherFermented", validPureAlcoholInOtherFermented.toString) + ("volumes.totalLitresVolume", validTotalOtherFermented.toString), + ("volumes.pureAlcoholVolume", validPureAlcoholInOtherFermented.toString) ) val result = route(application, request).value @@ -166,7 +168,7 @@ class DutySuspendedOtherFermentedControllerSpec extends SpecBase { running(application) { val request = FakeRequest(POST, dutySuspendedOtherFermentedRoute) - .withFormUrlEncodedBody(("totalOtherFermented", "value 1"), ("pureAlcoholInOtherFermented", "value 2")) + .withFormUrlEncodedBody(("volumes.totalLitresVolume", "value 1"), ("volumes.pureAlcoholVolume", "value 2")) val result = route(application, request).value @@ -182,8 +184,8 @@ class DutySuspendedOtherFermentedControllerSpec extends SpecBase { val request = FakeRequest(POST, dutySuspendedOtherFermentedRoute) .withFormUrlEncodedBody( - ("totalOtherFermented", validTotalOtherFermented.toString), - ("pureAlcoholInOtherFermented", validPureAlcoholInOtherFermented.toString) + ("volumes.totalLitresVolume", validTotalOtherFermented.toString), + ("volumes.pureAlcoholVolume", validPureAlcoholInOtherFermented.toString) ) val result = route(application, request).value diff --git a/test/controllers/dutySuspended/DutySuspendedSpiritsControllerSpec.scala b/test/controllers/dutySuspended/DutySuspendedSpiritsControllerSpec.scala index 29a3a7f3..6f3c28da 100644 --- a/test/controllers/dutySuspended/DutySuspendedSpiritsControllerSpec.scala +++ b/test/controllers/dutySuspended/DutySuspendedSpiritsControllerSpec.scala @@ -17,9 +17,8 @@ package controllers.dutySuspended import base.SpecBase -import forms.dutySuspended.DutySuspendedSpiritsFormProvider import models.NormalMode -import models.dutySuspended.DutySuspendedSpirits +import models.dutySuspended.DutySuspendedVolume import navigation.{DeclareDutySuspendedDeliveriesNavigator, FakeDeclareDutySuspendedDeliveriesNavigator} import org.mockito.ArgumentMatchers.any import pages.dutySuspended.DutySuspendedSpiritsPage @@ -28,6 +27,8 @@ import play.api.libs.json.Json import play.api.mvc.Call import play.api.test.Helpers._ import connectors.UserAnswersConnector +import forms.dutySuspended.DutySuspendedFormProvider +import models.AlcoholRegime.Spirits import uk.gov.hmrc.http.HttpResponse import views.html.dutySuspended.DutySuspendedSpiritsView @@ -36,8 +37,9 @@ import scala.concurrent.Future class DutySuspendedSpiritsControllerSpec extends SpecBase { def onwardRoute = Call("GET", "/foo") - val formProvider = new DutySuspendedSpiritsFormProvider() - val form = formProvider() + val formProvider = new DutySuspendedFormProvider() + val regime = Spirits + val form = formProvider(regime)(getMessages(app)) val validTotalSpirits = 45.67 val validPureAlcoholInSpirits = 23.45 @@ -46,8 +48,8 @@ class DutySuspendedSpiritsControllerSpec extends SpecBase { val userAnswers = userAnswersWithSpirits.copy(data = Json.obj( DutySuspendedSpiritsPage.toString -> Json.obj( - "totalSpirits" -> validTotalSpirits, - "pureAlcoholInSpirits" -> validPureAlcoholInSpirits + "totalLitresVolume" -> validTotalSpirits, + "pureAlcoholVolume" -> validPureAlcoholInSpirits ) ) ) @@ -80,7 +82,7 @@ class DutySuspendedSpiritsControllerSpec extends SpecBase { status(result) mustEqual OK contentAsString(result) mustEqual view( - form.fill(DutySuspendedSpirits(validTotalSpirits, validPureAlcoholInSpirits)), + form.fill(DutySuspendedVolume(validTotalSpirits, validPureAlcoholInSpirits)), NormalMode )( request, @@ -107,8 +109,8 @@ class DutySuspendedSpiritsControllerSpec extends SpecBase { val request = FakeRequest(POST, dutySuspendedSpiritsRoute) .withFormUrlEncodedBody( - ("totalSpirits", validTotalSpirits.toString), - ("pureAlcoholInSpirits", validPureAlcoholInSpirits.toString) + ("volumes.totalLitresVolume", validTotalSpirits.toString), + ("volumes.pureAlcoholVolume", validPureAlcoholInSpirits.toString) ) val result = route(application, request).value @@ -169,7 +171,7 @@ class DutySuspendedSpiritsControllerSpec extends SpecBase { running(application) { val request = FakeRequest(POST, dutySuspendedSpiritsRoute) - .withFormUrlEncodedBody(("totalSpirits", "value 1"), ("pureAlcoholInSpirits", "value 2")) + .withFormUrlEncodedBody(("volumes.totalLitresVolume", "value 1"), ("volumes.pureAlcoholVolume", "value 2")) val result = route(application, request).value @@ -185,8 +187,8 @@ class DutySuspendedSpiritsControllerSpec extends SpecBase { val request = FakeRequest(POST, dutySuspendedSpiritsRoute) .withFormUrlEncodedBody( - ("totalSpirits", validTotalSpirits.toString), - ("pureAlcoholInSpirits", validPureAlcoholInSpirits.toString) + ("volumes.totalLitresVolume", validTotalSpirits.toString), + ("volumes.pureAlcoholVolume", validPureAlcoholInSpirits.toString) ) val result = route(application, request).value diff --git a/test/controllers/dutySuspended/DutySuspendedWineControllerSpec.scala b/test/controllers/dutySuspended/DutySuspendedWineControllerSpec.scala index 2a9ca82e..c2c1ca5d 100644 --- a/test/controllers/dutySuspended/DutySuspendedWineControllerSpec.scala +++ b/test/controllers/dutySuspended/DutySuspendedWineControllerSpec.scala @@ -17,9 +17,8 @@ package controllers.dutySuspended import base.SpecBase -import forms.dutySuspended.DutySuspendedWineFormProvider import models.NormalMode -import models.dutySuspended.DutySuspendedWine +import models.dutySuspended.DutySuspendedVolume import navigation.{DeclareDutySuspendedDeliveriesNavigator, FakeDeclareDutySuspendedDeliveriesNavigator} import org.mockito.ArgumentMatchers.any import pages.dutySuspended.DutySuspendedWinePage @@ -28,6 +27,8 @@ import play.api.libs.json.Json import play.api.mvc.Call import play.api.test.Helpers._ import connectors.UserAnswersConnector +import forms.dutySuspended.DutySuspendedFormProvider +import models.AlcoholRegime.Wine import uk.gov.hmrc.http.HttpResponse import views.html.dutySuspended.DutySuspendedWineView @@ -36,8 +37,9 @@ import scala.concurrent.Future class DutySuspendedWineControllerSpec extends SpecBase { def onwardRoute = Call("GET", "/foo") - val formProvider = new DutySuspendedWineFormProvider() - val form = formProvider() + val formProvider = new DutySuspendedFormProvider() + val regime = Wine + val form = formProvider(regime)(getMessages(app)) lazy val dutySuspendedWineRoute = routes.DutySuspendedWineController.onPageLoad(NormalMode).url val validTotalWine = 23.45 @@ -46,8 +48,8 @@ class DutySuspendedWineControllerSpec extends SpecBase { val userAnswers = userAnswersWithWine.copy(data = Json.obj( DutySuspendedWinePage.toString -> Json.obj( - "totalWine" -> validTotalWine, - "pureAlcoholInWine" -> validPureAlcoholInWine + "totalLitresVolume" -> validTotalWine, + "pureAlcoholVolume" -> validPureAlcoholInWine ) ) ) @@ -80,7 +82,7 @@ class DutySuspendedWineControllerSpec extends SpecBase { status(result) mustEqual OK contentAsString(result) mustEqual view( - form.fill(DutySuspendedWine(validTotalWine, validPureAlcoholInWine)), + form.fill(DutySuspendedVolume(validTotalWine, validPureAlcoholInWine)), NormalMode )(request, getMessages(application)).toString } @@ -104,8 +106,8 @@ class DutySuspendedWineControllerSpec extends SpecBase { val request = FakeRequest(POST, dutySuspendedWineRoute) .withFormUrlEncodedBody( - ("totalWine", validTotalWine.toString), - ("pureAlcoholInWine", validPureAlcoholInWine.toString) + ("volumes.totalLitresVolume", validTotalWine.toString), + ("volumes.pureAlcoholVolume", validPureAlcoholInWine.toString) ) val result = route(application, request).value @@ -167,8 +169,8 @@ class DutySuspendedWineControllerSpec extends SpecBase { val request = FakeRequest(POST, dutySuspendedWineRoute) .withFormUrlEncodedBody( - ("totalWine", validTotalWine.toString), - ("pureAlcoholInWine", validPureAlcoholInWine.toString) + ("volumes.totalLitresVolume", validTotalWine.toString), + ("volumes.pureAlcoholVolume", validPureAlcoholInWine.toString) ) val result = route(application, request).value @@ -185,8 +187,8 @@ class DutySuspendedWineControllerSpec extends SpecBase { val request = FakeRequest(POST, dutySuspendedWineRoute) .withFormUrlEncodedBody( - ("totalWine", validTotalWine.toString), - ("pureAlcoholInWine", validPureAlcoholInWine.toString) + ("volumes.totalLitresVolume", validTotalWine.toString), + ("volumes.pureAlcoholVolume", validPureAlcoholInWine.toString) ) val result = route(application, request).value diff --git a/test/forms/dutySuspended/DutySuspendedBeerFormProviderSpec.scala b/test/forms/dutySuspended/DutySuspendedBeerFormProviderSpec.scala deleted file mode 100644 index d202104c..00000000 --- a/test/forms/dutySuspended/DutySuspendedBeerFormProviderSpec.scala +++ /dev/null @@ -1,120 +0,0 @@ -/* - * 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 forms.dutySuspended - -import forms.behaviours.BigDecimalFieldBehaviours -import play.api.data.FormError - -import scala.collection.immutable.ArraySeq - -class DutySuspendedBeerFormProviderSpec extends BigDecimalFieldBehaviours { - - val form = new DutySuspendedBeerFormProvider()() - - ".totalBeer" - { - - val fieldName = "totalBeer" - val requiredKey = "dutySuspendedBeer.error.totalBeer.required" - val minimum = -999999999.99 - val maximum = 999999999.99 - val decimal = 2 - - val validDataGenerator = bigDecimalsInRangeWithCommas(minimum, maximum, decimal) - - behave like fieldThatBindsValidData( - form, - fieldName, - validDataGenerator - ) - - behave like bigDecimalField( - form, - fieldName, - nonNumericError = FormError(fieldName, "dutySuspendedBeer.error.totalBeer.nonNumeric"), - decimalPlacesError = FormError(fieldName, "dutySuspendedBeer.error.totalBeer.decimalPlaces") - ) - - behave like bigDecimalFieldWithMinimum( - form, - fieldName, - minimum = minimum, - decimal = decimal, - expectedError = FormError(fieldName, "dutySuspendedBeer.error.totalBeer.minimumRequired", ArraySeq(minimum)) - ) - - behave like bigDecimalFieldWithMaximum( - form, - fieldName, - maximum = maximum, - decimal = decimal, - expectedError = FormError(fieldName, "dutySuspendedBeer.error.totalBeer.maximumRequired", ArraySeq(maximum)) - ) - - behave like mandatoryField( - form, - fieldName, - requiredError = FormError(fieldName, requiredKey) - ) - } - - ".pureAlcoholInBeer" - { - - val fieldName = "pureAlcoholInBeer" - val requiredKey = "dutySuspendedBeer.error.pureAlcoholInBeer.required" - val minimum = -999999999.9999 - val maximum = 999999999.9999 - val decimal = 4 - val validDataGenerator = bigDecimalsInRangeWithCommas(minimum, maximum, decimal) - - behave like fieldThatBindsValidData( - form, - fieldName, - validDataGenerator - ) - - behave like bigDecimalField( - form, - fieldName, - nonNumericError = FormError(fieldName, "dutySuspendedBeer.error.pureAlcoholInBeer.nonNumeric"), - decimalPlacesError = FormError(fieldName, "dutySuspendedBeer.error.pureAlcoholInBeer.decimalPlaces") - ) - - behave like bigDecimalFieldWithMinimum( - form, - fieldName, - minimum = minimum, - decimal = decimal, - expectedError = - FormError(fieldName, "dutySuspendedBeer.error.pureAlcoholInBeer.minimumRequired", ArraySeq(minimum)) - ) - - behave like bigDecimalFieldWithMaximum( - form, - fieldName, - maximum = maximum, - decimal = decimal, - expectedError = - FormError(fieldName, "dutySuspendedBeer.error.pureAlcoholInBeer.maximumRequired", ArraySeq(maximum)) - ) - - behave like mandatoryField( - form, - fieldName, - requiredError = FormError(fieldName, requiredKey) - ) - } -} diff --git a/test/forms/dutySuspended/DutySuspendedCiderFormProviderSpec.scala b/test/forms/dutySuspended/DutySuspendedCiderFormProviderSpec.scala deleted file mode 100644 index cfd4dbac..00000000 --- a/test/forms/dutySuspended/DutySuspendedCiderFormProviderSpec.scala +++ /dev/null @@ -1,121 +0,0 @@ -/* - * 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 forms.dutySuspended - -import forms.behaviours.BigDecimalFieldBehaviours -import play.api.data.FormError - -import scala.collection.immutable.ArraySeq - -class DutySuspendedCiderFormProviderSpec extends BigDecimalFieldBehaviours { - - val form = new DutySuspendedCiderFormProvider()() - - ".totalCider" - { - - val fieldName = "totalCider" - val requiredKey = "dutySuspendedCider.error.totalCider.required" - val minimum = -999999999.99 - val maximum = 999999999.99 - val decimal = 2 - - val validDataGenerator = bigDecimalsInRangeWithCommas(minimum, maximum, decimal) - - behave like fieldThatBindsValidData( - form, - fieldName, - validDataGenerator - ) - - behave like bigDecimalField( - form, - fieldName, - nonNumericError = FormError(fieldName, "dutySuspendedCider.error.totalCider.nonNumeric"), - decimalPlacesError = FormError(fieldName, "dutySuspendedCider.error.totalCider.decimalPlaces") - ) - - behave like bigDecimalFieldWithMinimum( - form, - fieldName, - minimum = minimum, - decimal = decimal, - expectedError = FormError(fieldName, "dutySuspendedCider.error.totalCider.minimumRequired", ArraySeq(minimum)) - ) - - behave like bigDecimalFieldWithMaximum( - form, - fieldName, - maximum = maximum, - decimal = decimal, - expectedError = FormError(fieldName, "dutySuspendedCider.error.totalCider.maximumRequired", ArraySeq(maximum)) - ) - - behave like mandatoryField( - form, - fieldName, - requiredError = FormError(fieldName, requiredKey) - ) - } - - ".pureAlcoholInCider" - { - - val fieldName = "pureAlcoholInCider" - val requiredKey = "dutySuspendedCider.error.pureAlcoholInCider.required" - val minimum = -999999999.9999 - val maximum = 999999999.9999 - val decimal = 4 - - val validDataGenerator = bigDecimalsInRangeWithCommas(minimum, maximum, decimal) - - behave like fieldThatBindsValidData( - form, - fieldName, - validDataGenerator - ) - - behave like bigDecimalField( - form, - fieldName, - nonNumericError = FormError(fieldName, "dutySuspendedCider.error.pureAlcoholInCider.nonNumeric"), - decimalPlacesError = FormError(fieldName, "dutySuspendedCider.error.pureAlcoholInCider.decimalPlaces") - ) - - behave like bigDecimalFieldWithMinimum( - form, - fieldName, - minimum = minimum, - decimal = decimal, - expectedError = - FormError(fieldName, "dutySuspendedCider.error.pureAlcoholInCider.minimumRequired", ArraySeq(minimum)) - ) - - behave like bigDecimalFieldWithMaximum( - form, - fieldName, - maximum = maximum, - decimal = decimal, - expectedError = - FormError(fieldName, "dutySuspendedCider.error.pureAlcoholInCider.maximumRequired", ArraySeq(maximum)) - ) - - behave like mandatoryField( - form, - fieldName, - requiredError = FormError(fieldName, requiredKey) - ) - } -} diff --git a/test/forms/dutySuspended/DutySuspendedFormProviderSpec.scala b/test/forms/dutySuspended/DutySuspendedFormProviderSpec.scala new file mode 100644 index 00000000..3297a618 --- /dev/null +++ b/test/forms/dutySuspended/DutySuspendedFormProviderSpec.scala @@ -0,0 +1,161 @@ +/* + * 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 forms.dutySuspended + +import forms.behaviours.BigDecimalFieldBehaviours +import models.dutySuspended.DutySuspendedVolume +import org.mockito.MockitoSugar.mock +import play.api.data.FormError +import play.api.i18n.Messages + +class DutySuspendedFormProviderSpec extends BigDecimalFieldBehaviours { + val regime = regimeGen.sample.value + val messages = mock[Messages] + val form = new DutySuspendedFormProvider()(regime)(messages) + + ".volumes" - { + "must bind valid data" in { + val data = Map( + "volumes.totalLitresVolume" -> "1", + "volumes.pureAlcoholVolume" -> "1" + ) + form.bind(data).value.value mustBe DutySuspendedVolume(1, 1) + } + + "must unbind valid data" in { + val data = DutySuspendedVolume(1, 1) + form.fill(data).data must contain theSameElementsAs Map( + "volumes.totalLitresVolume" -> "1", + "volumes.pureAlcoholVolume" -> "1" + ) + } + + "fail to bind when no answers are selected" in { + val data = Map.empty[String, String] + form.bind(data).errors must contain allElementsOf List( + FormError("volumes_totalLitresVolume", "dutySuspendedVolume.error.noValue.totalLitresVolume", Seq("")), + FormError("volumes_pureAlcoholVolume", "dutySuspendedVolume.error.noValue.pureAlcoholVolume", Seq("")) + ) + } + + "fail to bind when blank answer provided" in { + val data = Map( + "volumes.totalLitresVolume" -> "", + "volumes.pureAlcoholVolume" -> "" + ) + form.bind(data).errors must contain allElementsOf List( + FormError("volumes_totalLitresVolume", "dutySuspendedVolume.error.noValue.totalLitresVolume", Seq("")), + FormError("volumes_pureAlcoholVolume", "dutySuspendedVolume.error.noValue.pureAlcoholVolume", Seq("")) + ) + } + + "fail to bind when values with too many decimal places are provided" in { + val data = Map( + "volumes.totalLitresVolume" -> "1.111", + "volumes.pureAlcoholVolume" -> "1.11234" + ) + form.bind(data).errors must contain allElementsOf List( + FormError("volumes_totalLitresVolume", s"dutySuspendedVolume.error.decimalPlaces.totalLitresVolume", Seq("")), + FormError("volumes_pureAlcoholVolume", s"dutySuspendedVolume.error.decimalPlaces.pureAlcoholVolume", Seq("")) + ) + } + + "fail to bind when invalid values are provided" in { + val data = Map( + "volumes.totalLitresVolume" -> "invalid", + "volumes.pureAlcoholVolume" -> "invalid" + ) + form.bind(data).errors must contain allElementsOf List( + FormError("volumes_totalLitresVolume", "dutySuspendedVolume.error.invalid.totalLitresVolume", List("")), + FormError("volumes_pureAlcoholVolume", "dutySuspendedVolume.error.invalid.pureAlcoholVolume", List("")) + ) + } + + "fail to bind when values below minimum are provided" in { + val data = Map( + "volumes.totalLitresVolume" -> "-100000000000", + "volumes.pureAlcoholVolume" -> "-100000000000" + ) + form.bind(data).errors must contain allElementsOf List( + FormError("volumes_totalLitresVolume", "dutySuspendedVolume.error.minimumValue.totalLitresVolume", List("")), + FormError("volumes_pureAlcoholVolume", "dutySuspendedVolume.error.minimumValue.pureAlcoholVolume", List("")) + ) + } + + "fail to bind when values exceed maximum are provided" in { + val data = Map( + "volumes.totalLitresVolume" -> "100000000000", + "volumes.pureAlcoholVolume" -> "100000000000" + ) + form.bind(data).errors must contain allElementsOf List( + FormError("volumes_totalLitresVolume", "dutySuspendedVolume.error.maximumValue.totalLitresVolume", List("")), + FormError("volumes_pureAlcoholVolume", "dutySuspendedVolume.error.maximumValue.pureAlcoholVolume", List("")) + ) + } + + "fail to bind when pure alcohol volume is higher than total litres value" in { + val data = Map( + "volumes.totalLitresVolume" -> "0", + "volumes.pureAlcoholVolume" -> "2" + ) + form.bind(data).errors must contain allElementsOf List( + FormError("volumes_pureAlcoholVolume", "dutySuspendedVolume.error.lessThanExpected", List("")) + ) + } + + "fail to bind when pure alcohol volume is negative and total litres value is positive" in { + val data = Map( + "volumes.totalLitresVolume" -> "1", + "volumes.pureAlcoholVolume" -> "-2" + ) + form.bind(data).errors must contain allElementsOf List( + FormError("volumes_pureAlcoholVolume", "dutySuspendedVolume.error.incorrectSign", List("")) + ) + } + + "fail to bind when total litres value is negative and pure alcohol volume is a higher negative" in { + val data = Map( + "volumes.totalLitresVolume" -> "-11", + "volumes.pureAlcoholVolume" -> "-2" + ) + form.bind(data).errors must contain allElementsOf List( + FormError("volumes_pureAlcoholVolume", "dutySuspendedVolume.error.lessThanExpected", List("")) + ) + } + + "fail to bind when total litres value is zero and pure alcohol volume is negative" in { + val data = Map( + "volumes.totalLitresVolume" -> "0", + "volumes.pureAlcoholVolume" -> "-2" + ) + form.bind(data).errors must contain allElementsOf List( + FormError("volumes_pureAlcoholVolume", "dutySuspendedVolume.error.zeroTotalLitres", List("")) + ) + } + + "fail to bind when total litres value is positive and pure alcohol volume is zero" in { + val data = Map( + "volumes.totalLitresVolume" -> "23", + "volumes.pureAlcoholVolume" -> "0" + ) + form.bind(data).errors must contain allElementsOf List( + FormError("volumes_pureAlcoholVolume", "dutySuspendedVolume.error.zeroLPA", List("")) + ) + } + + } +} diff --git a/test/forms/dutySuspended/DutySuspendedOtherFermentedFormProviderSpec.scala b/test/forms/dutySuspended/DutySuspendedOtherFermentedFormProviderSpec.scala deleted file mode 100644 index d8396d90..00000000 --- a/test/forms/dutySuspended/DutySuspendedOtherFermentedFormProviderSpec.scala +++ /dev/null @@ -1,131 +0,0 @@ -/* - * 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 forms.dutySuspended - -import forms.behaviours.BigDecimalFieldBehaviours -import play.api.data.FormError - -import scala.collection.immutable.ArraySeq - -class DutySuspendedOtherFermentedFormProviderSpec extends BigDecimalFieldBehaviours { - - val form = new DutySuspendedOtherFermentedFormProvider()() - - ".totalOtherFermented" - { - - val fieldName = "totalOtherFermented" - val requiredKey = "dutySuspendedOtherFermented.error.totalOtherFermented.required" - val minimum = -999999999.99 - val maximum = 999999999.99 - val decimal = 2 - - val validDataGenerator = bigDecimalsInRangeWithCommas(minimum, maximum, decimal) - - behave like fieldThatBindsValidData( - form, - fieldName, - validDataGenerator - ) - - behave like bigDecimalField( - form, - fieldName, - nonNumericError = FormError(fieldName, "dutySuspendedOtherFermented.error.totalOtherFermented.nonNumeric"), - decimalPlacesError = FormError(fieldName, "dutySuspendedOtherFermented.error.totalOtherFermented.decimalPlaces") - ) - - behave like bigDecimalFieldWithMinimum( - form, - fieldName, - minimum = minimum, - decimal = decimal, - expectedError = - FormError(fieldName, "dutySuspendedOtherFermented.error.totalOtherFermented.minimumRequired", ArraySeq(minimum)) - ) - - behave like bigDecimalFieldWithMaximum( - form, - fieldName, - maximum = maximum, - decimal = decimal, - expectedError = - FormError(fieldName, "dutySuspendedOtherFermented.error.totalOtherFermented.maximumRequired", ArraySeq(maximum)) - ) - - behave like mandatoryField( - form, - fieldName, - requiredError = FormError(fieldName, requiredKey) - ) - } - - ".pureAlcoholInOtherFermented" - { - - val fieldName = "pureAlcoholInOtherFermented" - val requiredKey = "dutySuspendedOtherFermented.error.pureAlcoholInOtherFermented.required" - val minimum = -999999999.9999 - val maximum = 999999999.9999 - val decimal = 4 - - val validDataGenerator = bigDecimalsInRangeWithCommas(minimum, maximum, decimal) - - behave like fieldThatBindsValidData( - form, - fieldName, - validDataGenerator - ) - - behave like bigDecimalField( - form, - fieldName, - nonNumericError = - FormError(fieldName, "dutySuspendedOtherFermented.error.pureAlcoholInOtherFermented.nonNumeric"), - decimalPlacesError = - FormError(fieldName, "dutySuspendedOtherFermented.error.pureAlcoholInOtherFermented.decimalPlaces") - ) - - behave like bigDecimalFieldWithMinimum( - form, - fieldName, - minimum = minimum, - decimal = decimal, - expectedError = FormError( - fieldName, - "dutySuspendedOtherFermented.error.pureAlcoholInOtherFermented.minimumRequired", - ArraySeq(minimum) - ) - ) - - behave like bigDecimalFieldWithMaximum( - form, - fieldName, - maximum = maximum, - decimal = decimal, - expectedError = FormError( - fieldName, - "dutySuspendedOtherFermented.error.pureAlcoholInOtherFermented.maximumRequired", - ArraySeq(maximum) - ) - ) - - behave like mandatoryField( - form, - fieldName, - requiredError = FormError(fieldName, requiredKey) - ) - } -} diff --git a/test/forms/dutySuspended/DutySuspendedSpiritsFormProviderSpec.scala b/test/forms/dutySuspended/DutySuspendedSpiritsFormProviderSpec.scala deleted file mode 100644 index 90884381..00000000 --- a/test/forms/dutySuspended/DutySuspendedSpiritsFormProviderSpec.scala +++ /dev/null @@ -1,120 +0,0 @@ -/* - * 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 forms.dutySuspended - -import forms.behaviours.BigDecimalFieldBehaviours -import play.api.data.FormError - -import scala.collection.immutable.ArraySeq -class DutySuspendedSpiritsFormProviderSpec extends BigDecimalFieldBehaviours { - - val form = new DutySuspendedSpiritsFormProvider()() - - ".totalSpirits" - { - - val fieldName = "totalSpirits" - val requiredKey = "dutySuspendedSpirits.error.totalSpirits.required" - val minimum = -999999999.99 - val maximum = 999999999.99 - val decimal = 2 - - val validDataGenerator = bigDecimalsInRangeWithCommas(minimum, maximum, decimal) - - behave like fieldThatBindsValidData( - form, - fieldName, - validDataGenerator - ) - - behave like bigDecimalField( - form, - fieldName, - nonNumericError = FormError(fieldName, "dutySuspendedSpirits.error.totalSpirits.nonNumeric"), - decimalPlacesError = FormError(fieldName, "dutySuspendedSpirits.error.totalSpirits.decimalPlaces") - ) - - behave like bigDecimalFieldWithMinimum( - form, - fieldName, - minimum = minimum, - decimal = decimal, - expectedError = FormError(fieldName, "dutySuspendedSpirits.error.totalSpirits.minimumRequired", ArraySeq(minimum)) - ) - - behave like bigDecimalFieldWithMaximum( - form, - fieldName, - maximum = maximum, - decimal = decimal, - expectedError = FormError(fieldName, "dutySuspendedSpirits.error.totalSpirits.maximumRequired", ArraySeq(maximum)) - ) - - behave like mandatoryField( - form, - fieldName, - requiredError = FormError(fieldName, requiredKey) - ) - } - - ".pureAlcoholInSpirits" - { - - val fieldName = "pureAlcoholInSpirits" - val requiredKey = "dutySuspendedSpirits.error.pureAlcoholInSpirits.required" - val minimum = -999999999.9999 - val maximum = 999999999.9999 - val decimal = 4 - - val validDataGenerator = bigDecimalsInRangeWithCommas(minimum, maximum, decimal) - - behave like fieldThatBindsValidData( - form, - fieldName, - validDataGenerator - ) - - behave like bigDecimalField( - form, - fieldName, - nonNumericError = FormError(fieldName, "dutySuspendedSpirits.error.pureAlcoholInSpirits.nonNumeric"), - decimalPlacesError = FormError(fieldName, "dutySuspendedSpirits.error.pureAlcoholInSpirits.decimalPlaces") - ) - - behave like bigDecimalFieldWithMinimum( - form, - fieldName, - minimum = minimum, - decimal = decimal, - expectedError = - FormError(fieldName, "dutySuspendedSpirits.error.pureAlcoholInSpirits.minimumRequired", ArraySeq(minimum)) - ) - - behave like bigDecimalFieldWithMaximum( - form, - fieldName, - maximum = maximum, - decimal = decimal, - expectedError = - FormError(fieldName, "dutySuspendedSpirits.error.pureAlcoholInSpirits.maximumRequired", ArraySeq(maximum)) - ) - - behave like mandatoryField( - form, - fieldName, - requiredError = FormError(fieldName, requiredKey) - ) - } -} diff --git a/test/forms/dutySuspended/DutySuspendedWineFormProviderSpec.scala b/test/forms/dutySuspended/DutySuspendedWineFormProviderSpec.scala deleted file mode 100644 index dbdb42ce..00000000 --- a/test/forms/dutySuspended/DutySuspendedWineFormProviderSpec.scala +++ /dev/null @@ -1,121 +0,0 @@ -/* - * 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 forms.dutySuspended - -import forms.behaviours.BigDecimalFieldBehaviours -import play.api.data.FormError - -import scala.collection.immutable.ArraySeq - -class DutySuspendedWineFormProviderSpec extends BigDecimalFieldBehaviours { - - val form = new DutySuspendedWineFormProvider()() - - ".totalWine" - { - - val fieldName = "totalWine" - val requiredKey = "dutySuspendedWine.error.totalWine.required" - val minimum = -999999999.99 - val maximum = 999999999.99 - val decimal = 2 - - val validDataGenerator = bigDecimalsInRangeWithCommas(minimum, maximum, decimal) - - behave like fieldThatBindsValidData( - form, - fieldName, - validDataGenerator - ) - - behave like bigDecimalField( - form, - fieldName, - nonNumericError = FormError(fieldName, "dutySuspendedWine.error.totalWine.nonNumeric"), - decimalPlacesError = FormError(fieldName, "dutySuspendedWine.error.totalWine.decimalPlaces") - ) - - behave like bigDecimalFieldWithMinimum( - form, - fieldName, - minimum = minimum, - decimal = decimal, - expectedError = FormError(fieldName, "dutySuspendedWine.error.totalWine.minimumRequired", ArraySeq(minimum)) - ) - - behave like bigDecimalFieldWithMaximum( - form, - fieldName, - maximum = maximum, - decimal = decimal, - expectedError = FormError(fieldName, "dutySuspendedWine.error.totalWine.maximumRequired", ArraySeq(maximum)) - ) - - behave like mandatoryField( - form, - fieldName, - requiredError = FormError(fieldName, requiredKey) - ) - } - - ".pureAlcoholInWine" - { - - val fieldName = "pureAlcoholInWine" - val requiredKey = "dutySuspendedWine.error.pureAlcoholInWine.required" - val minimum = -999999999.9999 - val maximum = 999999999.9999 - val decimal = 4 - - val validDataGenerator = bigDecimalsInRangeWithCommas(minimum, maximum, decimal) - - behave like fieldThatBindsValidData( - form, - fieldName, - validDataGenerator - ) - - behave like bigDecimalField( - form, - fieldName, - nonNumericError = FormError(fieldName, "dutySuspendedWine.error.pureAlcoholInWine.nonNumeric"), - decimalPlacesError = FormError(fieldName, "dutySuspendedWine.error.pureAlcoholInWine.decimalPlaces") - ) - - behave like bigDecimalFieldWithMinimum( - form, - fieldName, - minimum = minimum, - decimal = decimal, - expectedError = - FormError(fieldName, "dutySuspendedWine.error.pureAlcoholInWine.minimumRequired", ArraySeq(minimum)) - ) - - behave like bigDecimalFieldWithMaximum( - form, - fieldName, - maximum = maximum, - decimal = decimal, - expectedError = - FormError(fieldName, "dutySuspendedWine.error.pureAlcoholInWine.maximumRequired", ArraySeq(maximum)) - ) - - behave like mandatoryField( - form, - fieldName, - requiredError = FormError(fieldName, requiredKey) - ) - } -} diff --git a/test/viewmodels/tasklist/ReturnTaskListCreatorSpec.scala b/test/viewmodels/tasklist/ReturnTaskListCreatorSpec.scala index 6b18374e..bdd3d92e 100644 --- a/test/viewmodels/tasklist/ReturnTaskListCreatorSpec.scala +++ b/test/viewmodels/tasklist/ReturnTaskListCreatorSpec.scala @@ -559,20 +559,20 @@ class ReturnTaskListCreatorSpec extends SpecBase { .copy(data = Json.obj( DutySuspendedBeerPage.toString -> Json.obj( - "totalBeer" -> validTotal, - "pureAlcoholInBeer" -> validPureAlcohol + "totalLitresVolume" -> validTotal, + "pureAlcoholVolume" -> validPureAlcohol ), DutySuspendedCiderPage.toString -> Json.obj( - "totalCider" -> validTotal, - "pureAlcoholInCider" -> validPureAlcohol + "totalLitresVolume" -> validTotal, + "pureAlcoholVolume" -> validPureAlcohol ), DutySuspendedSpiritsPage.toString -> Json.obj( - "totalSpirits" -> validTotal, - "pureAlcoholInSpirits" -> validPureAlcohol + "totalLitresVolume" -> validTotal, + "pureAlcoholVolume" -> validPureAlcohol ), DutySuspendedWinePage.toString -> Json.obj( - "totalWine" -> validTotal, - "pureAlcoholInWine" -> validPureAlcohol + "totalLitresVolume" -> validTotal, + "pureAlcoholVolume" -> validPureAlcohol ) ) ) @@ -609,24 +609,24 @@ class ReturnTaskListCreatorSpec extends SpecBase { .copy(data = Json.obj( DutySuspendedBeerPage.toString -> Json.obj( - "totalBeer" -> validTotal, - "pureAlcoholInBeer" -> validPureAlcohol + "totalLitresVolume" -> validTotal, + "pureAlcoholVolume" -> validPureAlcohol ), DutySuspendedCiderPage.toString -> Json.obj( - "totalCider" -> validTotal, - "pureAlcoholInCider" -> validPureAlcohol + "totalLitresVolume" -> validTotal, + "pureAlcoholVolume" -> validPureAlcohol ), DutySuspendedSpiritsPage.toString -> Json.obj( - "totalSpirits" -> validTotal, - "pureAlcoholInSpirits" -> validPureAlcohol + "totalLitresVolume" -> validTotal, + "pureAlcoholVolume" -> validPureAlcohol ), DutySuspendedWinePage.toString -> Json.obj( - "totalWine" -> validTotal, - "pureAlcoholInWine" -> validPureAlcohol + "totalLitresVolume" -> validTotal, + "pureAlcoholVolume" -> validPureAlcohol ), DutySuspendedOtherFermentedPage.toString -> Json.obj( - "totalOtherFermented" -> validTotal, - "pureAlcoholInOtherFermented" -> validPureAlcohol + "totalLitresVolume" -> validTotal, + "pureAlcoholVolume" -> validPureAlcohol ) ) ) @@ -664,12 +664,12 @@ class ReturnTaskListCreatorSpec extends SpecBase { .copy(data = Json.obj( DutySuspendedCiderPage.toString -> Json.obj( - "totalCider" -> validTotal, - "pureAlcoholInCider" -> validPureAlcohol + "totalLitresVolume" -> validTotal, + "pureAlcoholVolume" -> validPureAlcohol ), DutySuspendedOtherFermentedPage.toString -> Json.obj( - "totalOtherFermented" -> validTotal, - "pureAlcoholInOtherFermented" -> validPureAlcohol + "totalLitresVolume" -> validTotal, + "pureAlcoholVolume" -> validPureAlcohol ) ) ) @@ -707,16 +707,16 @@ class ReturnTaskListCreatorSpec extends SpecBase { .copy(data = Json.obj( DutySuspendedBeerPage.toString -> Json.obj( - "totalBeer" -> validTotal, - "pureAlcoholInBeer" -> validPureAlcohol + "totalLitresVolume" -> validTotal, + "pureAlcoholVolume" -> validPureAlcohol ), DutySuspendedWinePage.toString -> Json.obj( - "totalWine" -> validTotal, - "pureAlcoholInWine" -> validPureAlcohol + "totalLitresVolume" -> validTotal, + "pureAlcoholVolume" -> validPureAlcohol ), DutySuspendedSpiritsPage.toString -> Json.obj( - "totalSpirits" -> validTotal, - "pureAlcoholInSpirits" -> validPureAlcohol + "totalLitresVolume" -> validTotal, + "pureAlcoholVolume" -> validPureAlcohol ) ) ) From b28e98c0030d86b8d82bf6861a5bcb49b3cf4606 Mon Sep 17 00:00:00 2001 From: sini-george Date: Wed, 27 Nov 2024 15:58:06 +0000 Subject: [PATCH 2/3] ADR-1425 content and formatter changes --- .../dutySuspended/DutySuspendedFormProvider.scala | 1 - .../mappings/DutySuspendedVolumesFormatter.scala | 15 +++++---------- app/forms/mappings/Mappings.scala | 2 -- .../spiritsQuestions/SpiritTypeSummary.scala | 2 +- conf/messages.en | 7 +++---- .../DutySuspendedFormProviderSpec.scala | 10 ---------- 6 files changed, 9 insertions(+), 28 deletions(-) diff --git a/app/forms/dutySuspended/DutySuspendedFormProvider.scala b/app/forms/dutySuspended/DutySuspendedFormProvider.scala index 59990eec..058ec6e7 100644 --- a/app/forms/dutySuspended/DutySuspendedFormProvider.scala +++ b/app/forms/dutySuspended/DutySuspendedFormProvider.scala @@ -34,7 +34,6 @@ class DutySuspendedFormProvider @Inject() extends Mappings { "dutySuspendedVolume.error.lessThanExpected", "dutySuspendedVolume.error.incorrectSign", "dutySuspendedVolume.error.zeroTotalLitres", - "dutySuspendedVolume.error.zeroLPA", Seq(messages(s"return.regime.$regime")) ) ) diff --git a/app/forms/mappings/DutySuspendedVolumesFormatter.scala b/app/forms/mappings/DutySuspendedVolumesFormatter.scala index f60593a7..22fb7efd 100644 --- a/app/forms/mappings/DutySuspendedVolumesFormatter.scala +++ b/app/forms/mappings/DutySuspendedVolumesFormatter.scala @@ -30,7 +30,6 @@ class DutySuspendedVolumesFormatter( inconsistentKey: String, inconsistentSignKey: String, zeroTotalLitresKey: String, - zeroLPAKey: String, args: Seq[String] ) extends Formatter[DutySuspendedVolume] with Formatters { @@ -60,9 +59,9 @@ class DutySuspendedVolumesFormatter( args = args ) - private val NUMBER_OF_FIELDS = 2 - private val totalVolumeKey = "totalLitresVolume" - private val pureAlcoholKey = "pureAlcoholVolume" + private val NUMBER_OF_FIELDS = 2 + private val totalVolumeKey = "totalLitresVolume" + private val pureAlcoholKey = "pureAlcoholVolume" private val fieldKeys: List[String] = List(totalVolumeKey, pureAlcoholKey) private def requiredFieldFormError(key: String, field: String): FormError = @@ -89,12 +88,8 @@ class DutySuspendedVolumesFormatter( volumes => if (volumes.totalLitresVolume < volumes.pureAlcoholVolume) { Left(Seq(FormError(nameToId(s"$key.$pureAlcoholKey"), inconsistentKey, args))) - } - else if ((volumes.totalLitresVolume > 0) && (volumes.pureAlcoholVolume < 0)) { - Left(Seq(FormError(nameToId(s"$key.$pureAlcoholKey"), inconsistentSignKey, args))) - } - else if (volumes.totalLitresVolume != 0 && volumes.pureAlcoholVolume == 0) { - Left(Seq(FormError(nameToId(s"$key.$pureAlcoholKey"), zeroLPAKey, args))) + } else if ((volumes.totalLitresVolume > 0) && (volumes.pureAlcoholVolume < 0)) { + Left(Seq(FormError(nameToId(s"$key.$pureAlcoholKey"), inconsistentSignKey, args))) } else if (volumes.totalLitresVolume == 0 && volumes.pureAlcoholVolume < 0) { Left(Seq(FormError(nameToId(s"$key.$pureAlcoholKey"), zeroTotalLitresKey, args))) } else { diff --git a/app/forms/mappings/Mappings.scala b/app/forms/mappings/Mappings.scala index 0da9f658..9722bcb3 100644 --- a/app/forms/mappings/Mappings.scala +++ b/app/forms/mappings/Mappings.scala @@ -201,7 +201,6 @@ trait Mappings extends Formatters with Constraints { inconsistentKey: String, inconsistentSignKey: String, zeroTotalLitresKey: String, - zeroLPAKey: String, args: Seq[String] = Seq.empty ): FieldMapping[DutySuspendedVolume] = of( @@ -214,7 +213,6 @@ trait Mappings extends Formatters with Constraints { inconsistentKey, inconsistentSignKey, zeroTotalLitresKey, - zeroLPAKey, args ) ) diff --git a/app/viewmodels/checkAnswers/spiritsQuestions/SpiritTypeSummary.scala b/app/viewmodels/checkAnswers/spiritsQuestions/SpiritTypeSummary.scala index 2a6c0dee..a8e70816 100644 --- a/app/viewmodels/checkAnswers/spiritsQuestions/SpiritTypeSummary.scala +++ b/app/viewmodels/checkAnswers/spiritsQuestions/SpiritTypeSummary.scala @@ -17,7 +17,7 @@ package viewmodels.checkAnswers.spiritsQuestions import controllers.spiritsQuestions.routes -import models.{CheckMode, SpiritType, UserAnswers} +import models.{CheckMode, UserAnswers} import pages.spiritsQuestions.SpiritTypePage import play.api.i18n.Messages import play.twirl.api.HtmlFormat diff --git a/conf/messages.en b/conf/messages.en index 1f55c9af..7ad94259 100644 --- a/conf/messages.en +++ b/conf/messages.en @@ -524,10 +524,9 @@ dutySuspendedVolume.error.decimalPlaces.totalLitresVolume = Total net quantity o dutySuspendedVolume.error.maximumValue.pureAlcoholVolume = Total net quantity of pure alcohol must be less than 100 million litres dutySuspendedVolume.error.minimumValue.pureAlcoholVolume = Total net quantity of pure alcohol must be more than -100 million litres dutySuspendedVolume.error.decimalPlaces.pureAlcoholVolume = Total net quantity of pure alcohol must be a number up to 4 decimal places -dutySuspendedVolume.error.incorrectSign = Total net quantity of pure alcohol must be more than 0.0000 -dutySuspendedVolume.error.zeroTotalLitres = Total net quantity of pure alcohol must be zero if {0} is also zero -dutySuspendedVolume.error.zeroLPA = Total net quantity of pure alcohol must be more or less than zero if {0} is more or less than 0.00 -dutySuspendedVolume.error.lessThanExpected = Total net quantity of pure alcohol must be the same or less than the total net quantity of {0} +dutySuspendedVolume.error.incorrectSign = Total net quantity of pure alcohol must be zero or more +dutySuspendedVolume.error.zeroTotalLitres = Total net quantity of pure alcohol must be zero if total net quantity of {0} is also zero +dutySuspendedVolume.error.lessThanExpected = Total net quantity of pure alcohol must be the same or less than total net quantity of {0} dutySuspendedCider.title = Tell us about your duty suspended cider dutySuspendedCider.heading = Tell us about your duty suspended cider diff --git a/test/forms/dutySuspended/DutySuspendedFormProviderSpec.scala b/test/forms/dutySuspended/DutySuspendedFormProviderSpec.scala index 3297a618..eb4b3b5d 100644 --- a/test/forms/dutySuspended/DutySuspendedFormProviderSpec.scala +++ b/test/forms/dutySuspended/DutySuspendedFormProviderSpec.scala @@ -147,15 +147,5 @@ class DutySuspendedFormProviderSpec extends BigDecimalFieldBehaviours { ) } - "fail to bind when total litres value is positive and pure alcohol volume is zero" in { - val data = Map( - "volumes.totalLitresVolume" -> "23", - "volumes.pureAlcoholVolume" -> "0" - ) - form.bind(data).errors must contain allElementsOf List( - FormError("volumes_pureAlcoholVolume", "dutySuspendedVolume.error.zeroLPA", List("")) - ) - } - } } From 22a9573f6e0a0ce4145810650f40cbcd67a20d36 Mon Sep 17 00:00:00 2001 From: sini-george Date: Mon, 2 Dec 2024 16:21:21 +0000 Subject: [PATCH 3/3] ADR-1425 changes to keep the existing useranswer field names --- .../DutySuspendedBeerController.scala | 6 +- .../DutySuspendedCiderController.scala | 7 +- ...utySuspendedOtherFermentedController.scala | 11 ++- .../DutySuspendedSpiritsController.scala | 8 +- .../DutySuspendedWineController.scala | 6 +- .../DutySuspendedFormProvider.scala | 3 +- .../DutySuspendedVolumesFormatter.scala | 58 ++++++------- app/forms/mappings/Mappings.scala | 8 +- .../DutySuspendedRegimeKey.scala | 43 +++++++++ .../dutySuspended/DutySuspendedVolume.scala | 17 +++- .../AdrReturnSubmissionService.scala | 55 ++++++------ .../DutySuspendedBeerSummary.scala | 10 ++- .../DutySuspendedCiderSummary.scala | 10 ++- .../DutySuspendedOtherFermentedSummary.scala | 10 ++- .../DutySuspendedSpiritsSummary.scala | 10 ++- .../DutySuspendedWineSummary.scala | 10 ++- .../tasklist/ReturnTaskListCreator.scala | 26 ++++-- .../DutySuspendedBeerView.scala.html | 15 ++-- .../DutySuspendedCiderView.scala.html | 14 +-- ...DutySuspendedOtherFermentedView.scala.html | 15 ++-- .../DutySuspendedSpiritsView.scala.html | 14 +-- .../DutySuspendedWineView.scala.html | 14 +-- test-utils/common/TestData.scala | 20 ++--- test-utils/common/TestPages.scala | 14 +-- ...utySuspendedDeliveriesControllerSpec.scala | 24 ++--- .../DutySuspendedBeerControllerSpec.scala | 14 +-- .../DutySuspendedCiderControllerSpec.scala | 16 ++-- ...uspendedOtherFermentedControllerSpec.scala | 17 ++-- .../DutySuspendedSpiritsControllerSpec.scala | 14 +-- .../DutySuspendedWineControllerSpec.scala | 16 ++-- .../DutySuspendedFormProviderSpec.scala | 87 ++++++++++--------- .../tasklist/ReturnTaskListCreatorSpec.scala | 56 ++++++------ 32 files changed, 386 insertions(+), 262 deletions(-) create mode 100644 app/models/dutySuspended/DutySuspendedRegimeKey.scala diff --git a/app/controllers/dutySuspended/DutySuspendedBeerController.scala b/app/controllers/dutySuspended/DutySuspendedBeerController.scala index f343701d..4c541d3f 100644 --- a/app/controllers/dutySuspended/DutySuspendedBeerController.scala +++ b/app/controllers/dutySuspended/DutySuspendedBeerController.scala @@ -27,6 +27,7 @@ import play.api.i18n.{I18nSupport, MessagesApi} import play.api.mvc.{Action, AnyContent, MessagesControllerComponents} import connectors.UserAnswersConnector import models.AlcoholRegime.Beer +import models.dutySuspended.DutySuspendedVolume import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController import views.html.dutySuspended.DutySuspendedBeerView @@ -50,7 +51,7 @@ class DutySuspendedBeerController @Inject() ( def onPageLoad(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData andThen checkRegime) { implicit request => val form = formProvider(Beer) - val preparedForm = request.userAnswers.get(DutySuspendedBeerPage) match { + val preparedForm = request.userAnswers.get(DutySuspendedBeerPage)(DutySuspendedVolume.format(Beer)) match { case None => form case Some(value) => form.fill(value) } @@ -67,7 +68,8 @@ class DutySuspendedBeerController @Inject() ( formWithErrors => Future.successful(BadRequest(view(formWithErrors, mode))), value => for { - updatedAnswers <- Future.fromTry(request.userAnswers.set(DutySuspendedBeerPage, value)) + updatedAnswers <- + Future.fromTry(request.userAnswers.set(DutySuspendedBeerPage, value)(DutySuspendedVolume.format(Beer))) _ <- userAnswersConnector.set(updatedAnswers) } yield Redirect(navigator.nextPage(DutySuspendedBeerPage, mode, updatedAnswers)) ) diff --git a/app/controllers/dutySuspended/DutySuspendedCiderController.scala b/app/controllers/dutySuspended/DutySuspendedCiderController.scala index 714e850f..a9ea88da 100644 --- a/app/controllers/dutySuspended/DutySuspendedCiderController.scala +++ b/app/controllers/dutySuspended/DutySuspendedCiderController.scala @@ -27,6 +27,7 @@ import play.api.i18n.{I18nSupport, MessagesApi} import play.api.mvc.{Action, AnyContent, MessagesControllerComponents} import connectors.UserAnswersConnector import models.AlcoholRegime.Cider +import models.dutySuspended.DutySuspendedVolume import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController import views.html.dutySuspended.DutySuspendedCiderView @@ -50,7 +51,7 @@ class DutySuspendedCiderController @Inject() ( def onPageLoad(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData andThen checkRegime) { implicit request => val form = formProvider(Cider) - val preparedForm = request.userAnswers.get(DutySuspendedCiderPage) match { + val preparedForm = request.userAnswers.get(DutySuspendedCiderPage)(DutySuspendedVolume.format(Cider)) match { case None => form case Some(value) => form.fill(value) } @@ -67,7 +68,9 @@ class DutySuspendedCiderController @Inject() ( formWithErrors => Future.successful(BadRequest(view(formWithErrors, mode))), value => for { - updatedAnswers <- Future.fromTry(request.userAnswers.set(DutySuspendedCiderPage, value)) + updatedAnswers <- + Future + .fromTry(request.userAnswers.set(DutySuspendedCiderPage, value)(DutySuspendedVolume.format(Cider))) _ <- userAnswersConnector.set(updatedAnswers) } yield Redirect(navigator.nextPage(DutySuspendedCiderPage, mode, updatedAnswers)) ) diff --git a/app/controllers/dutySuspended/DutySuspendedOtherFermentedController.scala b/app/controllers/dutySuspended/DutySuspendedOtherFermentedController.scala index 06d2f6e4..076a2795 100644 --- a/app/controllers/dutySuspended/DutySuspendedOtherFermentedController.scala +++ b/app/controllers/dutySuspended/DutySuspendedOtherFermentedController.scala @@ -27,6 +27,7 @@ import play.api.i18n.{I18nSupport, MessagesApi} import play.api.mvc.{Action, AnyContent, MessagesControllerComponents} import connectors.UserAnswersConnector import models.AlcoholRegime.OtherFermentedProduct +import models.dutySuspended.DutySuspendedVolume import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController import views.html.dutySuspended.DutySuspendedOtherFermentedView @@ -50,7 +51,9 @@ class DutySuspendedOtherFermentedController @Inject() ( def onPageLoad(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData andThen checkRegime) { implicit request => val form = formProvider(OtherFermentedProduct) - val preparedForm = request.userAnswers.get(DutySuspendedOtherFermentedPage) match { + val preparedForm = request.userAnswers.get(DutySuspendedOtherFermentedPage)( + DutySuspendedVolume.format(OtherFermentedProduct) + ) match { case None => form case Some(value) => form.fill(value) } @@ -67,7 +70,11 @@ class DutySuspendedOtherFermentedController @Inject() ( formWithErrors => Future.successful(BadRequest(view(formWithErrors, mode))), value => for { - updatedAnswers <- Future.fromTry(request.userAnswers.set(DutySuspendedOtherFermentedPage, value)) + updatedAnswers <- Future.fromTry( + request.userAnswers.set(DutySuspendedOtherFermentedPage, value)( + DutySuspendedVolume.format(OtherFermentedProduct) + ) + ) _ <- userAnswersConnector.set(updatedAnswers) } yield Redirect(navigator.nextPage(DutySuspendedOtherFermentedPage, mode, updatedAnswers)) ) diff --git a/app/controllers/dutySuspended/DutySuspendedSpiritsController.scala b/app/controllers/dutySuspended/DutySuspendedSpiritsController.scala index 0989b56e..8b06448c 100644 --- a/app/controllers/dutySuspended/DutySuspendedSpiritsController.scala +++ b/app/controllers/dutySuspended/DutySuspendedSpiritsController.scala @@ -27,6 +27,7 @@ import play.api.i18n.{I18nSupport, MessagesApi} import play.api.mvc.{Action, AnyContent, MessagesControllerComponents} import connectors.UserAnswersConnector import models.AlcoholRegime.Spirits +import models.dutySuspended.DutySuspendedVolume import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController import views.html.dutySuspended.DutySuspendedSpiritsView @@ -50,7 +51,7 @@ class DutySuspendedSpiritsController @Inject() ( def onPageLoad(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData andThen checkRegime) { implicit request => val form = formProvider(Spirits) - val preparedForm = request.userAnswers.get(DutySuspendedSpiritsPage) match { + val preparedForm = request.userAnswers.get(DutySuspendedSpiritsPage)(DutySuspendedVolume.format(Spirits)) match { case None => form case Some(value) => form.fill(value) } @@ -67,7 +68,10 @@ class DutySuspendedSpiritsController @Inject() ( formWithErrors => Future.successful(BadRequest(view(formWithErrors, mode))), value => for { - updatedAnswers <- Future.fromTry(request.userAnswers.set(DutySuspendedSpiritsPage, value)) + updatedAnswers <- + Future.fromTry( + request.userAnswers.set(DutySuspendedSpiritsPage, value)(DutySuspendedVolume.format(Spirits)) + ) _ <- userAnswersConnector.set(updatedAnswers) } yield Redirect(navigator.nextPage(DutySuspendedSpiritsPage, mode, updatedAnswers)) ) diff --git a/app/controllers/dutySuspended/DutySuspendedWineController.scala b/app/controllers/dutySuspended/DutySuspendedWineController.scala index 46776f87..15e20768 100644 --- a/app/controllers/dutySuspended/DutySuspendedWineController.scala +++ b/app/controllers/dutySuspended/DutySuspendedWineController.scala @@ -27,6 +27,7 @@ import play.api.i18n.{I18nSupport, MessagesApi} import play.api.mvc.{Action, AnyContent, MessagesControllerComponents} import connectors.UserAnswersConnector import models.AlcoholRegime.Wine +import models.dutySuspended.DutySuspendedVolume import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController import views.html.dutySuspended.DutySuspendedWineView @@ -50,7 +51,7 @@ class DutySuspendedWineController @Inject() ( def onPageLoad(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData andThen checkRegime) { implicit request => val form = formProvider(Wine) - val preparedForm = request.userAnswers.get(DutySuspendedWinePage) match { + val preparedForm = request.userAnswers.get(DutySuspendedWinePage)(DutySuspendedVolume.format(Wine)) match { case None => form case Some(value) => form.fill(value) } @@ -67,7 +68,8 @@ class DutySuspendedWineController @Inject() ( formWithErrors => Future.successful(BadRequest(view(formWithErrors, mode))), value => for { - updatedAnswers <- Future.fromTry(request.userAnswers.set(DutySuspendedWinePage, value)) + updatedAnswers <- + Future.fromTry(request.userAnswers.set(DutySuspendedWinePage, value)(DutySuspendedVolume.format(Wine))) _ <- userAnswersConnector.set(updatedAnswers) } yield Redirect(navigator.nextPage(DutySuspendedWinePage, mode, updatedAnswers)) ) diff --git a/app/forms/dutySuspended/DutySuspendedFormProvider.scala b/app/forms/dutySuspended/DutySuspendedFormProvider.scala index 058ec6e7..6c2edb59 100644 --- a/app/forms/dutySuspended/DutySuspendedFormProvider.scala +++ b/app/forms/dutySuspended/DutySuspendedFormProvider.scala @@ -34,7 +34,8 @@ class DutySuspendedFormProvider @Inject() extends Mappings { "dutySuspendedVolume.error.lessThanExpected", "dutySuspendedVolume.error.incorrectSign", "dutySuspendedVolume.error.zeroTotalLitres", - Seq(messages(s"return.regime.$regime")) + Seq(messages(s"return.regime.$regime")), + regime ) ) } diff --git a/app/forms/mappings/DutySuspendedVolumesFormatter.scala b/app/forms/mappings/DutySuspendedVolumesFormatter.scala index 22fb7efd..8e2202d3 100644 --- a/app/forms/mappings/DutySuspendedVolumesFormatter.scala +++ b/app/forms/mappings/DutySuspendedVolumesFormatter.scala @@ -17,7 +17,8 @@ package forms.mappings import config.Constants -import models.dutySuspended.DutySuspendedVolume +import models.AlcoholRegime +import models.dutySuspended.{DutySuspendedRegimeSpecificKey, DutySuspendedVolume} import play.api.data.FormError import play.api.data.format.Formatter @@ -30,7 +31,8 @@ class DutySuspendedVolumesFormatter( inconsistentKey: String, inconsistentSignKey: String, zeroTotalLitresKey: String, - args: Seq[String] + args: Seq[String], + regime: AlcoholRegime ) extends Formatter[DutySuspendedVolume] with Formatters { @@ -59,10 +61,8 @@ class DutySuspendedVolumesFormatter( args = args ) - private val NUMBER_OF_FIELDS = 2 - private val totalVolumeKey = "totalLitresVolume" - private val pureAlcoholKey = "pureAlcoholVolume" - private val fieldKeys: List[String] = List(totalVolumeKey, pureAlcoholKey) + private val totalVolumeKey = DutySuspendedRegimeSpecificKey.totalVolumeKey(regime) + private val pureAlcoholKey = DutySuspendedRegimeSpecificKey.pureAlcoholKey(regime) private def requiredFieldFormError(key: String, field: String): FormError = FormError(nameToId(s"${key}_$field"), s"$requiredKey.$field", args) @@ -86,11 +86,11 @@ class DutySuspendedVolumesFormatter( formatVolume(key, data).fold( errors => Left(errors), volumes => - if (volumes.totalLitresVolume < volumes.pureAlcoholVolume) { + if (volumes.total < volumes.pureAlcohol) { Left(Seq(FormError(nameToId(s"$key.$pureAlcoholKey"), inconsistentKey, args))) - } else if ((volumes.totalLitresVolume > 0) && (volumes.pureAlcoholVolume < 0)) { + } else if ((volumes.total > 0) && (volumes.pureAlcohol < 0)) { Left(Seq(FormError(nameToId(s"$key.$pureAlcoholKey"), inconsistentSignKey, args))) - } else if (volumes.totalLitresVolume == 0 && volumes.pureAlcoholVolume < 0) { + } else if (volumes.total == 0 && volumes.pureAlcohol < 0) { Left(Seq(FormError(nameToId(s"$key.$pureAlcoholKey"), zeroTotalLitresKey, args))) } else { Right(volumes) @@ -98,30 +98,30 @@ class DutySuspendedVolumesFormatter( ) override def bind(key: String, data: Map[String, String]): Either[Seq[FormError], DutySuspendedVolume] = { - val fields = fieldKeys.map { field => - field -> data.get(s"$key.$field").filter(_.nonEmpty) - }.toMap - - lazy val missingFields = fields - .withFilter(_._2.isEmpty) - .map(_._1) - .toList - - fields.count(_._2.isDefined) match { - case NUMBER_OF_FIELDS => - checkValues(key, data) - case _ => - Left( - missingFields.map { field => - requiredFieldFormError(key, field) - } - ) + val totalLitresResult = validateField(totalVolumeKey, key, data, volumeFormatter) + val pureAlcoholResult = validateField(pureAlcoholKey, key, data, pureAlcoholBigDecimalFormatter) + val allErrors = totalLitresResult.left.toSeq.flatten ++ pureAlcoholResult.left.toSeq.flatten + if (allErrors.nonEmpty) { + Left(allErrors) + } else { + checkValues(key, data) } } + private def validateField( + field: String, + key: String, + data: Map[String, String], + formatter: String => BigDecimalFieldFormatter + ): Either[Seq[FormError], BigDecimal] = + data.get(s"$key.$field").filter(_.nonEmpty) match { + case Some(_) => formatter(field).bind(s"$key.$field", data) + case None => Left(Seq(requiredFieldFormError(key, field))) + } + override def unbind(key: String, value: DutySuspendedVolume): Map[String, String] = Map( - s"$key.$totalVolumeKey" -> value.totalLitresVolume.toString, - s"$key.$pureAlcoholKey" -> value.pureAlcoholVolume.toString + s"$key.$totalVolumeKey" -> value.total.toString, + s"$key.$pureAlcoholKey" -> value.pureAlcohol.toString ) } diff --git a/app/forms/mappings/Mappings.scala b/app/forms/mappings/Mappings.scala index 9722bcb3..30733f16 100644 --- a/app/forms/mappings/Mappings.scala +++ b/app/forms/mappings/Mappings.scala @@ -21,7 +21,7 @@ import models.declareDuty.{VolumeAndRateByTaxType, VolumesByTaxType} import java.time.{LocalDate, YearMonth} import play.api.data.FieldMapping import play.api.data.Forms.of -import models.Enumerable +import models.{AlcoholRegime, Enumerable} import models.adjustment.{AdjustmentVolume, AdjustmentVolumeWithSPR, SpoiltVolumeWithDuty} import models.dutySuspended.DutySuspendedVolume @@ -201,7 +201,8 @@ trait Mappings extends Formatters with Constraints { inconsistentKey: String, inconsistentSignKey: String, zeroTotalLitresKey: String, - args: Seq[String] = Seq.empty + args: Seq[String] = Seq.empty, + regime: AlcoholRegime ): FieldMapping[DutySuspendedVolume] = of( new DutySuspendedVolumesFormatter( @@ -213,7 +214,8 @@ trait Mappings extends Formatters with Constraints { inconsistentKey, inconsistentSignKey, zeroTotalLitresKey, - args + args, + regime ) ) } diff --git a/app/models/dutySuspended/DutySuspendedRegimeKey.scala b/app/models/dutySuspended/DutySuspendedRegimeKey.scala new file mode 100644 index 00000000..a21c8a3f --- /dev/null +++ b/app/models/dutySuspended/DutySuspendedRegimeKey.scala @@ -0,0 +1,43 @@ +/* + * 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.dutySuspended + +import models.AlcoholRegime + +trait DutySuspendedRegimeKeyProvider { + def totalVolumeKey(regime: AlcoholRegime): String + + def pureAlcoholKey(regime: AlcoholRegime): String +} + +object DutySuspendedRegimeSpecificKey extends DutySuspendedRegimeKeyProvider { + override def totalVolumeKey(regime: AlcoholRegime): String = regime match { + case AlcoholRegime.Beer => "totalBeer" + case AlcoholRegime.Cider => "totalCider" + case AlcoholRegime.OtherFermentedProduct => "totalOtherFermented" + case AlcoholRegime.Wine => "totalWine" + case AlcoholRegime.Spirits => "totalSpirits" + } + + override def pureAlcoholKey(regime: AlcoholRegime): String = regime match { + case AlcoholRegime.Beer => "pureAlcoholInBeer" + case AlcoholRegime.Cider => "pureAlcoholInCider" + case AlcoholRegime.OtherFermentedProduct => "pureAlcoholInOtherFermented" + case AlcoholRegime.Wine => "pureAlcoholInWine" + case AlcoholRegime.Spirits => "pureAlcoholInSpirits" + } +} \ No newline at end of file diff --git a/app/models/dutySuspended/DutySuspendedVolume.scala b/app/models/dutySuspended/DutySuspendedVolume.scala index 37c9fa05..9bcde529 100644 --- a/app/models/dutySuspended/DutySuspendedVolume.scala +++ b/app/models/dutySuspended/DutySuspendedVolume.scala @@ -16,10 +16,21 @@ package models.dutySuspended +import models.AlcoholRegime import play.api.libs.json._ -case class DutySuspendedVolume(totalLitresVolume: BigDecimal, pureAlcoholVolume: BigDecimal) - +case class DutySuspendedVolume(total: BigDecimal, pureAlcohol: BigDecimal) object DutySuspendedVolume { - implicit val format: OFormat[DutySuspendedVolume] = Json.format[DutySuspendedVolume] + implicit def reads(regime: AlcoholRegime): Reads[DutySuspendedVolume] = (json: JsValue) => + for { + total <- (json \ DutySuspendedRegimeSpecificKey.totalVolumeKey(regime)).validate[BigDecimal] + pureAlcohol <- (json \ DutySuspendedRegimeSpecificKey.pureAlcoholKey(regime)).validate[BigDecimal] + } yield DutySuspendedVolume(total, pureAlcohol) + implicit def writes(regime: AlcoholRegime): OWrites[DutySuspendedVolume] = (volume: DutySuspendedVolume) => { + Json.obj( + DutySuspendedRegimeSpecificKey.totalVolumeKey(regime) -> volume.total, + DutySuspendedRegimeSpecificKey.pureAlcoholKey(regime) -> volume.pureAlcohol + ) + } + implicit def format(regime: AlcoholRegime): OFormat[DutySuspendedVolume] = OFormat(reads(regime), writes(regime)) } diff --git a/app/services/checkAndSubmit/AdrReturnSubmissionService.scala b/app/services/checkAndSubmit/AdrReturnSubmissionService.scala index e9c4211f..f3d5fb6b 100644 --- a/app/services/checkAndSubmit/AdrReturnSubmissionService.scala +++ b/app/services/checkAndSubmit/AdrReturnSubmissionService.scala @@ -20,11 +20,13 @@ import cats.data.EitherT import com.google.inject.ImplementedBy import config.FrontendAppConfig import connectors.AlcoholDutyCalculatorConnector +import models.AlcoholRegime.{Beer, Cider, OtherFermentedProduct, Spirits, Wine} import models.adjustment.{AdjustmentEntry, AdjustmentType} import models.adjustment.AdjustmentType.{Drawback, Overdeclaration, RepackagedDraughtProducts, Spoilt, Underdeclaration} import models.checkAndSubmit.{AdrAdjustmentItem, AdrAdjustments, AdrAlcoholQuantity, AdrDuty, AdrDutyDeclared, AdrDutyDeclaredItem, AdrDutySuspended, AdrDutySuspendedAlcoholRegime, AdrDutySuspendedProduct, AdrOtherIngredient, AdrRepackagedDraughtAdjustmentItem, AdrReturnSubmission, AdrSpirits, AdrSpiritsGrainsQuantities, AdrSpiritsIngredientsVolumes, AdrSpiritsProduced, AdrSpiritsVolumes, AdrTotals, AdrTypeOfSpirit, AdrUnitOfMeasure} import models.declareDuty.AlcoholDuty import models.checkAndSubmit.AdrTypeOfSpirit.fromSpiritsType +import models.dutySuspended.DutySuspendedVolume import models.{AlcoholRegime, ReturnPeriod, UserAnswers} import models.spiritsQuestions.{EthyleneGasOrMolassesUsed, OtherMaltedGrains} import pages.QuestionPage @@ -249,75 +251,76 @@ class AdrReturnSubmissionServiceImpl @Inject() ( ): EitherT[Future, String, Seq[AdrDutySuspendedProduct]] = for { beerDutySuspended <- if (userAnswers.regimes.hasBeer()) { - getValue(userAnswers, DutySuspendedBeerPage) + getValue(userAnswers, DutySuspendedBeerPage)(DutySuspendedVolume.format(Beer)) .map(dutySuspendedBeer => Some( AdrDutySuspendedProduct( regime = AdrDutySuspendedAlcoholRegime.Beer, suspendedQuantity = AdrAlcoholQuantity( - dutySuspendedBeer.totalLitresVolume, - dutySuspendedBeer.pureAlcoholVolume + dutySuspendedBeer.total, + dutySuspendedBeer.pureAlcohol ) ) ) ) } else EitherT.rightT[Future, String](None) ciderDutySuspended <- if (userAnswers.regimes.hasCider()) - getValue(userAnswers, DutySuspendedCiderPage) + getValue(userAnswers, DutySuspendedCiderPage)(DutySuspendedVolume.format(Cider)) .map(dutySuspendedCider => Some( AdrDutySuspendedProduct( regime = AdrDutySuspendedAlcoholRegime.Cider, suspendedQuantity = AdrAlcoholQuantity( - dutySuspendedCider.totalLitresVolume, - dutySuspendedCider.pureAlcoholVolume + dutySuspendedCider.total, + dutySuspendedCider.pureAlcohol ) ) ) ) else EitherT.rightT[Future, String](None) spiritsDutySuspended <- if (userAnswers.regimes.hasSpirits()) - getValue(userAnswers, DutySuspendedSpiritsPage) + getValue(userAnswers, DutySuspendedSpiritsPage)(DutySuspendedVolume.format(Spirits)) .map(dutySuspendedSpirits => Some( AdrDutySuspendedProduct( regime = AdrDutySuspendedAlcoholRegime.Spirits, suspendedQuantity = AdrAlcoholQuantity( - dutySuspendedSpirits.totalLitresVolume, - dutySuspendedSpirits.pureAlcoholVolume + dutySuspendedSpirits.total, + dutySuspendedSpirits.pureAlcohol ) ) ) ) else EitherT.rightT[Future, String](None) wineDutySuspended <- if (userAnswers.regimes.hasWine()) - getValue(userAnswers, DutySuspendedWinePage) + getValue(userAnswers, DutySuspendedWinePage)(DutySuspendedVolume.format(Wine)) .map(dutySuspendedWine => Some( AdrDutySuspendedProduct( regime = AdrDutySuspendedAlcoholRegime.Wine, suspendedQuantity = AdrAlcoholQuantity( - dutySuspendedWine.totalLitresVolume, - dutySuspendedWine.pureAlcoholVolume - ) - ) - ) - ) - else EitherT.rightT[Future, String](None) - otherFermentedDutySuspended <- if (userAnswers.regimes.hasOtherFermentedProduct()) - getValue(userAnswers, DutySuspendedOtherFermentedPage) - .map(dutySuspendedOtherFermentedProducts => - Some( - AdrDutySuspendedProduct( - regime = AdrDutySuspendedAlcoholRegime.OtherFermentedProduct, - suspendedQuantity = AdrAlcoholQuantity( - dutySuspendedOtherFermentedProducts.totalLitresVolume, - dutySuspendedOtherFermentedProducts.pureAlcoholVolume + dutySuspendedWine.total, + dutySuspendedWine.pureAlcohol ) ) ) ) else EitherT.rightT[Future, String](None) + otherFermentedDutySuspended <- + if (userAnswers.regimes.hasOtherFermentedProduct()) + getValue(userAnswers, DutySuspendedOtherFermentedPage)(DutySuspendedVolume.format(OtherFermentedProduct)) + .map(dutySuspendedOtherFermentedProducts => + Some( + AdrDutySuspendedProduct( + regime = AdrDutySuspendedAlcoholRegime.OtherFermentedProduct, + suspendedQuantity = AdrAlcoholQuantity( + dutySuspendedOtherFermentedProducts.total, + dutySuspendedOtherFermentedProducts.pureAlcohol + ) + ) + ) + ) + else EitherT.rightT[Future, String](None) } yield Seq( beerDutySuspended, ciderDutySuspended, diff --git a/app/viewmodels/checkAnswers/dutySuspended/DutySuspendedBeerSummary.scala b/app/viewmodels/checkAnswers/dutySuspended/DutySuspendedBeerSummary.scala index 0d70077b..5dc57af1 100644 --- a/app/viewmodels/checkAnswers/dutySuspended/DutySuspendedBeerSummary.scala +++ b/app/viewmodels/checkAnswers/dutySuspended/DutySuspendedBeerSummary.scala @@ -17,6 +17,8 @@ package viewmodels.checkAnswers.dutySuspended import controllers.dutySuspended.routes +import models.AlcoholRegime.Beer +import models.dutySuspended.DutySuspendedVolume import models.{CheckMode, UserAnswers} import pages.dutySuspended.DutySuspendedBeerPage import play.api.i18n.Messages @@ -27,10 +29,10 @@ import viewmodels.implicits._ object DutySuspendedBeerSummary { def totalVolumeRow(answers: UserAnswers)(implicit messages: Messages): Option[SummaryListRow] = - answers.get(DutySuspendedBeerPage).map { answer => + answers.get(DutySuspendedBeerPage)(DutySuspendedVolume.format(Beer)).map { answer => SummaryListRowViewModel( key = "dutySuspendedBeer.totalBeer.checkYourAnswersLabel", - value = ValueViewModel(s"${messages("site.2DP", answer.totalLitresVolume)} ${messages("site.unit.litres")}"), + value = ValueViewModel(s"${messages("site.2DP", answer.total)} ${messages("site.unit.litres")}"), actions = Seq( ActionItemViewModel("site.change", routes.DutySuspendedBeerController.onPageLoad(CheckMode).url) .withVisuallyHiddenText(messages("dutySuspendedBeer.totalBeer.change.hidden")) @@ -40,11 +42,11 @@ object DutySuspendedBeerSummary { } def pureAlcoholRow(answers: UserAnswers)(implicit messages: Messages): Option[SummaryListRow] = - answers.get(DutySuspendedBeerPage).map { answer => + answers.get(DutySuspendedBeerPage)(DutySuspendedVolume.format(Beer)).map { answer => SummaryListRowViewModel( key = "dutySuspendedBeer.pureAlcoholInBeer.checkYourAnswersLabel", value = ValueViewModel( - s"${messages("site.4DP", answer.pureAlcoholVolume)} ${messages("site.unit.litres")}" + s"${messages("site.4DP", answer.pureAlcohol)} ${messages("site.unit.litres")}" ), actions = Seq( ActionItemViewModel("site.change", routes.DutySuspendedBeerController.onPageLoad(CheckMode).url) diff --git a/app/viewmodels/checkAnswers/dutySuspended/DutySuspendedCiderSummary.scala b/app/viewmodels/checkAnswers/dutySuspended/DutySuspendedCiderSummary.scala index 627efa28..9a615504 100644 --- a/app/viewmodels/checkAnswers/dutySuspended/DutySuspendedCiderSummary.scala +++ b/app/viewmodels/checkAnswers/dutySuspended/DutySuspendedCiderSummary.scala @@ -17,6 +17,8 @@ package viewmodels.checkAnswers.dutySuspended import controllers.dutySuspended.routes +import models.AlcoholRegime.Cider +import models.dutySuspended.DutySuspendedVolume import models.{CheckMode, UserAnswers} import pages.dutySuspended.DutySuspendedCiderPage import play.api.i18n.Messages @@ -27,10 +29,10 @@ import viewmodels.implicits._ object DutySuspendedCiderSummary { def totalVolumeRow(answers: UserAnswers)(implicit messages: Messages): Option[SummaryListRow] = - answers.get(DutySuspendedCiderPage).map { answer => + answers.get(DutySuspendedCiderPage)(DutySuspendedVolume.format(Cider)).map { answer => SummaryListRowViewModel( key = "dutySuspendedCider.totalCider.checkYourAnswersLabel", - value = ValueViewModel(s"${messages("site.2DP", answer.totalLitresVolume)} ${messages("site.unit.litres")}"), + value = ValueViewModel(s"${messages("site.2DP", answer.total)} ${messages("site.unit.litres")}"), actions = Seq( ActionItemViewModel("site.change", routes.DutySuspendedCiderController.onPageLoad(CheckMode).url) .withVisuallyHiddenText(messages("dutySuspendedCider.totalCider.change.hidden")) @@ -39,11 +41,11 @@ object DutySuspendedCiderSummary { } def pureAlcoholRow(answers: UserAnswers)(implicit messages: Messages): Option[SummaryListRow] = - answers.get(DutySuspendedCiderPage).map { answer => + answers.get(DutySuspendedCiderPage)(DutySuspendedVolume.format(Cider)).map { answer => SummaryListRowViewModel( key = "dutySuspendedCider.pureAlcoholInCider.checkYourAnswersLabel", value = ValueViewModel( - s"${messages("site.4DP", answer.pureAlcoholVolume)} ${messages("site.unit.litres")}" + s"${messages("site.4DP", answer.pureAlcohol)} ${messages("site.unit.litres")}" ), actions = Seq( ActionItemViewModel("site.change", routes.DutySuspendedCiderController.onPageLoad(CheckMode).url) diff --git a/app/viewmodels/checkAnswers/dutySuspended/DutySuspendedOtherFermentedSummary.scala b/app/viewmodels/checkAnswers/dutySuspended/DutySuspendedOtherFermentedSummary.scala index b8a0defd..4d7cb949 100644 --- a/app/viewmodels/checkAnswers/dutySuspended/DutySuspendedOtherFermentedSummary.scala +++ b/app/viewmodels/checkAnswers/dutySuspended/DutySuspendedOtherFermentedSummary.scala @@ -17,6 +17,8 @@ package viewmodels.checkAnswers.dutySuspended import controllers.dutySuspended.routes +import models.AlcoholRegime.OtherFermentedProduct +import models.dutySuspended.DutySuspendedVolume import models.{CheckMode, UserAnswers} import pages.dutySuspended.DutySuspendedOtherFermentedPage import play.api.i18n.Messages @@ -27,11 +29,11 @@ import viewmodels.implicits._ object DutySuspendedOtherFermentedSummary { def totalVolumeRow(answers: UserAnswers)(implicit messages: Messages): Option[SummaryListRow] = - answers.get(DutySuspendedOtherFermentedPage).map { answer => + answers.get(DutySuspendedOtherFermentedPage)(DutySuspendedVolume.format(OtherFermentedProduct)).map { answer => SummaryListRowViewModel( key = "dutySuspendedOtherFermented.totalOtherFermented.checkYourAnswersLabel", value = ValueViewModel( - s"${messages("site.2DP", answer.totalLitresVolume)} ${messages("site.unit.litres")}" + s"${messages("site.2DP", answer.total)} ${messages("site.unit.litres")}" ), actions = Seq( ActionItemViewModel("site.change", routes.DutySuspendedOtherFermentedController.onPageLoad(CheckMode).url) @@ -41,11 +43,11 @@ object DutySuspendedOtherFermentedSummary { } def pureAlcoholRow(answers: UserAnswers)(implicit messages: Messages): Option[SummaryListRow] = - answers.get(DutySuspendedOtherFermentedPage).map { answer => + answers.get(DutySuspendedOtherFermentedPage)(DutySuspendedVolume.format(OtherFermentedProduct)).map { answer => SummaryListRowViewModel( key = "dutySuspendedOtherFermented.pureAlcoholInOtherFermented.checkYourAnswersLabel", value = ValueViewModel( - s"${messages("site.4DP", answer.pureAlcoholVolume)} ${messages("site.unit.litres")}" + s"${messages("site.4DP", answer.pureAlcohol)} ${messages("site.unit.litres")}" ), actions = Seq( ActionItemViewModel("site.change", routes.DutySuspendedOtherFermentedController.onPageLoad(CheckMode).url) diff --git a/app/viewmodels/checkAnswers/dutySuspended/DutySuspendedSpiritsSummary.scala b/app/viewmodels/checkAnswers/dutySuspended/DutySuspendedSpiritsSummary.scala index f4e746ee..6560392f 100644 --- a/app/viewmodels/checkAnswers/dutySuspended/DutySuspendedSpiritsSummary.scala +++ b/app/viewmodels/checkAnswers/dutySuspended/DutySuspendedSpiritsSummary.scala @@ -17,6 +17,8 @@ package viewmodels.checkAnswers.dutySuspended import controllers.dutySuspended.routes +import models.AlcoholRegime.Spirits +import models.dutySuspended.DutySuspendedVolume import models.{CheckMode, UserAnswers} import pages.dutySuspended.DutySuspendedSpiritsPage import play.api.i18n.Messages @@ -27,10 +29,10 @@ import viewmodels.implicits._ object DutySuspendedSpiritsSummary { def totalVolumeRow(answers: UserAnswers)(implicit messages: Messages): Option[SummaryListRow] = - answers.get(DutySuspendedSpiritsPage).map { answer => + answers.get(DutySuspendedSpiritsPage)(DutySuspendedVolume.format(Spirits)).map { answer => SummaryListRowViewModel( key = "dutySuspendedSpirits.totalSpirits.checkYourAnswersLabel", - value = ValueViewModel(s"${messages("site.2DP", answer.totalLitresVolume)} ${messages("site.unit.litres")}"), + value = ValueViewModel(s"${messages("site.2DP", answer.total)} ${messages("site.unit.litres")}"), actions = Seq( ActionItemViewModel("site.change", routes.DutySuspendedSpiritsController.onPageLoad(CheckMode).url) .withVisuallyHiddenText(messages("dutySuspendedSpirits.totalSpirits.change.hidden")) @@ -39,11 +41,11 @@ object DutySuspendedSpiritsSummary { } def pureAlcoholRow(answers: UserAnswers)(implicit messages: Messages): Option[SummaryListRow] = - answers.get(DutySuspendedSpiritsPage).map { answer => + answers.get(DutySuspendedSpiritsPage)(DutySuspendedVolume.format(Spirits)).map { answer => SummaryListRowViewModel( key = "dutySuspendedSpirits.pureAlcoholInSpirits.checkYourAnswersLabel", value = ValueViewModel( - s"${messages("site.4DP", answer.pureAlcoholVolume)} ${messages("site.unit.litres")}" + s"${messages("site.4DP", answer.pureAlcohol)} ${messages("site.unit.litres")}" ), actions = Seq( ActionItemViewModel("site.change", routes.DutySuspendedSpiritsController.onPageLoad(CheckMode).url) diff --git a/app/viewmodels/checkAnswers/dutySuspended/DutySuspendedWineSummary.scala b/app/viewmodels/checkAnswers/dutySuspended/DutySuspendedWineSummary.scala index d3e5727e..c0d79591 100644 --- a/app/viewmodels/checkAnswers/dutySuspended/DutySuspendedWineSummary.scala +++ b/app/viewmodels/checkAnswers/dutySuspended/DutySuspendedWineSummary.scala @@ -17,6 +17,8 @@ package viewmodels.checkAnswers.dutySuspended import controllers.dutySuspended.routes +import models.AlcoholRegime.Wine +import models.dutySuspended.DutySuspendedVolume import models.{CheckMode, UserAnswers} import pages.dutySuspended.DutySuspendedWinePage import play.api.i18n.Messages @@ -27,10 +29,10 @@ import viewmodels.implicits._ object DutySuspendedWineSummary { def totalVolumeRow(answers: UserAnswers)(implicit messages: Messages): Option[SummaryListRow] = - answers.get(DutySuspendedWinePage).map { answer => + answers.get(DutySuspendedWinePage)(DutySuspendedVolume.format(Wine)).map { answer => SummaryListRowViewModel( key = "dutySuspendedWine.totalWine.checkYourAnswersLabel", - value = ValueViewModel(s"${messages("site.2DP", answer.totalLitresVolume)} ${messages("site.unit.litres")}"), + value = ValueViewModel(s"${messages("site.2DP", answer.total)} ${messages("site.unit.litres")}"), actions = Seq( ActionItemViewModel("site.change", routes.DutySuspendedWineController.onPageLoad(CheckMode).url) .withVisuallyHiddenText(messages("dutySuspendedWine.totalWine.change.hidden")) @@ -39,11 +41,11 @@ object DutySuspendedWineSummary { } def pureAlcoholRow(answers: UserAnswers)(implicit messages: Messages): Option[SummaryListRow] = - answers.get(DutySuspendedWinePage).map { answer => + answers.get(DutySuspendedWinePage)(DutySuspendedVolume.format(Wine)).map { answer => SummaryListRowViewModel( key = "dutySuspendedWine.pureAlcoholInWine.checkYourAnswersLabel", value = ValueViewModel( - s"${messages("site.4DP", answer.pureAlcoholVolume)} ${messages("site.unit.litres")}" + s"${messages("site.4DP", answer.pureAlcohol)} ${messages("site.unit.litres")}" ), actions = Seq( ActionItemViewModel("site.change", routes.DutySuspendedWineController.onPageLoad(CheckMode).url) diff --git a/app/viewmodels/tasklist/ReturnTaskListCreator.scala b/app/viewmodels/tasklist/ReturnTaskListCreator.scala index a78fd9f9..8bb558ee 100644 --- a/app/viewmodels/tasklist/ReturnTaskListCreator.scala +++ b/app/viewmodels/tasklist/ReturnTaskListCreator.scala @@ -17,7 +17,9 @@ package viewmodels.tasklist import config.Constants +import models.AlcoholRegime.{Beer, Cider, OtherFermentedProduct, Spirits, Wine} import models.adjustment.AdjustmentType +import models.dutySuspended.DutySuspendedVolume import models.{AlcoholRegime, AlcoholRegimes, CheckMode, Mode, NormalMode, SpiritType, UserAnswers} import pages.QuestionPage import pages.adjustment.{AdjustmentEntryListPage, AdjustmentListPage, CurrentAdjustmentEntryPage, DeclareAdjustmentQuestionPage, OverDeclarationReasonPage, OverDeclarationTotalPage, UnderDeclarationReasonPage, UnderDeclarationTotalPage} @@ -224,13 +226,27 @@ class ReturnTaskListCreator @Inject() () { private def returnDSDJourneyTaskListItem(userAnswers: UserAnswers)(implicit messages: Messages): TaskListItem = { val getDeclarationState = () => { val regimes = userAnswers.regimes - val maybeBeer = if (regimes.hasBeer()) Some(userAnswers.get(DutySuspendedBeerPage).isDefined) else None - val maybeCider = if (regimes.hasCider()) Some(userAnswers.get(DutySuspendedCiderPage).isDefined) else None - val maybeWine = if (regimes.hasWine()) Some(userAnswers.get(DutySuspendedWinePage).isDefined) else None + val maybeBeer = + if (regimes.hasBeer()) Some(userAnswers.get(DutySuspendedBeerPage)(DutySuspendedVolume.format(Beer)).isDefined) + else None + val maybeCider = + if (regimes.hasCider()) + Some(userAnswers.get(DutySuspendedCiderPage)(DutySuspendedVolume.format(Cider)).isDefined) + else None + val maybeWine = + if (regimes.hasWine()) Some(userAnswers.get(DutySuspendedWinePage)(DutySuspendedVolume.format(Wine)).isDefined) + else None val maybeSpirits = - if (regimes.hasSpirits()) Some(userAnswers.get(DutySuspendedSpiritsPage).isDefined) else None + if (regimes.hasSpirits()) + Some(userAnswers.get(DutySuspendedSpiritsPage)(DutySuspendedVolume.format(Spirits)).isDefined) + else None val maybeOtherFermented = - if (regimes.hasOtherFermentedProduct()) Some(userAnswers.get(DutySuspendedOtherFermentedPage).isDefined) + if (regimes.hasOtherFermentedProduct()) + Some( + userAnswers + .get(DutySuspendedOtherFermentedPage)(DutySuspendedVolume.format(OtherFermentedProduct)) + .isDefined + ) else None val pagesCompleted = Seq(maybeBeer, maybeCider, maybeWine, maybeSpirits, maybeOtherFermented).flatten diff --git a/app/views/dutySuspended/DutySuspendedBeerView.scala.html b/app/views/dutySuspended/DutySuspendedBeerView.scala.html index 8bf60454..f74e7d4b 100644 --- a/app/views/dutySuspended/DutySuspendedBeerView.scala.html +++ b/app/views/dutySuspended/DutySuspendedBeerView.scala.html @@ -16,6 +16,8 @@ @import viewmodels.InputWidth._ @import components.{SectionHeading, PageHeading, Paragraph, SubHeading} +@import models.dutySuspended.DutySuspendedRegimeSpecificKey +@import models.AlcoholRegime.Beer @this( layout: templates.Layout, @@ -51,10 +53,10 @@ @govukInput( InputViewModel( field = form("volumes"), - key="totalLitresVolume", + key=DutySuspendedRegimeSpecificKey.totalVolumeKey(Beer), label = LabelViewModel(messages("dutySuspendedBeer.subheading1")).asSubheading, - errorMessageField = form("volumes_totalLitresVolume"), - value = form("volumes.totalLitresVolume").value + errorMessageField = form(s"volumes_${DutySuspendedRegimeSpecificKey.totalVolumeKey(Beer)}"), + value = form(s"volumes.${DutySuspendedRegimeSpecificKey.totalVolumeKey(Beer)}").value ) .asNumeric() .withWidth(Fixed10) @@ -65,10 +67,11 @@ @govukInput( InputViewModel( field = form("volumes"), - key="pureAlcoholVolume", + key=DutySuspendedRegimeSpecificKey.pureAlcoholKey(Beer), label = LabelViewModel(messages("dutySuspendedBeer.subheading2")).asSubheading, - errorMessageField = form("volumes_pureAlcoholVolume"), - value = form("volumes.pureAlcoholVolume").value) + errorMessageField = form(s"volumes_${DutySuspendedRegimeSpecificKey.pureAlcoholKey(Beer)}"), + value = form(s"volumes.${DutySuspendedRegimeSpecificKey.pureAlcoholKey(Beer)}").value + ) .asNumeric() .withWidth(Fixed10) .withSuffix(PrefixOrSuffix(content = messages("site.unit.litres"))) diff --git a/app/views/dutySuspended/DutySuspendedCiderView.scala.html b/app/views/dutySuspended/DutySuspendedCiderView.scala.html index 857cd299..ae97bad6 100644 --- a/app/views/dutySuspended/DutySuspendedCiderView.scala.html +++ b/app/views/dutySuspended/DutySuspendedCiderView.scala.html @@ -16,6 +16,8 @@ @import viewmodels.InputWidth._ @import components.{SectionHeading, PageHeading, Paragraph, SubHeading} +@import models.dutySuspended.DutySuspendedRegimeSpecificKey +@import models.AlcoholRegime.Cider @this( layout: templates.Layout, @@ -52,10 +54,10 @@ @govukInput( InputViewModel( field = form("volumes"), - key="totalLitresVolume", + key=DutySuspendedRegimeSpecificKey.totalVolumeKey(Cider), label = LabelViewModel(messages("dutySuspendedCider.subheading1")).asSubheading, - errorMessageField = form("volumes_totalLitresVolume"), - value = form("volumes.totalLitresVolume").value + errorMessageField = form(s"volumes_${DutySuspendedRegimeSpecificKey.totalVolumeKey(Cider)}"), + value = form(s"volumes.${DutySuspendedRegimeSpecificKey.totalVolumeKey(Cider)}").value ) .asNumeric() .withWidth(Fixed10) @@ -66,10 +68,10 @@ @govukInput( InputViewModel( field = form("volumes"), - key="pureAlcoholVolume", + key=DutySuspendedRegimeSpecificKey.pureAlcoholKey(Cider), label = LabelViewModel(messages("dutySuspendedCider.subheading2")).asSubheading, - errorMessageField = form("volumes_pureAlcoholVolume"), - value = form("volumes.pureAlcoholVolume").value + errorMessageField = form(s"volumes_${DutySuspendedRegimeSpecificKey.pureAlcoholKey(Cider)}"), + value = form(s"volumes.${DutySuspendedRegimeSpecificKey.pureAlcoholKey(Cider)}").value ) .asNumeric() .withWidth(Fixed10) diff --git a/app/views/dutySuspended/DutySuspendedOtherFermentedView.scala.html b/app/views/dutySuspended/DutySuspendedOtherFermentedView.scala.html index 311e3746..2099b3e5 100644 --- a/app/views/dutySuspended/DutySuspendedOtherFermentedView.scala.html +++ b/app/views/dutySuspended/DutySuspendedOtherFermentedView.scala.html @@ -16,6 +16,8 @@ @import viewmodels.InputWidth._ @import components.{SectionHeading, PageHeading, Paragraph, SubHeading} +@import models.dutySuspended.DutySuspendedRegimeSpecificKey +@import models.AlcoholRegime.OtherFermentedProduct @this( layout: templates.Layout, @@ -51,10 +53,11 @@ @govukInput( InputViewModel( field = form("volumes"), - key="totalLitresVolume", + key=DutySuspendedRegimeSpecificKey.totalVolumeKey(OtherFermentedProduct), label = LabelViewModel(messages("dutySuspendedOtherFermented.subheading1")).asSubheading, - errorMessageField = form("volumes_totalLitresVolume"), - value = form("volumes.totalLitresVolume").value) + errorMessageField = form(s"volumes_${DutySuspendedRegimeSpecificKey.totalVolumeKey(OtherFermentedProduct)}"), + value = form(s"volumes.${DutySuspendedRegimeSpecificKey.totalVolumeKey(OtherFermentedProduct)}").value + ) .asNumeric() .withWidth(Fixed10) .withSuffix(PrefixOrSuffix(content = messages("site.unit.litres"))) @@ -64,10 +67,10 @@ @govukInput( InputViewModel( field = form("volumes"), - key="pureAlcoholVolume", + key=DutySuspendedRegimeSpecificKey.pureAlcoholKey(OtherFermentedProduct), label = LabelViewModel(messages("dutySuspendedOtherFermented.subheading2")).asSubheading, - errorMessageField = form("volumes_pureAlcoholVolume"), - value = form("volumes.pureAlcoholVolume").value + errorMessageField = form(s"volumes_${DutySuspendedRegimeSpecificKey.pureAlcoholKey(OtherFermentedProduct)}"), + value = form(s"volumes.${DutySuspendedRegimeSpecificKey.pureAlcoholKey(OtherFermentedProduct)}").value ) .asNumeric() .withWidth(Fixed10) diff --git a/app/views/dutySuspended/DutySuspendedSpiritsView.scala.html b/app/views/dutySuspended/DutySuspendedSpiritsView.scala.html index 1bd6500a..e8ff2f3a 100644 --- a/app/views/dutySuspended/DutySuspendedSpiritsView.scala.html +++ b/app/views/dutySuspended/DutySuspendedSpiritsView.scala.html @@ -16,6 +16,8 @@ @import viewmodels.InputWidth._ @import components.{SectionHeading, PageHeading, Paragraph, SubHeading} +@import models.dutySuspended.DutySuspendedRegimeSpecificKey +@import models.AlcoholRegime.Spirits @this( layout: templates.Layout, @@ -51,10 +53,10 @@ @govukInput( InputViewModel( field = form("volumes"), - key="totalLitresVolume", + key=DutySuspendedRegimeSpecificKey.totalVolumeKey(Spirits), label = LabelViewModel(messages("dutySuspendedSpirits.subheading1")).asSubheading, - errorMessageField = form("volumes_totalLitresVolume"), - value = form("volumes.totalLitresVolume").value + errorMessageField = form(s"volumes_${DutySuspendedRegimeSpecificKey.totalVolumeKey(Spirits)}"), + value = form(s"volumes.${DutySuspendedRegimeSpecificKey.totalVolumeKey(Spirits)}").value ) .asNumeric() .withWidth(Fixed10) @@ -65,10 +67,10 @@ @govukInput( InputViewModel( field = form("volumes"), - key="pureAlcoholVolume", + key=DutySuspendedRegimeSpecificKey.pureAlcoholKey(Spirits), label = LabelViewModel(messages("dutySuspendedSpirits.subheading2")).asSubheading, - errorMessageField = form("volumes_pureAlcoholVolume"), - value = form("volumes.pureAlcoholVolume").value + errorMessageField = form(s"volumes_${DutySuspendedRegimeSpecificKey.pureAlcoholKey(Spirits)}"), + value = form(s"volumes.${DutySuspendedRegimeSpecificKey.pureAlcoholKey(Spirits)}").value ) .asNumeric() .withWidth(Fixed10) diff --git a/app/views/dutySuspended/DutySuspendedWineView.scala.html b/app/views/dutySuspended/DutySuspendedWineView.scala.html index 15debb91..9f4915c5 100644 --- a/app/views/dutySuspended/DutySuspendedWineView.scala.html +++ b/app/views/dutySuspended/DutySuspendedWineView.scala.html @@ -16,6 +16,8 @@ @import viewmodels.InputWidth._ @import components.{SectionHeading, PageHeading, Paragraph, SubHeading} +@import models.dutySuspended.DutySuspendedRegimeSpecificKey +@import models.AlcoholRegime.Wine @this( layout: templates.Layout, @@ -51,10 +53,10 @@ @govukInput( InputViewModel( field = form("volumes"), - key="totalLitresVolume", + key=DutySuspendedRegimeSpecificKey.totalVolumeKey(Wine), label = LabelViewModel(messages("dutySuspendedWine.subheading1")).asSubheading, - errorMessageField = form("volumes_totalLitresVolume"), - value = form("volumes.totalLitresVolume").value + errorMessageField = form(s"volumes_${DutySuspendedRegimeSpecificKey.totalVolumeKey(Wine)}"), + value = form(s"volumes.${DutySuspendedRegimeSpecificKey.totalVolumeKey(Wine)}").value ) .asNumeric() .withWidth(Fixed10) @@ -65,10 +67,10 @@ @govukInput( InputViewModel( field = form("volumes"), - key="pureAlcoholVolume", + key=DutySuspendedRegimeSpecificKey.pureAlcoholKey(Wine), label = LabelViewModel(messages("dutySuspendedWine.subheading2")).asSubheading, - errorMessageField = form("volumes_pureAlcoholVolume"), - value = form("volumes.pureAlcoholVolume").value + errorMessageField = form(s"volumes_${DutySuspendedRegimeSpecificKey.pureAlcoholKey(Wine)}"), + value = form(s"volumes.${DutySuspendedRegimeSpecificKey.pureAlcoholKey(Wine)}").value ) .asNumeric() .withWidth(Fixed10) diff --git a/test-utils/common/TestData.scala b/test-utils/common/TestData.scala index caf0a0dd..9df58bad 100644 --- a/test-utils/common/TestData.scala +++ b/test-utils/common/TestData.scala @@ -802,24 +802,24 @@ trait TestData extends ModelGenerators { OverDeclarationReasonPage.toString -> "Reason for over declaration", DeclareDutySuspendedDeliveriesQuestionPage.toString -> true, DutySuspendedBeerPage.toString -> Json.obj( - "totalLitresVolume" -> 1000, - "pureAlcoholVolume" -> 100 + "totalBeer" -> 1000, + "pureAlcoholInBeer" -> 100 ), DutySuspendedCiderPage.toString -> Json.obj( - "totalLitresVolume" -> 2000, - "pureAlcoholVolume" -> 200 + "totalCider" -> 2000, + "pureAlcoholInCider" -> 200 ), DutySuspendedSpiritsPage.toString -> Json.obj( - "totalLitresVolume" -> 1000, - "pureAlcoholVolume" -> 100 + "totalSpirits" -> 1000, + "pureAlcoholInSpirits" -> 100 ), DutySuspendedWinePage.toString -> Json.obj( - "totalLitresVolume" -> 1000, - "pureAlcoholVolume" -> 100 + "totalWine" -> 1000, + "pureAlcoholInWine" -> 100 ), DutySuspendedOtherFermentedPage.toString -> Json.obj( - "totalLitresVolume" -> 1000, - "pureAlcoholVolume" -> 100 + "totalOtherFermented" -> 1000, + "pureAlcoholInOtherFermented" -> 100 ), DeclareQuarterlySpiritsPage.toString -> true, DeclareSpiritsTotalPage.toString -> 1234, diff --git a/test-utils/common/TestPages.scala b/test-utils/common/TestPages.scala index 2bd92ff9..2f74ebe3 100644 --- a/test-utils/common/TestPages.scala +++ b/test-utils/common/TestPages.scala @@ -201,20 +201,24 @@ trait TestPages extends TestData { multipleSPRListPage(userAnswers, regime, allVolumeAndRateByTaxTypeUnsorted) def dutySuspendedBeerPage(userAnswers: UserAnswers, dutySuspendedBeer: DutySuspendedVolume): UserAnswers = - userAnswers.set(DutySuspendedBeerPage, dutySuspendedBeer).get + userAnswers.set(DutySuspendedBeerPage, dutySuspendedBeer)(DutySuspendedVolume.format(Beer)).get def dutySuspendedCiderPage(userAnswers: UserAnswers, dutySuspendedCider: DutySuspendedVolume): UserAnswers = - userAnswers.set(DutySuspendedCiderPage, dutySuspendedCider).get + userAnswers.set(DutySuspendedCiderPage, dutySuspendedCider)(DutySuspendedVolume.format(Cider)).get def dutySuspendedWinePage(userAnswers: UserAnswers, dutySuspendedWine: DutySuspendedVolume): UserAnswers = - userAnswers.set(DutySuspendedWinePage, dutySuspendedWine).get + userAnswers.set(DutySuspendedWinePage, dutySuspendedWine)(DutySuspendedVolume.format(Wine)).get def dutySuspendedSpiritsPage(userAnswers: UserAnswers, dutySuspendedSpirits: DutySuspendedVolume): UserAnswers = - userAnswers.set(DutySuspendedSpiritsPage, dutySuspendedSpirits).get + userAnswers.set(DutySuspendedSpiritsPage, dutySuspendedSpirits)(DutySuspendedVolume.format(Spirits)).get def dutySuspendedOtherFermentedPage( userAnswers: UserAnswers, dutySuspendedOtherFermented: DutySuspendedVolume ): UserAnswers = - userAnswers.set(DutySuspendedOtherFermentedPage, dutySuspendedOtherFermented).get + userAnswers + .set(DutySuspendedOtherFermentedPage, dutySuspendedOtherFermented)( + DutySuspendedVolume.format(OtherFermentedProduct) + ) + .get } diff --git a/test/controllers/dutySuspended/CheckYourAnswersDutySuspendedDeliveriesControllerSpec.scala b/test/controllers/dutySuspended/CheckYourAnswersDutySuspendedDeliveriesControllerSpec.scala index 7ecc4758..652c0410 100644 --- a/test/controllers/dutySuspended/CheckYourAnswersDutySuspendedDeliveriesControllerSpec.scala +++ b/test/controllers/dutySuspended/CheckYourAnswersDutySuspendedDeliveriesControllerSpec.scala @@ -34,24 +34,24 @@ class CheckYourAnswersDutySuspendedDeliveriesControllerSpec extends SpecBase wit Json.obj( AlcoholRegimePage.toString -> Json.toJson(AlcoholRegime.values), DutySuspendedBeerPage.toString -> Json.obj( - "totalLitresVolume" -> validTotal, - "pureAlcoholVolume" -> validPureAlcohol + "totalBeer" -> validTotal, + "pureAlcoholInBeer" -> validPureAlcohol ), DutySuspendedCiderPage.toString -> Json.obj( - "totalLitresVolume" -> validTotal, - "pureAlcoholVolume" -> validPureAlcohol + "totalCider" -> validTotal, + "pureAlcoholInCider" -> validPureAlcohol ), DutySuspendedSpiritsPage.toString -> Json.obj( - "totalLitresVolume" -> validTotal, - "pureAlcoholVolume" -> validPureAlcohol + "totalSpirits" -> validTotal, + "pureAlcoholInSpirits" -> validPureAlcohol ), DutySuspendedWinePage.toString -> Json.obj( - "totalLitresVolume" -> validTotal, - "pureAlcoholVolume" -> validPureAlcohol + "totalWine" -> validTotal, + "pureAlcoholInWine" -> validPureAlcohol ), DutySuspendedOtherFermentedPage.toString -> Json.obj( - "totalLitresVolume" -> validTotal, - "pureAlcoholVolume" -> validPureAlcohol + "totalOtherFermented" -> validTotal, + "pureAlcoholInOtherFermented" -> validPureAlcohol ) ) ) @@ -91,8 +91,8 @@ class CheckYourAnswersDutySuspendedDeliveriesControllerSpec extends SpecBase wit regimes = AlcoholRegimes(Set(regime)), data = Json.obj( page.toString -> Json.obj( - "totalLitresVolume" -> validTotal, - "pureAlcoholVolume" -> validPureAlcohol + s"total${regime.entryName}" -> validTotal, + s"pureAlcoholIn${regime.entryName}" -> validPureAlcohol ) ) ) diff --git a/test/controllers/dutySuspended/DutySuspendedBeerControllerSpec.scala b/test/controllers/dutySuspended/DutySuspendedBeerControllerSpec.scala index 96b7e08f..503b9ae2 100644 --- a/test/controllers/dutySuspended/DutySuspendedBeerControllerSpec.scala +++ b/test/controllers/dutySuspended/DutySuspendedBeerControllerSpec.scala @@ -49,8 +49,8 @@ class DutySuspendedBeerControllerSpec extends SpecBase { val userAnswers = userAnswersWithBeer.copy(data = Json.obj( DutySuspendedBeerPage.toString -> Json.obj( - "totalLitresVolume" -> validTotalBeer, - "pureAlcoholVolume" -> validPureAlcoholInBeer + "totalBeer" -> validTotalBeer, + "pureAlcoholInBeer" -> validPureAlcoholInBeer ) ) ) @@ -110,8 +110,8 @@ class DutySuspendedBeerControllerSpec extends SpecBase { val request = FakeRequest(POST, dutySuspendedBeerRoute) .withFormUrlEncodedBody( - ("volumes.totalLitresVolume", validTotalBeer.toString), - ("volumes.pureAlcoholVolume", validPureAlcoholInBeer.toString) + ("volumes.totalBeer", validTotalBeer.toString), + ("volumes.pureAlcoholInBeer", validPureAlcoholInBeer.toString) ) val result = route(application, request).value @@ -172,7 +172,7 @@ class DutySuspendedBeerControllerSpec extends SpecBase { running(application) { val request = FakeRequest(POST, dutySuspendedBeerRoute) - .withFormUrlEncodedBody(("volumes.totalLitresVolume", "5.6"), ("volumes.pureAlcoholVolume", "47.5")) + .withFormUrlEncodedBody(("volumes.totalBeer", "5.6"), ("volumes.pureAlcoholInBeer", "47.5")) val result = route(application, request).value @@ -188,8 +188,8 @@ class DutySuspendedBeerControllerSpec extends SpecBase { val request = FakeRequest(POST, dutySuspendedBeerRoute) .withFormUrlEncodedBody( - ("volumes.totalLitresVolume", validTotalBeer.toString), - ("volumes.pureAlcoholVolume", validPureAlcoholInBeer.toString) + ("volumes.totalBeer", validTotalBeer.toString), + ("volumes.pureAlcoholInBeer", validPureAlcoholInBeer.toString) ) val result = route(application, request).value diff --git a/test/controllers/dutySuspended/DutySuspendedCiderControllerSpec.scala b/test/controllers/dutySuspended/DutySuspendedCiderControllerSpec.scala index 1a3fdef7..10ea7f7c 100644 --- a/test/controllers/dutySuspended/DutySuspendedCiderControllerSpec.scala +++ b/test/controllers/dutySuspended/DutySuspendedCiderControllerSpec.scala @@ -48,8 +48,8 @@ class DutySuspendedCiderControllerSpec extends SpecBase { val userAnswers = userAnswersWithCider.copy(data = Json.obj( DutySuspendedCiderPage.toString -> Json.obj( - "totalLitresVolume" -> validTotalCider, - "pureAlcoholVolume" -> validPureAlcoholInCider + "totalCider" -> validTotalCider, + "pureAlcoholInCider" -> validPureAlcoholInCider ) ) ) @@ -106,8 +106,8 @@ class DutySuspendedCiderControllerSpec extends SpecBase { val request = FakeRequest(POST, dutySuspendedCiderRoute) .withFormUrlEncodedBody( - ("volumes.totalLitresVolume", validTotalCider.toString), - ("volumes.pureAlcoholVolume", validPureAlcoholInCider.toString) + ("volumes.totalCider", validTotalCider.toString), + ("volumes.pureAlcoholInCider", validPureAlcoholInCider.toString) ) val result = route(application, request).value @@ -169,8 +169,8 @@ class DutySuspendedCiderControllerSpec extends SpecBase { val request = FakeRequest(POST, dutySuspendedCiderRoute) .withFormUrlEncodedBody( - ("volumes.totalLitresVolume", validTotalCider.toString), - ("volumes.pureAlcoholVolume", validPureAlcoholInCider.toString) + ("volumes.totalCider", validTotalCider.toString), + ("volumes.pureAlcoholInCider", validPureAlcoholInCider.toString) ) val result = route(application, request).value @@ -187,8 +187,8 @@ class DutySuspendedCiderControllerSpec extends SpecBase { val request = FakeRequest(POST, dutySuspendedCiderRoute) .withFormUrlEncodedBody( - ("volumes.totalLitresVolume", validTotalCider.toString), - ("volumes.pureAlcoholVolume", validPureAlcoholInCider.toString) + ("volumes.totalCider", validTotalCider.toString), + ("volumes.pureAlcoholInCider", validPureAlcoholInCider.toString) ) val result = route(application, request).value diff --git a/test/controllers/dutySuspended/DutySuspendedOtherFermentedControllerSpec.scala b/test/controllers/dutySuspended/DutySuspendedOtherFermentedControllerSpec.scala index ea492f72..8638822c 100644 --- a/test/controllers/dutySuspended/DutySuspendedOtherFermentedControllerSpec.scala +++ b/test/controllers/dutySuspended/DutySuspendedOtherFermentedControllerSpec.scala @@ -48,8 +48,8 @@ class DutySuspendedOtherFermentedControllerSpec extends SpecBase { val userAnswers = userAnswersWithOtherFermentedProduct.copy(data = Json.obj( DutySuspendedOtherFermentedPage.toString -> Json.obj( - "totalLitresVolume" -> validTotalOtherFermented, - "pureAlcoholVolume" -> validPureAlcoholInOtherFermented + "totalOtherFermented" -> validTotalOtherFermented, + "pureAlcoholInOtherFermented" -> validPureAlcoholInOtherFermented ) ) ) @@ -106,8 +106,8 @@ class DutySuspendedOtherFermentedControllerSpec extends SpecBase { val request = FakeRequest(POST, dutySuspendedOtherFermentedRoute) .withFormUrlEncodedBody( - ("volumes.totalLitresVolume", validTotalOtherFermented.toString), - ("volumes.pureAlcoholVolume", validPureAlcoholInOtherFermented.toString) + ("volumes.totalOtherFermented", validTotalOtherFermented.toString), + ("volumes.pureAlcoholInOtherFermented", validPureAlcoholInOtherFermented.toString) ) val result = route(application, request).value @@ -168,7 +168,10 @@ class DutySuspendedOtherFermentedControllerSpec extends SpecBase { running(application) { val request = FakeRequest(POST, dutySuspendedOtherFermentedRoute) - .withFormUrlEncodedBody(("volumes.totalLitresVolume", "value 1"), ("volumes.pureAlcoholVolume", "value 2")) + .withFormUrlEncodedBody( + ("volumes.totalOtherFermented", "value 1"), + ("volumes.pureAlcoholInOtherFermented", "value 2") + ) val result = route(application, request).value @@ -184,8 +187,8 @@ class DutySuspendedOtherFermentedControllerSpec extends SpecBase { val request = FakeRequest(POST, dutySuspendedOtherFermentedRoute) .withFormUrlEncodedBody( - ("volumes.totalLitresVolume", validTotalOtherFermented.toString), - ("volumes.pureAlcoholVolume", validPureAlcoholInOtherFermented.toString) + ("volumes.totalOtherFermented", validTotalOtherFermented.toString), + ("volumes.pureAlcoholInOtherFermented", validPureAlcoholInOtherFermented.toString) ) val result = route(application, request).value diff --git a/test/controllers/dutySuspended/DutySuspendedSpiritsControllerSpec.scala b/test/controllers/dutySuspended/DutySuspendedSpiritsControllerSpec.scala index 6f3c28da..c67c0993 100644 --- a/test/controllers/dutySuspended/DutySuspendedSpiritsControllerSpec.scala +++ b/test/controllers/dutySuspended/DutySuspendedSpiritsControllerSpec.scala @@ -48,8 +48,8 @@ class DutySuspendedSpiritsControllerSpec extends SpecBase { val userAnswers = userAnswersWithSpirits.copy(data = Json.obj( DutySuspendedSpiritsPage.toString -> Json.obj( - "totalLitresVolume" -> validTotalSpirits, - "pureAlcoholVolume" -> validPureAlcoholInSpirits + "totalSpirits" -> validTotalSpirits, + "pureAlcoholInSpirits" -> validPureAlcoholInSpirits ) ) ) @@ -109,8 +109,8 @@ class DutySuspendedSpiritsControllerSpec extends SpecBase { val request = FakeRequest(POST, dutySuspendedSpiritsRoute) .withFormUrlEncodedBody( - ("volumes.totalLitresVolume", validTotalSpirits.toString), - ("volumes.pureAlcoholVolume", validPureAlcoholInSpirits.toString) + ("volumes.totalSpirits", validTotalSpirits.toString), + ("volumes.pureAlcoholInSpirits", validPureAlcoholInSpirits.toString) ) val result = route(application, request).value @@ -171,7 +171,7 @@ class DutySuspendedSpiritsControllerSpec extends SpecBase { running(application) { val request = FakeRequest(POST, dutySuspendedSpiritsRoute) - .withFormUrlEncodedBody(("volumes.totalLitresVolume", "value 1"), ("volumes.pureAlcoholVolume", "value 2")) + .withFormUrlEncodedBody(("volumes.totalSpirits", "value 1"), ("volumes.pureAlcoholInSpirits", "value 2")) val result = route(application, request).value @@ -187,8 +187,8 @@ class DutySuspendedSpiritsControllerSpec extends SpecBase { val request = FakeRequest(POST, dutySuspendedSpiritsRoute) .withFormUrlEncodedBody( - ("volumes.totalLitresVolume", validTotalSpirits.toString), - ("volumes.pureAlcoholVolume", validPureAlcoholInSpirits.toString) + ("volumes.totalSpirits", validTotalSpirits.toString), + ("volumes.pureAlcoholInSpirits", validPureAlcoholInSpirits.toString) ) val result = route(application, request).value diff --git a/test/controllers/dutySuspended/DutySuspendedWineControllerSpec.scala b/test/controllers/dutySuspended/DutySuspendedWineControllerSpec.scala index c2c1ca5d..be13edd4 100644 --- a/test/controllers/dutySuspended/DutySuspendedWineControllerSpec.scala +++ b/test/controllers/dutySuspended/DutySuspendedWineControllerSpec.scala @@ -48,8 +48,8 @@ class DutySuspendedWineControllerSpec extends SpecBase { val userAnswers = userAnswersWithWine.copy(data = Json.obj( DutySuspendedWinePage.toString -> Json.obj( - "totalLitresVolume" -> validTotalWine, - "pureAlcoholVolume" -> validPureAlcoholInWine + "totalWine" -> validTotalWine, + "pureAlcoholInWine" -> validPureAlcoholInWine ) ) ) @@ -106,8 +106,8 @@ class DutySuspendedWineControllerSpec extends SpecBase { val request = FakeRequest(POST, dutySuspendedWineRoute) .withFormUrlEncodedBody( - ("volumes.totalLitresVolume", validTotalWine.toString), - ("volumes.pureAlcoholVolume", validPureAlcoholInWine.toString) + ("volumes.totalWine", validTotalWine.toString), + ("volumes.pureAlcoholInWine", validPureAlcoholInWine.toString) ) val result = route(application, request).value @@ -169,8 +169,8 @@ class DutySuspendedWineControllerSpec extends SpecBase { val request = FakeRequest(POST, dutySuspendedWineRoute) .withFormUrlEncodedBody( - ("volumes.totalLitresVolume", validTotalWine.toString), - ("volumes.pureAlcoholVolume", validPureAlcoholInWine.toString) + ("volumes.totalWine", validTotalWine.toString), + ("volumes.pureAlcoholInWine", validPureAlcoholInWine.toString) ) val result = route(application, request).value @@ -187,8 +187,8 @@ class DutySuspendedWineControllerSpec extends SpecBase { val request = FakeRequest(POST, dutySuspendedWineRoute) .withFormUrlEncodedBody( - ("volumes.totalLitresVolume", validTotalWine.toString), - ("volumes.pureAlcoholVolume", validPureAlcoholInWine.toString) + ("volumes.totalWine", validTotalWine.toString), + ("volumes.pureAlcoholInWine", validPureAlcoholInWine.toString) ) val result = route(application, request).value diff --git a/test/forms/dutySuspended/DutySuspendedFormProviderSpec.scala b/test/forms/dutySuspended/DutySuspendedFormProviderSpec.scala index eb4b3b5d..44a086ca 100644 --- a/test/forms/dutySuspended/DutySuspendedFormProviderSpec.scala +++ b/test/forms/dutySuspended/DutySuspendedFormProviderSpec.scala @@ -17,21 +17,22 @@ package forms.dutySuspended import forms.behaviours.BigDecimalFieldBehaviours -import models.dutySuspended.DutySuspendedVolume +import models.dutySuspended.{DutySuspendedRegimeSpecificKey, DutySuspendedVolume} import org.mockito.MockitoSugar.mock import play.api.data.FormError import play.api.i18n.Messages class DutySuspendedFormProviderSpec extends BigDecimalFieldBehaviours { - val regime = regimeGen.sample.value - val messages = mock[Messages] - val form = new DutySuspendedFormProvider()(regime)(messages) - + val regime = regimeGen.sample.value + val messages = mock[Messages] + val form = new DutySuspendedFormProvider()(regime)(messages) + val totalVolumeKey = DutySuspendedRegimeSpecificKey.totalVolumeKey(regime) + val pureAlcoholKey = DutySuspendedRegimeSpecificKey.pureAlcoholKey(regime) ".volumes" - { "must bind valid data" in { val data = Map( - "volumes.totalLitresVolume" -> "1", - "volumes.pureAlcoholVolume" -> "1" + s"volumes.$totalVolumeKey" -> "1", + s"volumes.$pureAlcoholKey" -> "1" ) form.bind(data).value.value mustBe DutySuspendedVolume(1, 1) } @@ -39,111 +40,111 @@ class DutySuspendedFormProviderSpec extends BigDecimalFieldBehaviours { "must unbind valid data" in { val data = DutySuspendedVolume(1, 1) form.fill(data).data must contain theSameElementsAs Map( - "volumes.totalLitresVolume" -> "1", - "volumes.pureAlcoholVolume" -> "1" + s"volumes.$totalVolumeKey" -> "1", + s"volumes.$pureAlcoholKey" -> "1" ) } "fail to bind when no answers are selected" in { val data = Map.empty[String, String] form.bind(data).errors must contain allElementsOf List( - FormError("volumes_totalLitresVolume", "dutySuspendedVolume.error.noValue.totalLitresVolume", Seq("")), - FormError("volumes_pureAlcoholVolume", "dutySuspendedVolume.error.noValue.pureAlcoholVolume", Seq("")) + FormError(s"volumes_$totalVolumeKey", s"dutySuspendedVolume.error.noValue.$totalVolumeKey", Seq("")), + FormError(s"volumes_$pureAlcoholKey", s"dutySuspendedVolume.error.noValue.$pureAlcoholKey", Seq("")) ) } "fail to bind when blank answer provided" in { val data = Map( - "volumes.totalLitresVolume" -> "", - "volumes.pureAlcoholVolume" -> "" + s"volumes.$totalVolumeKey" -> "", + s"volumes.$pureAlcoholKey" -> "" ) form.bind(data).errors must contain allElementsOf List( - FormError("volumes_totalLitresVolume", "dutySuspendedVolume.error.noValue.totalLitresVolume", Seq("")), - FormError("volumes_pureAlcoholVolume", "dutySuspendedVolume.error.noValue.pureAlcoholVolume", Seq("")) + FormError(s"volumes_$totalVolumeKey", s"dutySuspendedVolume.error.noValue.$totalVolumeKey", Seq("")), + FormError(s"volumes_$pureAlcoholKey", s"dutySuspendedVolume.error.noValue.$pureAlcoholKey", Seq("")) ) } "fail to bind when values with too many decimal places are provided" in { val data = Map( - "volumes.totalLitresVolume" -> "1.111", - "volumes.pureAlcoholVolume" -> "1.11234" + s"volumes.$totalVolumeKey" -> "1.111", + s"volumes.$pureAlcoholKey" -> "1.11234" ) form.bind(data).errors must contain allElementsOf List( - FormError("volumes_totalLitresVolume", s"dutySuspendedVolume.error.decimalPlaces.totalLitresVolume", Seq("")), - FormError("volumes_pureAlcoholVolume", s"dutySuspendedVolume.error.decimalPlaces.pureAlcoholVolume", Seq("")) + FormError(s"volumes_$totalVolumeKey", s"dutySuspendedVolume.error.decimalPlaces.$totalVolumeKey", Seq("")), + FormError(s"volumes_$pureAlcoholKey", s"dutySuspendedVolume.error.decimalPlaces.$pureAlcoholKey", Seq("")) ) } "fail to bind when invalid values are provided" in { val data = Map( - "volumes.totalLitresVolume" -> "invalid", - "volumes.pureAlcoholVolume" -> "invalid" + s"volumes.$totalVolumeKey" -> "invalid", + s"volumes.$pureAlcoholKey" -> "invalid" ) form.bind(data).errors must contain allElementsOf List( - FormError("volumes_totalLitresVolume", "dutySuspendedVolume.error.invalid.totalLitresVolume", List("")), - FormError("volumes_pureAlcoholVolume", "dutySuspendedVolume.error.invalid.pureAlcoholVolume", List("")) + FormError(s"volumes_$totalVolumeKey", s"dutySuspendedVolume.error.invalid.$totalVolumeKey", List("")), + FormError(s"volumes_$pureAlcoholKey", s"dutySuspendedVolume.error.invalid.$pureAlcoholKey", List("")) ) } "fail to bind when values below minimum are provided" in { val data = Map( - "volumes.totalLitresVolume" -> "-100000000000", - "volumes.pureAlcoholVolume" -> "-100000000000" + s"volumes.$totalVolumeKey" -> "-100000000000", + s"volumes.$pureAlcoholKey" -> "-100000000000" ) form.bind(data).errors must contain allElementsOf List( - FormError("volumes_totalLitresVolume", "dutySuspendedVolume.error.minimumValue.totalLitresVolume", List("")), - FormError("volumes_pureAlcoholVolume", "dutySuspendedVolume.error.minimumValue.pureAlcoholVolume", List("")) + FormError(s"volumes_$totalVolumeKey", s"dutySuspendedVolume.error.minimumValue.$totalVolumeKey", List("")), + FormError(s"volumes_$pureAlcoholKey", s"dutySuspendedVolume.error.minimumValue.$pureAlcoholKey", List("")) ) } "fail to bind when values exceed maximum are provided" in { val data = Map( - "volumes.totalLitresVolume" -> "100000000000", - "volumes.pureAlcoholVolume" -> "100000000000" + s"volumes.$totalVolumeKey" -> "100000000000", + s"volumes.$pureAlcoholKey" -> "100000000000" ) form.bind(data).errors must contain allElementsOf List( - FormError("volumes_totalLitresVolume", "dutySuspendedVolume.error.maximumValue.totalLitresVolume", List("")), - FormError("volumes_pureAlcoholVolume", "dutySuspendedVolume.error.maximumValue.pureAlcoholVolume", List("")) + FormError(s"volumes_$totalVolumeKey", s"dutySuspendedVolume.error.maximumValue.$totalVolumeKey", List("")), + FormError(s"volumes_$pureAlcoholKey", s"dutySuspendedVolume.error.maximumValue.$pureAlcoholKey", List("")) ) } "fail to bind when pure alcohol volume is higher than total litres value" in { val data = Map( - "volumes.totalLitresVolume" -> "0", - "volumes.pureAlcoholVolume" -> "2" + s"volumes.$totalVolumeKey" -> "0", + s"volumes.$pureAlcoholKey" -> "2" ) form.bind(data).errors must contain allElementsOf List( - FormError("volumes_pureAlcoholVolume", "dutySuspendedVolume.error.lessThanExpected", List("")) + FormError(s"volumes_$pureAlcoholKey", "dutySuspendedVolume.error.lessThanExpected", List("")) ) } "fail to bind when pure alcohol volume is negative and total litres value is positive" in { val data = Map( - "volumes.totalLitresVolume" -> "1", - "volumes.pureAlcoholVolume" -> "-2" + s"volumes.$totalVolumeKey" -> "1", + s"volumes.$pureAlcoholKey" -> "-2" ) form.bind(data).errors must contain allElementsOf List( - FormError("volumes_pureAlcoholVolume", "dutySuspendedVolume.error.incorrectSign", List("")) + FormError(s"volumes_$pureAlcoholKey", "dutySuspendedVolume.error.incorrectSign", List("")) ) } "fail to bind when total litres value is negative and pure alcohol volume is a higher negative" in { val data = Map( - "volumes.totalLitresVolume" -> "-11", - "volumes.pureAlcoholVolume" -> "-2" + s"volumes.$totalVolumeKey" -> "-11", + s"volumes.$pureAlcoholKey" -> "-2" ) form.bind(data).errors must contain allElementsOf List( - FormError("volumes_pureAlcoholVolume", "dutySuspendedVolume.error.lessThanExpected", List("")) + FormError(s"volumes_$pureAlcoholKey", "dutySuspendedVolume.error.lessThanExpected", List("")) ) } "fail to bind when total litres value is zero and pure alcohol volume is negative" in { val data = Map( - "volumes.totalLitresVolume" -> "0", - "volumes.pureAlcoholVolume" -> "-2" + s"volumes.$totalVolumeKey" -> "0", + s"volumes.$pureAlcoholKey" -> "-2" ) form.bind(data).errors must contain allElementsOf List( - FormError("volumes_pureAlcoholVolume", "dutySuspendedVolume.error.zeroTotalLitres", List("")) + FormError(s"volumes_$pureAlcoholKey", "dutySuspendedVolume.error.zeroTotalLitres", List("")) ) } diff --git a/test/viewmodels/tasklist/ReturnTaskListCreatorSpec.scala b/test/viewmodels/tasklist/ReturnTaskListCreatorSpec.scala index bdd3d92e..6b18374e 100644 --- a/test/viewmodels/tasklist/ReturnTaskListCreatorSpec.scala +++ b/test/viewmodels/tasklist/ReturnTaskListCreatorSpec.scala @@ -559,20 +559,20 @@ class ReturnTaskListCreatorSpec extends SpecBase { .copy(data = Json.obj( DutySuspendedBeerPage.toString -> Json.obj( - "totalLitresVolume" -> validTotal, - "pureAlcoholVolume" -> validPureAlcohol + "totalBeer" -> validTotal, + "pureAlcoholInBeer" -> validPureAlcohol ), DutySuspendedCiderPage.toString -> Json.obj( - "totalLitresVolume" -> validTotal, - "pureAlcoholVolume" -> validPureAlcohol + "totalCider" -> validTotal, + "pureAlcoholInCider" -> validPureAlcohol ), DutySuspendedSpiritsPage.toString -> Json.obj( - "totalLitresVolume" -> validTotal, - "pureAlcoholVolume" -> validPureAlcohol + "totalSpirits" -> validTotal, + "pureAlcoholInSpirits" -> validPureAlcohol ), DutySuspendedWinePage.toString -> Json.obj( - "totalLitresVolume" -> validTotal, - "pureAlcoholVolume" -> validPureAlcohol + "totalWine" -> validTotal, + "pureAlcoholInWine" -> validPureAlcohol ) ) ) @@ -609,24 +609,24 @@ class ReturnTaskListCreatorSpec extends SpecBase { .copy(data = Json.obj( DutySuspendedBeerPage.toString -> Json.obj( - "totalLitresVolume" -> validTotal, - "pureAlcoholVolume" -> validPureAlcohol + "totalBeer" -> validTotal, + "pureAlcoholInBeer" -> validPureAlcohol ), DutySuspendedCiderPage.toString -> Json.obj( - "totalLitresVolume" -> validTotal, - "pureAlcoholVolume" -> validPureAlcohol + "totalCider" -> validTotal, + "pureAlcoholInCider" -> validPureAlcohol ), DutySuspendedSpiritsPage.toString -> Json.obj( - "totalLitresVolume" -> validTotal, - "pureAlcoholVolume" -> validPureAlcohol + "totalSpirits" -> validTotal, + "pureAlcoholInSpirits" -> validPureAlcohol ), DutySuspendedWinePage.toString -> Json.obj( - "totalLitresVolume" -> validTotal, - "pureAlcoholVolume" -> validPureAlcohol + "totalWine" -> validTotal, + "pureAlcoholInWine" -> validPureAlcohol ), DutySuspendedOtherFermentedPage.toString -> Json.obj( - "totalLitresVolume" -> validTotal, - "pureAlcoholVolume" -> validPureAlcohol + "totalOtherFermented" -> validTotal, + "pureAlcoholInOtherFermented" -> validPureAlcohol ) ) ) @@ -664,12 +664,12 @@ class ReturnTaskListCreatorSpec extends SpecBase { .copy(data = Json.obj( DutySuspendedCiderPage.toString -> Json.obj( - "totalLitresVolume" -> validTotal, - "pureAlcoholVolume" -> validPureAlcohol + "totalCider" -> validTotal, + "pureAlcoholInCider" -> validPureAlcohol ), DutySuspendedOtherFermentedPage.toString -> Json.obj( - "totalLitresVolume" -> validTotal, - "pureAlcoholVolume" -> validPureAlcohol + "totalOtherFermented" -> validTotal, + "pureAlcoholInOtherFermented" -> validPureAlcohol ) ) ) @@ -707,16 +707,16 @@ class ReturnTaskListCreatorSpec extends SpecBase { .copy(data = Json.obj( DutySuspendedBeerPage.toString -> Json.obj( - "totalLitresVolume" -> validTotal, - "pureAlcoholVolume" -> validPureAlcohol + "totalBeer" -> validTotal, + "pureAlcoholInBeer" -> validPureAlcohol ), DutySuspendedWinePage.toString -> Json.obj( - "totalLitresVolume" -> validTotal, - "pureAlcoholVolume" -> validPureAlcohol + "totalWine" -> validTotal, + "pureAlcoholInWine" -> validPureAlcohol ), DutySuspendedSpiritsPage.toString -> Json.obj( - "totalLitresVolume" -> validTotal, - "pureAlcoholVolume" -> validPureAlcohol + "totalSpirits" -> validTotal, + "pureAlcoholInSpirits" -> validPureAlcohol ) ) )