From b4bae9de42a44c72fa75d3d4e784b46ec3274de5 Mon Sep 17 00:00:00 2001 From: Jordan Rowe <37838443+jordanrowe@users.noreply.github.com> Date: Fri, 9 Oct 2020 16:15:51 +0100 Subject: [PATCH] [MIBM-112][JR] /remove-goods and /goods-removed (#41) --- .../controllers/DeclarationGoodsRequest.scala | 26 ++++ .../DeclarationJourneyActionProvider.scala | 18 ++- .../DeclarationJourneyController.scala | 11 +- .../ExciseAndRestrictedGoodsController.scala | 6 +- .../GoodsDestinationController.scala | 15 +- .../controllers/GoodsRemovedController.scala | 33 +++++ .../controllers/GoodsVatRateController.scala | 57 +++----- .../controllers/InvoiceNumberController.scala | 58 ++++---- .../PurchaseDetailsController.scala | 64 ++++----- .../controllers/RemoveGoodsController.scala | 67 +++++++++ .../controllers/ReviewGoodsController.scala | 6 +- .../controllers/SearchGoodsController.scala | 51 +++---- .../SearchGoodsCountryController.scala | 56 ++++---- .../SkeletonJourneyController.scala | 8 -- .../ValueWeightOfGoodsController.scala | 6 +- ...ala => ExciseAndRestrictedGoodsForm.scala} | 5 +- ...vider.scala => GoodsDestinationForm.scala} | 6 +- ...mProvider.scala => GoodsVatRateForm.scala} | 5 +- .../forms/RemoveGoodsForm.scala | 29 ++++ ...rmProvider.scala => ReviewGoodsForm.scala} | 5 +- ...der.scala => SearchGoodsCountryForm.scala} | 5 +- ...rmProvider.scala => SearchGoodsForm.scala} | 5 +- ...der.scala => ValueWeightOfGoodsForm.scala} | 5 +- .../model/core/Declaration.scala | 21 ++- .../views/GoodsRemovedView.scala.html | 37 +++++ .../views/RemoveGoodsView.scala.html | 43 ++++++ .../views/ReviewGoodsView.scala.html | 4 +- conf/app.routes | 9 +- conf/messages | 14 ++ ...ciseAndRestrictedGoodsControllerSpec.scala | 6 +- .../GoodsDestinationControllerSpec.scala | 8 +- .../GoodsRemovedControllerSpec.scala | 43 ++++++ .../GoodsVatRateControllerSpec.scala | 8 +- .../RemoveGoodsControllerSpec.scala | 134 ++++++++++++++++++ .../ReviewGoodsControllerSpec.scala | 7 +- .../SearchGoodsControllerSpec.scala | 6 +- .../SearchGoodsCountryControllerSpec.scala | 7 +- .../SkeletonJourneyControllerSpec.scala | 40 ------ .../ValueWeightOfGoodsControllerSpec.scala | 6 +- ...=> ExciseAndRestrictedGoodsFormSpec.scala} | 5 +- ...c.scala => GoodsDestinationFormSpec.scala} | 5 +- ...rSpec.scala => GoodsVatRateFormSpec.scala} | 5 +- .../forms/RemoveGoodsFormSpec.scala | 44 ++++++ ...erSpec.scala => ReviewGoodsFormSpec.scala} | 5 +- ...scala => SearchGoodsCountryFormSpec.scala} | 4 +- ...erSpec.scala => SearchGoodsFormSpec.scala} | 5 +- ...scala => ValueWeightOfGoodsFormSpec.scala} | 5 +- 47 files changed, 690 insertions(+), 328 deletions(-) create mode 100644 app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/DeclarationGoodsRequest.scala create mode 100644 app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/GoodsRemovedController.scala create mode 100644 app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/RemoveGoodsController.scala rename app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/{ExciseAndRestrictedGoodsFormProvider.scala => ExciseAndRestrictedGoodsForm.scala} (86%) rename app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/{GoodsDestinationFormProvider.scala => GoodsDestinationForm.scala} (88%) rename app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/{GoodsVatRateFormProvider.scala => GoodsVatRateForm.scala} (88%) create mode 100644 app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/RemoveGoodsForm.scala rename app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/{ReviewGoodsFormProvider.scala => ReviewGoodsForm.scala} (87%) rename app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/{SearchGoodsCountryFormProvider.scala => SearchGoodsCountryForm.scala} (86%) rename app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/{SearchGoodsFormProvider.scala => SearchGoodsForm.scala} (89%) rename app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/{ValueWeightOfGoodsFormProvider.scala => ValueWeightOfGoodsForm.scala} (87%) create mode 100644 app/uk/gov/hmrc/merchandiseinbaggagefrontend/views/GoodsRemovedView.scala.html create mode 100644 app/uk/gov/hmrc/merchandiseinbaggagefrontend/views/RemoveGoodsView.scala.html create mode 100644 test/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/GoodsRemovedControllerSpec.scala create mode 100644 test/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/RemoveGoodsControllerSpec.scala rename test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/{ExciseAndRestrictedGoodsFormProviderSpec.scala => ExciseAndRestrictedGoodsFormSpec.scala} (88%) rename test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/{GoodsDestinationFormProviderSpec.scala => GoodsDestinationFormSpec.scala} (90%) rename test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/{GoodsVatRateFormProviderSpec.scala => GoodsVatRateFormSpec.scala} (90%) create mode 100644 test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/RemoveGoodsFormSpec.scala rename test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/{ReviewGoodsFormProviderSpec.scala => ReviewGoodsFormSpec.scala} (89%) rename test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/{SearchGoodsCountryFormProviderSpec.scala => SearchGoodsCountryFormSpec.scala} (87%) rename test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/{SearchGoodsFormProviderSpec.scala => SearchGoodsFormSpec.scala} (90%) rename test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/{ValueWeightOfGoodsFormProviderSpec.scala => ValueWeightOfGoodsFormSpec.scala} (88%) diff --git a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/DeclarationGoodsRequest.scala b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/DeclarationGoodsRequest.scala new file mode 100644 index 000000000..04e0dd66e --- /dev/null +++ b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/DeclarationGoodsRequest.scala @@ -0,0 +1,26 @@ +/* + * Copyright 2020 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 uk.gov.hmrc.merchandiseinbaggagefrontend.controllers + +import play.api.mvc.WrappedRequest +import uk.gov.hmrc.merchandiseinbaggagefrontend.model.core.GoodsEntry + +final class DeclarationGoodsRequest[A](declarationJourneyRequest: DeclarationJourneyRequest[A], val goodsEntry: GoodsEntry) + extends WrappedRequest[A](declarationJourneyRequest) { + + val declarationJourney = declarationJourneyRequest.declarationJourney +} diff --git a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/DeclarationJourneyActionProvider.scala b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/DeclarationJourneyActionProvider.scala index c8f52b4fa..23c3dfa2d 100644 --- a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/DeclarationJourneyActionProvider.scala +++ b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/DeclarationJourneyActionProvider.scala @@ -30,11 +30,14 @@ class DeclarationJourneyActionProvider @Inject()(defaultActionBuilder: DefaultAc val journeyAction: ActionBuilder[DeclarationJourneyRequest, AnyContent] = defaultActionBuilder andThen journeyActionRefiner + def goodsAction(idx: Int): ActionBuilder[DeclarationGoodsRequest, AnyContent] = + defaultActionBuilder andThen journeyActionRefiner andThen goodsActionRefiner(idx) + def invalidRequest: Result = Redirect(routes.InvalidRequestController.onPageLoad()) def invalidRequestF: Future[Result] = Future.successful(invalidRequest) - def journeyActionRefiner: ActionRefiner[Request, DeclarationJourneyRequest] = + private def journeyActionRefiner: ActionRefiner[Request, DeclarationJourneyRequest] = new ActionRefiner[Request, DeclarationJourneyRequest] { override protected def refine[A](request: Request[A]): Future[Either[Result, DeclarationJourneyRequest[A]]] = { @@ -49,6 +52,19 @@ class DeclarationJourneyActionProvider @Inject()(defaultActionBuilder: DefaultAc } } + override protected def executionContext: ExecutionContext = ec + } + + private def goodsActionRefiner(idx: Int): ActionRefiner[DeclarationJourneyRequest, DeclarationGoodsRequest] = + new ActionRefiner[DeclarationJourneyRequest, DeclarationGoodsRequest] { + + override protected def refine[A](request: DeclarationJourneyRequest[A]): Future[Either[Result, DeclarationGoodsRequest[A]]] = { + request.declarationJourney.goodsEntries.entries.lift(idx - 1) match { + case None => Future successful Left(invalidRequest) + case Some(goodsEntry) => Future successful Right( new DeclarationGoodsRequest(request, goodsEntry)) + } + } + override protected def executionContext: ExecutionContext = ec } } diff --git a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/DeclarationJourneyController.scala b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/DeclarationJourneyController.scala index 25fb24630..f17e3578f 100644 --- a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/DeclarationJourneyController.scala +++ b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/DeclarationJourneyController.scala @@ -17,9 +17,12 @@ package uk.gov.hmrc.merchandiseinbaggagefrontend.controllers import play.api.i18n.Messages -import play.api.mvc.{Action, AnyContent, Request} +import play.api.mvc.{Action, AnyContent, Request, Result} +import uk.gov.hmrc.merchandiseinbaggagefrontend.model.core.GoodsEntry import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController +import scala.concurrent.Future + trait DeclarationJourneyController extends FrontendBaseController { implicit def messages(implicit request: Request[_]): Messages = controllerComponents.messagesApi.preferred(request) @@ -34,6 +37,12 @@ trait IndexedDeclarationJourneyController extends FrontendBaseController { implicit def messages(implicit request: Request[_]): Messages = controllerComponents.messagesApi.preferred(request) def onPageLoad(idx: Int): Action[AnyContent] + + def withGoodsCategory(goodsEntry: GoodsEntry)(f: String => Future[Result]): Future[Result] = + goodsEntry.maybeCategoryQuantityOfGoods match { + case Some(c) => f(c.category) + case None => Future successful Redirect(routes.InvalidRequestController.onPageLoad()) + } } trait IndexedDeclarationJourneyUpdateController extends IndexedDeclarationJourneyController { diff --git a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/ExciseAndRestrictedGoodsController.scala b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/ExciseAndRestrictedGoodsController.scala index f9f1cbf4b..8aff069dc 100644 --- a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/ExciseAndRestrictedGoodsController.scala +++ b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/ExciseAndRestrictedGoodsController.scala @@ -17,10 +17,9 @@ package uk.gov.hmrc.merchandiseinbaggagefrontend.controllers import javax.inject.{Inject, Singleton} -import play.api.data.Form import play.api.mvc.{Action, AnyContent, MessagesControllerComponents} import uk.gov.hmrc.merchandiseinbaggagefrontend.config.AppConfig -import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.ExciseAndRestrictedGoodsFormProvider +import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.ExciseAndRestrictedGoodsForm.form import uk.gov.hmrc.merchandiseinbaggagefrontend.repositories.DeclarationJourneyRepository import uk.gov.hmrc.merchandiseinbaggagefrontend.views.html.ExciseAndRestrictedGoodsView @@ -29,14 +28,11 @@ import scala.concurrent.{ExecutionContext, Future} @Singleton class ExciseAndRestrictedGoodsController @Inject()(override val controllerComponents: MessagesControllerComponents, actionProvider: DeclarationJourneyActionProvider, - formProvider: ExciseAndRestrictedGoodsFormProvider, repo: DeclarationJourneyRepository, view: ExciseAndRestrictedGoodsView) (implicit ec: ExecutionContext, appConfig: AppConfig) extends DeclarationJourneyUpdateController { - val form: Form[Boolean] = formProvider() - val onPageLoad: Action[AnyContent] = actionProvider.journeyAction { implicit request => Ok(view(request.declarationJourney.maybeExciseOrRestrictedGoods.fold(form)(form.fill))) } diff --git a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/GoodsDestinationController.scala b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/GoodsDestinationController.scala index b13c76e20..f433912a0 100644 --- a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/GoodsDestinationController.scala +++ b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/GoodsDestinationController.scala @@ -17,11 +17,9 @@ package uk.gov.hmrc.merchandiseinbaggagefrontend.controllers import javax.inject.{Inject, Singleton} -import play.api.data.Form import play.api.mvc.{Action, AnyContent, MessagesControllerComponents} import uk.gov.hmrc.merchandiseinbaggagefrontend.config.AppConfig -import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.GoodsDestinationFormProvider -import uk.gov.hmrc.merchandiseinbaggagefrontend.model.core.GoodsDestination +import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.GoodsDestinationForm.form import uk.gov.hmrc.merchandiseinbaggagefrontend.repositories.DeclarationJourneyRepository import uk.gov.hmrc.merchandiseinbaggagefrontend.views.html.GoodsDestinationView @@ -29,15 +27,12 @@ import scala.concurrent.{ExecutionContext, Future} @Singleton class GoodsDestinationController @Inject()( - override val controllerComponents: MessagesControllerComponents, - actionProvider: DeclarationJourneyActionProvider, - formProvider: GoodsDestinationFormProvider, - repo: DeclarationJourneyRepository, - view: GoodsDestinationView + override val controllerComponents: MessagesControllerComponents, + actionProvider: DeclarationJourneyActionProvider, + repo: DeclarationJourneyRepository, + view: GoodsDestinationView )(implicit ec: ExecutionContext, appConfig: AppConfig) extends DeclarationJourneyUpdateController { - val form: Form[GoodsDestination] = formProvider() - val onPageLoad: Action[AnyContent] = actionProvider.journeyAction { implicit request => Ok(view(request.declarationJourney.maybeGoodsDestination.fold(form)(form.fill))) } diff --git a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/GoodsRemovedController.scala b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/GoodsRemovedController.scala new file mode 100644 index 000000000..39c4f0cfa --- /dev/null +++ b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/GoodsRemovedController.scala @@ -0,0 +1,33 @@ +/* + * Copyright 2020 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 uk.gov.hmrc.merchandiseinbaggagefrontend.controllers + +import javax.inject.{Inject, Singleton} +import play.api.mvc.{Action, AnyContent, MessagesControllerComponents} +import uk.gov.hmrc.merchandiseinbaggagefrontend.config.AppConfig +import uk.gov.hmrc.merchandiseinbaggagefrontend.views.html.GoodsRemovedView + +@Singleton +class GoodsRemovedController @Inject()(override val controllerComponents: MessagesControllerComponents, + actionProvider: DeclarationJourneyActionProvider, + view: GoodsRemovedView)(implicit val appConfig: AppConfig) + extends DeclarationJourneyController { + + val onPageLoad: Action[AnyContent] = actionProvider.journeyAction { implicit request => + Ok(view()) + } +} diff --git a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/GoodsVatRateController.scala b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/GoodsVatRateController.scala index c6adf01fc..634d3367f 100644 --- a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/GoodsVatRateController.scala +++ b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/GoodsVatRateController.scala @@ -17,11 +17,9 @@ package uk.gov.hmrc.merchandiseinbaggagefrontend.controllers import javax.inject.{Inject, Singleton} -import play.api.data.Form import play.api.mvc.{Action, AnyContent, MessagesControllerComponents} import uk.gov.hmrc.merchandiseinbaggagefrontend.config.AppConfig -import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.GoodsVatRateFormProvider -import uk.gov.hmrc.merchandiseinbaggagefrontend.model.core.{GoodsEntries, GoodsVatRate} +import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.GoodsVatRateForm.form import uk.gov.hmrc.merchandiseinbaggagefrontend.repositories.DeclarationJourneyRepository import uk.gov.hmrc.merchandiseinbaggagefrontend.views.html.GoodsVatRateView @@ -31,48 +29,39 @@ import scala.concurrent.{ExecutionContext, Future} class GoodsVatRateController @Inject()( override val controllerComponents: MessagesControllerComponents, actionProvider: DeclarationJourneyActionProvider, - formProvider: GoodsVatRateFormProvider, repo: DeclarationJourneyRepository, view: GoodsVatRateView) (implicit ec: ExecutionContext, appConfig: AppConfig) extends IndexedDeclarationJourneyUpdateController { - val form: Form[GoodsVatRate] = formProvider() + def onPageLoad(idx: Int): Action[AnyContent] = actionProvider.goodsAction(idx).async { implicit request => + withGoodsCategory(request.goodsEntry) { category => + val preparedForm = request.goodsEntry.maybeGoodsVatRate.fold(form)(form.fill) - def onPageLoad(idx: Int): Action[AnyContent] = actionProvider.journeyAction { implicit request => - request.declarationJourney.goodsEntries.entries.lift(idx - 1).fold(actionProvider.invalidRequest) { goodsEntry => - goodsEntry.maybeCategoryQuantityOfGoods.fold(actionProvider.invalidRequest) { categoryQuantityOfGoods => - val preparedForm = goodsEntry.maybeGoodsVatRate.fold(form)(form.fill) - - Ok(view(preparedForm, idx, categoryQuantityOfGoods.category)) - } + Future successful Ok(view(preparedForm, idx, category)) } } - def onSubmit(idx: Int): Action[AnyContent] = actionProvider.journeyAction.async { implicit request => - request.declarationJourney.goodsEntries.entries.lift(idx - 1).fold(actionProvider.invalidRequestF) { goodsEntry => - goodsEntry.maybeCategoryQuantityOfGoods.fold(actionProvider.invalidRequestF) { categoryQuantityOfGoods => - form - .bindFromRequest() - .fold( - formWithErrors => - Future.successful(BadRequest(view(formWithErrors, idx, categoryQuantityOfGoods.category))), - goodsVatRate => { - val updatedGoodsEntries = - request.declarationJourney.goodsEntries.entries.updated( - idx - 1, - goodsEntry.copy(maybeGoodsVatRate = Some(goodsVatRate))) - - repo.upsert( - request.declarationJourney.copy( - goodsEntries = GoodsEntries(updatedGoodsEntries) + def onSubmit(idx: Int): Action[AnyContent] = actionProvider.goodsAction(idx).async { implicit request => + withGoodsCategory(request.goodsEntry) { category => + form + .bindFromRequest() + .fold( + formWithErrors => + Future.successful(BadRequest(view(formWithErrors, idx, category))), + goodsVatRate => { + repo.upsert( + request.declarationJourney.copy( + goodsEntries = request.declarationJourney.goodsEntries.patch( + idx, + request.goodsEntry.copy(maybeGoodsVatRate = Some(goodsVatRate)) ) - ).map { _ => - Redirect(routes.SearchGoodsCountryController.onPageLoad(idx)) - } + ) + ).map { _ => + Redirect(routes.SearchGoodsCountryController.onPageLoad(idx)) } - ) - } + } + ) } } diff --git a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/InvoiceNumberController.scala b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/InvoiceNumberController.scala index 291c57701..9204e2dad 100644 --- a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/InvoiceNumberController.scala +++ b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/InvoiceNumberController.scala @@ -17,11 +17,9 @@ package uk.gov.hmrc.merchandiseinbaggagefrontend.controllers import javax.inject.{Inject, Singleton} -import play.api.data.Form import play.api.mvc.{Action, AnyContent, MessagesControllerComponents} import uk.gov.hmrc.merchandiseinbaggagefrontend.config.AppConfig -import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.InvoiceNumberForm -import uk.gov.hmrc.merchandiseinbaggagefrontend.model.core.GoodsEntries +import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.InvoiceNumberForm.form import uk.gov.hmrc.merchandiseinbaggagefrontend.repositories.DeclarationJourneyRepository import uk.gov.hmrc.merchandiseinbaggagefrontend.views.html.InvoiceNumberView @@ -36,45 +34,37 @@ class InvoiceNumberController @Inject()( )(implicit ec: ExecutionContext, appConfig: AppConfig) extends IndexedDeclarationJourneyUpdateController { - val form: Form[String] = InvoiceNumberForm.form + def onPageLoad(idx: Int): Action[AnyContent] = actionProvider.goodsAction(idx).async { implicit request => + withGoodsCategory(request.goodsEntry) { category => + val preparedForm = request.goodsEntry.maybeInvoiceNumber.fold(form)(form.fill) - def onPageLoad(idx: Int): Action[AnyContent] = actionProvider.journeyAction { implicit request => - request.declarationJourney.goodsEntries.entries.lift(idx - 1).fold(actionProvider.invalidRequest) { goodsEntry => - goodsEntry.maybeCategoryQuantityOfGoods.fold(actionProvider.invalidRequest) { categoryQuantityOfGoods => - val preparedForm = goodsEntry.maybeInvoiceNumber.fold(form)(form.fill) - - Ok(view(preparedForm, idx, categoryQuantityOfGoods.category)) - } + Future successful Ok(view(preparedForm, idx, category)) } } - def onSubmit(idx: Int): Action[AnyContent] = actionProvider.journeyAction.async { implicit request => - request.declarationJourney.goodsEntries.entries.lift(idx - 1).fold(actionProvider.invalidRequestF) { goodsEntry => - goodsEntry.maybeCategoryQuantityOfGoods.fold(actionProvider.invalidRequestF) { categoryQuantityOfGoods => - form - .bindFromRequest() - .fold( - formWithErrors => - Future.successful(BadRequest(view(formWithErrors, idx, categoryQuantityOfGoods.category))), - invoiceNumber => { - val updatedGoodsEntries = - request.declarationJourney.goodsEntries.entries.updated( - idx - 1, - goodsEntry.copy( + def onSubmit(idx: Int): Action[AnyContent] = actionProvider.goodsAction(idx).async { implicit request => + withGoodsCategory(request.goodsEntry) { category => + form + .bindFromRequest() + .fold( + formWithErrors => + Future.successful(BadRequest(view(formWithErrors, idx, category))), + invoiceNumber => { + repo.upsert( + request.declarationJourney.copy( + goodsEntries = request.declarationJourney.goodsEntries.patch( + idx, + request.goodsEntry.copy( maybeInvoiceNumber = Some(invoiceNumber), maybeTaxDue = Some(BigDecimal(-999.99)) - )) - - repo.upsert( - request.declarationJourney.copy( - goodsEntries = GoodsEntries(updatedGoodsEntries) + ) ) - ).map { _ => - Redirect(routes.ReviewGoodsController.onPageLoad()) - } + ) + ).map { _ => + Redirect(routes.ReviewGoodsController.onPageLoad()) } - ) - } + } + ) } } diff --git a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/PurchaseDetailsController.scala b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/PurchaseDetailsController.scala index a985a08d6..d361ecb82 100644 --- a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/PurchaseDetailsController.scala +++ b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/PurchaseDetailsController.scala @@ -22,7 +22,7 @@ import uk.gov.hmrc.http.HttpClient import uk.gov.hmrc.merchandiseinbaggagefrontend.config.AppConfig import uk.gov.hmrc.merchandiseinbaggagefrontend.connectors.CurrencyConversionConnector import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.PurchaseDetailsForm.form -import uk.gov.hmrc.merchandiseinbaggagefrontend.model.core.{GoodsEntries, PurchaseDetails} +import uk.gov.hmrc.merchandiseinbaggagefrontend.model.core.PurchaseDetails import uk.gov.hmrc.merchandiseinbaggagefrontend.repositories.DeclarationJourneyRepository import uk.gov.hmrc.merchandiseinbaggagefrontend.views.html.PurchaseDetailsView @@ -38,48 +38,42 @@ class PurchaseDetailsController @Inject()( )(implicit ec: ExecutionContext, appConfig: AppConfig) extends IndexedDeclarationJourneyUpdateController with CurrencyConversionConnector { - def onPageLoad(idx: Int): Action[AnyContent] = actionProvider.journeyAction.async { implicit request => - request.declarationJourney.goodsEntries.entries.lift(idx - 1).fold(actionProvider.invalidRequestF) { goodsEntry => - goodsEntry.maybeCategoryQuantityOfGoods.fold(actionProvider.invalidRequestF) { categoryQuantityOfGoods => - getCurrencies().map { currencyPeriod => - val preparedForm = goodsEntry.maybePurchaseDetails.fold(form)(p => form.fill(p.purchaseDetailsInput)) + def onPageLoad(idx: Int): Action[AnyContent] = actionProvider.goodsAction(idx).async { implicit request => + withGoodsCategory(request.goodsEntry) { category => + getCurrencies().map { currencyPeriod => + val preparedForm = request.goodsEntry.maybePurchaseDetails.fold(form)(p => form.fill(p.purchaseDetailsInput)) - Ok(view(preparedForm, idx, categoryQuantityOfGoods.category, currencyPeriod.currencies)) - } + Ok(view(preparedForm, idx, category, currencyPeriod.currencies)) } } } - def onSubmit(idx: Int): Action[AnyContent] = actionProvider.journeyAction.async { implicit request => - request.declarationJourney.goodsEntries.entries.lift(idx - 1).fold(actionProvider.invalidRequestF) { goodsEntry => - goodsEntry.maybeCategoryQuantityOfGoods.fold(actionProvider.invalidRequestF) { categoryQuantityOfGoods => - getCurrencies().flatMap { currencyPeriod => - form - .bindFromRequest() - .fold( - formWithErrors => - Future.successful(BadRequest(view(formWithErrors, idx, categoryQuantityOfGoods.category, currencyPeriod.currencies))), - purchaseDetailsInput => { - currencyPeriod.currencies.find(_.currencyCode == purchaseDetailsInput.currency) - .fold(actionProvider.invalidRequestF) { currency => - val purchaseDetails = PurchaseDetails(purchaseDetailsInput.price, currency) + def onSubmit(idx: Int): Action[AnyContent] = actionProvider.goodsAction(idx).async { implicit request => + withGoodsCategory(request.goodsEntry) { category => + getCurrencies().flatMap { currencyPeriod => + form + .bindFromRequest() + .fold( + formWithErrors => + Future.successful(BadRequest(view(formWithErrors, idx, category, currencyPeriod.currencies))), + purchaseDetailsInput => { + currencyPeriod.currencies.find(_.currencyCode == purchaseDetailsInput.currency) + .fold(actionProvider.invalidRequestF) { currency => + val purchaseDetails = PurchaseDetails(purchaseDetailsInput.price, currency) - val updatedGoodsEntries = - request.declarationJourney.goodsEntries.entries.updated( - idx - 1, - goodsEntry.copy(maybePurchaseDetails = Some(purchaseDetails))) - - repo.upsert( - request.declarationJourney.copy( - goodsEntries = GoodsEntries(updatedGoodsEntries) + repo.upsert( + request.declarationJourney.copy( + goodsEntries = request.declarationJourney.goodsEntries.patch( + idx, + request.goodsEntry.copy(maybePurchaseDetails = Some(purchaseDetails)) ) - ).map { _ => - Redirect(routes.InvoiceNumberController.onPageLoad(idx)) - } + ) + ).map { _ => + Redirect(routes.InvoiceNumberController.onPageLoad(idx)) } - } - ) - } + } + } + ) } } } diff --git a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/RemoveGoodsController.scala b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/RemoveGoodsController.scala new file mode 100644 index 000000000..9d1574ace --- /dev/null +++ b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/RemoveGoodsController.scala @@ -0,0 +1,67 @@ +/* + * Copyright 2020 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 uk.gov.hmrc.merchandiseinbaggagefrontend.controllers + +import javax.inject.{Inject, Singleton} +import play.api.mvc.{Action, AnyContent, MessagesControllerComponents} +import uk.gov.hmrc.merchandiseinbaggagefrontend.config.AppConfig +import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.RemoveGoodsForm.form +import uk.gov.hmrc.merchandiseinbaggagefrontend.repositories.DeclarationJourneyRepository +import uk.gov.hmrc.merchandiseinbaggagefrontend.views.html.RemoveGoodsView + +import scala.concurrent.{ExecutionContext, Future} + +@Singleton +class RemoveGoodsController @Inject()( + override val controllerComponents: MessagesControllerComponents, + actionProvider: DeclarationJourneyActionProvider, + repo: DeclarationJourneyRepository, + view: RemoveGoodsView + )(implicit ec: ExecutionContext, appConfig: AppConfig) + extends IndexedDeclarationJourneyUpdateController { + + def onPageLoad(idx: Int): Action[AnyContent] = actionProvider.goodsAction(idx).async { implicit request => + withGoodsCategory(request.goodsEntry) { category => + Future successful Ok(view(form, idx, category)) + } + } + + def onSubmit(idx: Int): Action[AnyContent] = actionProvider.goodsAction(idx).async { implicit request => + withGoodsCategory(request.goodsEntry) { category => + form + .bindFromRequest() + .fold( + formWithErrors => Future.successful(BadRequest(view(formWithErrors, idx, category))), + removeGoods => { + if(removeGoods) { + repo.upsert( + request.declarationJourney.copy( + goodsEntries = request.declarationJourney.goodsEntries.remove(idx) + ) + ).map { _ => + if(request.declarationJourney.goodsEntries.entries.size == 1) Redirect(routes.GoodsRemovedController.onPageLoad) + else Redirect(routes.ReviewGoodsController.onPageLoad()) + } + } else { + Future successful Redirect(routes.ReviewGoodsController.onPageLoad()) + } + } + ) + } + } + +} diff --git a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/ReviewGoodsController.scala b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/ReviewGoodsController.scala index ba595616f..695c2dd9d 100644 --- a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/ReviewGoodsController.scala +++ b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/ReviewGoodsController.scala @@ -17,10 +17,9 @@ package uk.gov.hmrc.merchandiseinbaggagefrontend.controllers import javax.inject.{Inject, Singleton} -import play.api.data.Form import play.api.mvc.{Action, AnyContent, MessagesControllerComponents} import uk.gov.hmrc.merchandiseinbaggagefrontend.config.AppConfig -import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.ReviewGoodsFormProvider +import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.ReviewGoodsForm.form import uk.gov.hmrc.merchandiseinbaggagefrontend.model.core.{GoodsEntries, GoodsEntry} import uk.gov.hmrc.merchandiseinbaggagefrontend.repositories.DeclarationJourneyRepository import uk.gov.hmrc.merchandiseinbaggagefrontend.views.html.ReviewGoodsView @@ -30,14 +29,11 @@ import scala.concurrent.{ExecutionContext, Future} @Singleton class ReviewGoodsController @Inject()(override val controllerComponents: MessagesControllerComponents, actionProvider: DeclarationJourneyActionProvider, - formProvider: ReviewGoodsFormProvider, repo: DeclarationJourneyRepository, view: ReviewGoodsView) (implicit ec: ExecutionContext, appConfig: AppConfig) extends DeclarationJourneyUpdateController { - val form: Form[Boolean] = formProvider() - val onPageLoad: Action[AnyContent] = actionProvider.journeyAction { implicit request => request.declarationJourney.goodsEntries.declarationGoodsIfComplete.fold(actionProvider.invalidRequest) { goods => Ok(view(form, goods)) diff --git a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/SearchGoodsController.scala b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/SearchGoodsController.scala index 9ce25a2c3..69bc7bf50 100644 --- a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/SearchGoodsController.scala +++ b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/SearchGoodsController.scala @@ -17,11 +17,9 @@ package uk.gov.hmrc.merchandiseinbaggagefrontend.controllers import javax.inject.{Inject, Singleton} -import play.api.data.Form import play.api.mvc.{Action, AnyContent, MessagesControllerComponents} import uk.gov.hmrc.merchandiseinbaggagefrontend.config.AppConfig -import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.SearchGoodsFormProvider -import uk.gov.hmrc.merchandiseinbaggagefrontend.model.core.{CategoryQuantityOfGoods, GoodsEntries} +import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.SearchGoodsForm.form import uk.gov.hmrc.merchandiseinbaggagefrontend.repositories.DeclarationJourneyRepository import uk.gov.hmrc.merchandiseinbaggagefrontend.views.html.SearchGoodsView @@ -31,44 +29,35 @@ import scala.concurrent.{ExecutionContext, Future} class SearchGoodsController @Inject()( override val controllerComponents: MessagesControllerComponents, actionProvider: DeclarationJourneyActionProvider, - formProvider: SearchGoodsFormProvider, repo: DeclarationJourneyRepository, view: SearchGoodsView )(implicit ec: ExecutionContext, appConfig: AppConfig) extends IndexedDeclarationJourneyUpdateController { - val form: Form[CategoryQuantityOfGoods] = formProvider() + def onPageLoad(idx: Int): Action[AnyContent] = actionProvider.goodsAction(idx) { implicit request => + val preparedForm = request.goodsEntry.maybeCategoryQuantityOfGoods.fold(form)(form.fill) - def onPageLoad(idx: Int): Action[AnyContent] = actionProvider.journeyAction { implicit request => - request.declarationJourney.goodsEntries.entries.lift(idx - 1).fold(actionProvider.invalidRequest) { goodsEntry => - val preparedForm = goodsEntry.maybeCategoryQuantityOfGoods.fold(form)(form.fill) - - Ok(view(preparedForm, idx)) - } + Ok(view(preparedForm, idx)) } - def onSubmit(idx: Int): Action[AnyContent] = actionProvider.journeyAction.async { implicit request => - request.declarationJourney.goodsEntries.entries.lift(idx - 1).fold(actionProvider.invalidRequestF) { goodsEntry => - form - .bindFromRequest() - .fold( - formWithErrors => Future.successful(BadRequest(view(formWithErrors, idx))), - categoryQuantityOfGoods => { - val updatedGoodsEntries = - request.declarationJourney.goodsEntries.entries.updated( - idx - 1, - goodsEntry.copy(maybeCategoryQuantityOfGoods = Some(categoryQuantityOfGoods))) - - repo.upsert( - request.declarationJourney.copy( - goodsEntries = GoodsEntries(updatedGoodsEntries) + def onSubmit(idx: Int): Action[AnyContent] = actionProvider.goodsAction(idx).async { implicit request => + form + .bindFromRequest() + .fold( + formWithErrors => Future.successful(BadRequest(view(formWithErrors, idx))), + categoryQuantityOfGoods => { + repo.upsert( + request.declarationJourney.copy( + goodsEntries = request.declarationJourney.goodsEntries.patch( + idx, + request.goodsEntry.copy(maybeCategoryQuantityOfGoods = Some(categoryQuantityOfGoods)) ) - ).map { _ => - Redirect(routes.GoodsVatRateController.onPageLoad(idx)) - } + ) + ).map { _ => + Redirect(routes.GoodsVatRateController.onPageLoad(idx)) } - ) - } + } + ) } } diff --git a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/SearchGoodsCountryController.scala b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/SearchGoodsCountryController.scala index dff6e183a..7bb249a1e 100644 --- a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/SearchGoodsCountryController.scala +++ b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/SearchGoodsCountryController.scala @@ -20,8 +20,7 @@ import javax.inject.{Inject, Singleton} import play.api.data.Form import play.api.mvc.{Action, AnyContent, MessagesControllerComponents} import uk.gov.hmrc.merchandiseinbaggagefrontend.config.AppConfig -import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.SearchGoodsCountryFormProvider -import uk.gov.hmrc.merchandiseinbaggagefrontend.model.core.GoodsEntries +import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.SearchGoodsCountryForm.form import uk.gov.hmrc.merchandiseinbaggagefrontend.repositories.DeclarationJourneyRepository import uk.gov.hmrc.merchandiseinbaggagefrontend.service.CountriesService import uk.gov.hmrc.merchandiseinbaggagefrontend.views.html.SearchGoodsCountryView @@ -32,48 +31,41 @@ import scala.concurrent.{ExecutionContext, Future} class SearchGoodsCountryController @Inject()( override val controllerComponents: MessagesControllerComponents, actionProvider: DeclarationJourneyActionProvider, - formProvider: SearchGoodsCountryFormProvider, repo: DeclarationJourneyRepository, view: SearchGoodsCountryView )(implicit ec: ExecutionContext, appConfig: AppConfig) extends IndexedDeclarationJourneyUpdateController { - val form: Form[String] = formProvider(CountriesService.countries) + val countriesForm: Form[String] = form(CountriesService.countries) - def onPageLoad(idx: Int): Action[AnyContent] = actionProvider.journeyAction { implicit request => - request.declarationJourney.goodsEntries.entries.lift(idx - 1).fold(actionProvider.invalidRequest) { goodsEntry => - goodsEntry.maybeCategoryQuantityOfGoods.fold(actionProvider.invalidRequest) { categoryQuantityOfGoods => - val preparedForm = goodsEntry.maybeCountryOfPurchase.fold(form)(form.fill) + def onPageLoad(idx: Int): Action[AnyContent] = actionProvider.goodsAction(idx).async { implicit request => + withGoodsCategory(request.goodsEntry) { category => + val preparedForm = request.goodsEntry.maybeCountryOfPurchase.fold(countriesForm)(countriesForm.fill) - Ok(view(preparedForm, idx, categoryQuantityOfGoods.category)) - } + Future successful Ok(view(preparedForm, idx, category)) } } - def onSubmit(idx: Int): Action[AnyContent] = actionProvider.journeyAction.async { implicit request => - request.declarationJourney.goodsEntries.entries.lift(idx - 1).fold(actionProvider.invalidRequestF) { goodsEntry => - goodsEntry.maybeCategoryQuantityOfGoods.fold(actionProvider.invalidRequestF) { categoryQuantityOfGoods => - form - .bindFromRequest() - .fold( - formWithErrors => - Future.successful(BadRequest(view(formWithErrors, idx, categoryQuantityOfGoods.category))), - country => { - val updatedGoodsEntries = - request.declarationJourney.goodsEntries.entries.updated( - idx - 1, - goodsEntry.copy(maybeCountryOfPurchase = Some(country))) - - repo.upsert( - request.declarationJourney.copy( - goodsEntries = GoodsEntries(updatedGoodsEntries) + def onSubmit(idx: Int): Action[AnyContent] = actionProvider.goodsAction(idx).async { implicit request => + withGoodsCategory(request.goodsEntry) { category => + countriesForm + .bindFromRequest() + .fold( + formWithErrors => + Future.successful(BadRequest(view(formWithErrors, idx, category))), + country => { + repo.upsert( + request.declarationJourney.copy( + goodsEntries = request.declarationJourney.goodsEntries.patch( + idx, + request.goodsEntry.copy(maybeCountryOfPurchase = Some(country)) ) - ).map { _ => - Redirect(routes.PurchaseDetailsController.onPageLoad(idx)) - } + ) + ).map { _ => + Redirect(routes.PurchaseDetailsController.onPageLoad(idx)) } - ) - } + } + ) } } diff --git a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/SkeletonJourneyController.scala b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/SkeletonJourneyController.scala index 59507865c..51e720bf2 100644 --- a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/SkeletonJourneyController.scala +++ b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/SkeletonJourneyController.scala @@ -37,14 +37,6 @@ class SkeletonJourneyController @Inject()(mcc: MessagesControllerComponents, extends FrontendController(mcc) { implicit def messages(implicit request: Request[_]): Messages = controllerComponents.messagesApi.preferred(request) - val removeGoods: Action[AnyContent] = actionProvider.journeyAction { implicit request => - Ok(page(s"removeGoods.title", routes.SkeletonJourneyController.goodsRemoved())) - } - - val goodsRemoved: Action[AnyContent] = actionProvider.journeyAction { implicit request => - Ok(page(s"goodsRemoved.title", routes.SearchGoodsController.onPageLoad(1))) - } - val taxCalculation: Action[AnyContent] = actionProvider.journeyAction { implicit request => Ok(page(s"taxCalculation.title", routes.SkeletonJourneyController.customsAgent())) } diff --git a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/ValueWeightOfGoodsController.scala b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/ValueWeightOfGoodsController.scala index 2c8f637a2..ef0e35d13 100644 --- a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/ValueWeightOfGoodsController.scala +++ b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/ValueWeightOfGoodsController.scala @@ -17,10 +17,9 @@ package uk.gov.hmrc.merchandiseinbaggagefrontend.controllers import javax.inject.{Inject, Singleton} -import play.api.data.Form import play.api.mvc.{Action, AnyContent, MessagesControllerComponents} import uk.gov.hmrc.merchandiseinbaggagefrontend.config.AppConfig -import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.ValueWeightOfGoodsFormProvider +import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.ValueWeightOfGoodsForm.form import uk.gov.hmrc.merchandiseinbaggagefrontend.repositories.DeclarationJourneyRepository import uk.gov.hmrc.merchandiseinbaggagefrontend.views.html.ValueWeightOfGoodsView @@ -29,14 +28,11 @@ import scala.concurrent.{ExecutionContext, Future} @Singleton class ValueWeightOfGoodsController @Inject()(override val controllerComponents: MessagesControllerComponents, actionProvider: DeclarationJourneyActionProvider, - formProvider: ValueWeightOfGoodsFormProvider, repo: DeclarationJourneyRepository, view: ValueWeightOfGoodsView) (implicit ec: ExecutionContext, appConfig: AppConfig) extends DeclarationJourneyUpdateController { - val form: Form[Boolean] = formProvider() - val onPageLoad: Action[AnyContent] = actionProvider.journeyAction { implicit request => request.declarationJourney.maybeGoodsDestination match { case Some(dest) => Ok( diff --git a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/ExciseAndRestrictedGoodsFormProvider.scala b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/ExciseAndRestrictedGoodsForm.scala similarity index 86% rename from app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/ExciseAndRestrictedGoodsFormProvider.scala rename to app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/ExciseAndRestrictedGoodsForm.scala index 99db83fde..3dc095303 100644 --- a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/ExciseAndRestrictedGoodsFormProvider.scala +++ b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/ExciseAndRestrictedGoodsForm.scala @@ -16,13 +16,12 @@ package uk.gov.hmrc.merchandiseinbaggagefrontend.forms -import javax.inject.Inject import play.api.data.Form import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.mappings.Mappings -class ExciseAndRestrictedGoodsFormProvider @Inject() extends Mappings { +object ExciseAndRestrictedGoodsForm extends Mappings { - def apply(): Form[Boolean] = + val form: Form[Boolean] = Form( "value" -> boolean("exciseAndRestrictedGoods.error.required") ) diff --git a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/GoodsDestinationFormProvider.scala b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/GoodsDestinationForm.scala similarity index 88% rename from app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/GoodsDestinationFormProvider.scala rename to app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/GoodsDestinationForm.scala index 538b9e828..b4f474e64 100644 --- a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/GoodsDestinationFormProvider.scala +++ b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/GoodsDestinationForm.scala @@ -16,13 +16,13 @@ package uk.gov.hmrc.merchandiseinbaggagefrontend.forms -import javax.inject.Inject import play.api.data.Form import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.mappings.Mappings import uk.gov.hmrc.merchandiseinbaggagefrontend.model.core.{GoodsDestination, GoodsDestinations} -class GoodsDestinationFormProvider @Inject() extends Mappings { - def apply(): Form[GoodsDestination] = +object GoodsDestinationForm extends Mappings { + + val form: Form[GoodsDestination] = Form( "value" -> enum[GoodsDestination](GoodsDestinations, "goodsDestination.error.required") ) diff --git a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/GoodsVatRateFormProvider.scala b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/GoodsVatRateForm.scala similarity index 88% rename from app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/GoodsVatRateFormProvider.scala rename to app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/GoodsVatRateForm.scala index 6d66173a8..526be30c8 100644 --- a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/GoodsVatRateFormProvider.scala +++ b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/GoodsVatRateForm.scala @@ -16,14 +16,13 @@ package uk.gov.hmrc.merchandiseinbaggagefrontend.forms -import javax.inject.Inject import play.api.data.Form import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.mappings.Mappings import uk.gov.hmrc.merchandiseinbaggagefrontend.model.core.{GoodsVatRate, GoodsVatRates} -class GoodsVatRateFormProvider @Inject() extends Mappings { +object GoodsVatRateForm extends Mappings { - def apply(): Form[GoodsVatRate] = + val form: Form[GoodsVatRate] = Form( "value" -> enum[GoodsVatRate](GoodsVatRates, "goodsVatRate.error.required") ) diff --git a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/RemoveGoodsForm.scala b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/RemoveGoodsForm.scala new file mode 100644 index 000000000..0c633a094 --- /dev/null +++ b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/RemoveGoodsForm.scala @@ -0,0 +1,29 @@ +/* + * Copyright 2020 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 uk.gov.hmrc.merchandiseinbaggagefrontend.forms + +import play.api.data.Form +import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.mappings.Mappings + +object RemoveGoodsForm extends Mappings { + + val form: Form[Boolean] = + Form( + "value" -> boolean("removeGoods.error.required") + ) + +} diff --git a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/ReviewGoodsFormProvider.scala b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/ReviewGoodsForm.scala similarity index 87% rename from app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/ReviewGoodsFormProvider.scala rename to app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/ReviewGoodsForm.scala index 79eda1e93..91ac0cdb0 100644 --- a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/ReviewGoodsFormProvider.scala +++ b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/ReviewGoodsForm.scala @@ -16,13 +16,12 @@ package uk.gov.hmrc.merchandiseinbaggagefrontend.forms -import javax.inject.Inject import play.api.data.Form import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.mappings.Mappings -class ReviewGoodsFormProvider @Inject() extends Mappings { +object ReviewGoodsForm extends Mappings { - def apply(): Form[Boolean] = + val form: Form[Boolean] = Form( "value" -> boolean("reviewGoods.error.required") ) diff --git a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/SearchGoodsCountryFormProvider.scala b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/SearchGoodsCountryForm.scala similarity index 86% rename from app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/SearchGoodsCountryFormProvider.scala rename to app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/SearchGoodsCountryForm.scala index d184e959b..d5471de32 100644 --- a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/SearchGoodsCountryFormProvider.scala +++ b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/SearchGoodsCountryForm.scala @@ -16,13 +16,12 @@ package uk.gov.hmrc.merchandiseinbaggagefrontend.forms -import javax.inject.Inject import play.api.data.Form import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.mappings.Mappings -class SearchGoodsCountryFormProvider @Inject() extends Mappings { +object SearchGoodsCountryForm extends Mappings { - def apply(options: List[String]): Form[String] = + def form(options: List[String]): Form[String] = Form( "value" -> text("searchGoodsCountry.error.required") .verifying(existInList(options, "searchGoodsCountry.error.invalid")) diff --git a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/SearchGoodsFormProvider.scala b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/SearchGoodsForm.scala similarity index 89% rename from app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/SearchGoodsFormProvider.scala rename to app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/SearchGoodsForm.scala index 4430d73a2..e7938ed52 100644 --- a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/SearchGoodsFormProvider.scala +++ b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/SearchGoodsForm.scala @@ -16,15 +16,14 @@ package uk.gov.hmrc.merchandiseinbaggagefrontend.forms -import javax.inject.Inject import play.api.data.Form import play.api.data.Forms.mapping import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.mappings.Mappings import uk.gov.hmrc.merchandiseinbaggagefrontend.model.core.CategoryQuantityOfGoods -class SearchGoodsFormProvider @Inject() extends Mappings { +object SearchGoodsForm extends Mappings { - def apply(): Form[CategoryQuantityOfGoods] = + val form: Form[CategoryQuantityOfGoods] = Form( mapping( "category" -> text("searchGoods.category.error.required"), diff --git a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/ValueWeightOfGoodsFormProvider.scala b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/ValueWeightOfGoodsForm.scala similarity index 87% rename from app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/ValueWeightOfGoodsFormProvider.scala rename to app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/ValueWeightOfGoodsForm.scala index 82462d0f1..aa4f22024 100644 --- a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/ValueWeightOfGoodsFormProvider.scala +++ b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/ValueWeightOfGoodsForm.scala @@ -16,13 +16,12 @@ package uk.gov.hmrc.merchandiseinbaggagefrontend.forms -import javax.inject.Inject import play.api.data.Form import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.mappings.Mappings -class ValueWeightOfGoodsFormProvider @Inject() extends Mappings { +object ValueWeightOfGoodsForm extends Mappings { - def apply(): Form[Boolean] = + val form: Form[Boolean] = Form( "value" -> boolean("valueWeightOfGoods.error.required") ) diff --git a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/model/core/Declaration.scala b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/model/core/Declaration.scala index 8693611ac..c3794081d 100644 --- a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/model/core/Declaration.scala +++ b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/model/core/Declaration.scala @@ -21,9 +21,10 @@ import java.time.format.DateTimeFormatter import java.util.UUID.randomUUID import play.api.i18n.Messages +import uk.gov.hmrc.merchandiseinbaggagefrontend.controllers.routes._ import play.api.libs.functional.syntax._ import play.api.libs.json.{Format, Json, OFormat} -import uk.gov.hmrc.govukfrontend.views.Aliases.{Key, SummaryList, Text, Value} +import uk.gov.hmrc.govukfrontend.views.Aliases.{HtmlContent, Key, SummaryList, Text, Value} import uk.gov.hmrc.govukfrontend.views.viewmodels.summarylist.SummaryListRow import uk.gov.hmrc.merchandiseinbaggagefrontend.model.currencyconversion.Currency @@ -86,6 +87,14 @@ case class GoodsEntries(entries: Seq[GoodsEntry] = Seq(GoodsEntry.empty)) { if (entries.nonEmpty && (goods.size == entries.size)) Some(DeclarationGoods(goods)) else None } + + def patch(idx: Int, goodsEntry: GoodsEntry): GoodsEntries = + GoodsEntries(entries.updated(idx -1, goodsEntry)) + + def remove(idx: Int): GoodsEntries = { + if(entries.size == 1) GoodsEntries.empty + else GoodsEntries(entries.zipWithIndex.filter(_._2 != idx - 1).map(_._1)) + } } object GoodsEntries { @@ -212,9 +221,9 @@ case class Goods(categoryQuantityOfGoods: CategoryQuantityOfGoods, purchaseDetails: PurchaseDetails, invoiceNumber: String, taxDue: BigDecimal) { - def toSummaryList(implicit messages: Messages): SummaryList = { + def toSummaryList(idx: Int)(implicit messages: Messages): SummaryList = { val price = - s"${purchaseDetails.amount}, ${purchaseDetails.currency.displayName})" + s"${purchaseDetails.amount}, ${purchaseDetails.currency.displayName}" SummaryList(Seq( SummaryListRow( @@ -236,6 +245,12 @@ case class Goods(categoryQuantityOfGoods: CategoryQuantityOfGoods, SummaryListRow( Key(Text(messages("reviewGoods.list.invoice"))), Value(Text(invoiceNumber)) + ), + SummaryListRow( + key = Key( + HtmlContent(s"""${messages("site.remove")}""") + ), + classes = "govuk-summary-list__row--no-border" ) )) } diff --git a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/views/GoodsRemovedView.scala.html b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/views/GoodsRemovedView.scala.html new file mode 100644 index 000000000..6ca8ecf4a --- /dev/null +++ b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/views/GoodsRemovedView.scala.html @@ -0,0 +1,37 @@ +@* + * Copyright 2020 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. + *@ + +@import uk.gov.hmrc.govukfrontend.views.html.components +@import uk.gov.hmrc.merchandiseinbaggagefrontend.controllers.routes._ + +@this( +layout: Layout, +h1: components.h1, +p: components.p +) + +@()(implicit request: Request[_], messages: Messages, appConfig: AppConfig) + +@layout(pageTitle = Some(messages("goodsRemoved.title"))) { + @h1("goodsRemoved.heading") + + @p(Html(messages("goodsRemoved.p1"))) + +

@messages("goodsRemoved.link")

+ +

@messages("site.startAgain")

+ +} diff --git a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/views/RemoveGoodsView.scala.html b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/views/RemoveGoodsView.scala.html new file mode 100644 index 000000000..2f7ca92f7 --- /dev/null +++ b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/views/RemoveGoodsView.scala.html @@ -0,0 +1,43 @@ +@* + * Copyright 2020 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. + *@ + +@import uk.gov.hmrc.govukfrontend.views.html.components +@import uk.gov.hmrc.merchandiseinbaggagefrontend.controllers.routes._ + +@this( +layout: Layout, +formHelper: FormWithCSRF, +errorSummary: components.errorSummary, +inputYesNo: components.inputYesNo, +button: components.button +) + +@(form: Form[_], idx: Int, goodsCategory: String)(implicit request: Request[_], messages: Messages, appConfig: AppConfig) + +@layout(pageTitle = Some(messages(s"removeGoods.title", goodsCategory))) { + @formHelper(action = RemoveGoodsController.onSubmit(idx), 'autoComplete -> "off", 'novalidate -> "novalidate") { + + @errorSummary(form.errors) + + @inputYesNo( + form = form, + legend = messages(s"removeGoods.heading", goodsCategory), + legendAsHeading = true + ) + + @button("site.confirm") + } +} diff --git a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/views/ReviewGoodsView.scala.html b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/views/ReviewGoodsView.scala.html index a2593309f..e59dbe63b 100644 --- a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/views/ReviewGoodsView.scala.html +++ b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/views/ReviewGoodsView.scala.html @@ -38,8 +38,8 @@ @h1(messages("reviewGoods.heading")) - @for(goods <- goods.goods) { - @summaryList(goods.toSummaryList) + @for((goods, idx) <- goods.goods.zipWithIndex) { + @summaryList(goods.toSummaryList(idx + 1)) } @h3(messages("reviewGoods.h3")) diff --git a/conf/app.routes b/conf/app.routes index c317d7c21..24cf24ad4 100644 --- a/conf/app.routes +++ b/conf/app.routes @@ -8,8 +8,6 @@ GET /assets/*file controllers.Assets.versioned(path = "/p GET /payment uk.gov.hmrc.merchandiseinbaggagefrontend.controllers.PaymentController.onPageLoad POST /process-payment uk.gov.hmrc.merchandiseinbaggagefrontend.controllers.PaymentController.onSubmit() -GET /remove-goods uk.gov.hmrc.merchandiseinbaggagefrontend.controllers.SkeletonJourneyController.removeGoods -GET /goods-removed uk.gov.hmrc.merchandiseinbaggagefrontend.controllers.SkeletonJourneyController.goodsRemoved GET /tax-calculation uk.gov.hmrc.merchandiseinbaggagefrontend.controllers.SkeletonJourneyController.taxCalculation GET /customs-agent uk.gov.hmrc.merchandiseinbaggagefrontend.controllers.SkeletonJourneyController.customsAgent GET /agent-details uk.gov.hmrc.merchandiseinbaggagefrontend.controllers.SkeletonJourneyController.agentDetails @@ -67,6 +65,13 @@ POST /invoice-number/:idx uk.gov.hmrc.merchandiseinbaggagefronten GET /review-goods uk.gov.hmrc.merchandiseinbaggagefrontend.controllers.ReviewGoodsController.onPageLoad POST /review-goods uk.gov.hmrc.merchandiseinbaggagefrontend.controllers.ReviewGoodsController.onSubmit +# RemoveGoods +GET /remove-goods/:idx uk.gov.hmrc.merchandiseinbaggagefrontend.controllers.RemoveGoodsController.onPageLoad(idx: Int) +POST /remove-goods/:idx uk.gov.hmrc.merchandiseinbaggagefrontend.controllers.RemoveGoodsController.onSubmit(idx: Int) + +# GoodsRemoved +GET /goods-removed uk.gov.hmrc.merchandiseinbaggagefrontend.controllers.GoodsRemovedController.onPageLoad + # TraderDetalis GET /traveller-details uk.gov.hmrc.merchandiseinbaggagefrontend.controllers.TravellerDetailsController.onPageLoad POST /traveller-details uk.gov.hmrc.merchandiseinbaggagefrontend.controllers.TravellerDetailsController.onSubmit diff --git a/conf/messages b/conf/messages index 67e925849..6c7b638ff 100644 --- a/conf/messages +++ b/conf/messages @@ -23,7 +23,10 @@ error.must.be.positive = Enter an amount greater than 0 site.yes = Yes site.no = No site.continue = Continue +site.confirm = Confirm site.start = Start now +site.startAgain = Start again +site.remove = Remove payment.button = Pay now next.button = Next @@ -174,6 +177,17 @@ reviewGoods.list.invoice = Invoice number reviewGoods.h3 = Do you need to declare more goods? reviewGoods.error.required = Select one of the options below +# RemoveGoods +removeGoods.title = Are you sure you want to remove the {0}? +removeGoods.heading = Are you sure you want to remove the {0}? +removeGoods.error.required = Select one of the options below + +# GoodsRemoved +goodsRemoved.title = You removed your goods +goodsRemoved.heading = You removed your goods +goodsRemoved.p1 = You have no goods to declare. +goodsRemoved.link = Add other goods + # TraderDetails travellerDetails.title = Enter the name of the person carrying the goods travellerDetails.heading = Enter the name of the person carrying the goods diff --git a/test/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/ExciseAndRestrictedGoodsControllerSpec.scala b/test/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/ExciseAndRestrictedGoodsControllerSpec.scala index d9353e9a5..c791d40f7 100644 --- a/test/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/ExciseAndRestrictedGoodsControllerSpec.scala +++ b/test/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/ExciseAndRestrictedGoodsControllerSpec.scala @@ -18,19 +18,16 @@ package uk.gov.hmrc.merchandiseinbaggagefrontend.controllers import play.api.mvc.Result import play.api.test.Helpers._ -import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.ExciseAndRestrictedGoodsFormProvider import uk.gov.hmrc.merchandiseinbaggagefrontend.views.html.ExciseAndRestrictedGoodsView import scala.concurrent.ExecutionContext.Implicits.global import scala.concurrent.Future class ExciseAndRestrictedGoodsControllerSpec extends DeclarationJourneyControllerSpec { - private val formProvider = new ExciseAndRestrictedGoodsFormProvider() - private val form = formProvider() private lazy val controller = new ExciseAndRestrictedGoodsController( - controllerComponents, actionBuilder, formProvider, declarationJourneyRepository, injector.instanceOf[ExciseAndRestrictedGoodsView]) + controllerComponents, actionBuilder, declarationJourneyRepository, injector.instanceOf[ExciseAndRestrictedGoodsView]) private def ensureContent(result: Future[Result]) = { val content = contentAsString(result) @@ -109,7 +106,6 @@ class ExciseAndRestrictedGoodsControllerSpec extends DeclarationJourneyControlle "return BAD_REQUEST and errors" when { "no selection is made" in { givenADeclarationJourneyIsPersisted(startedDeclarationJourney) - form.bindFromRequest()(postRequest) val result = controller.onSubmit()(postRequest) diff --git a/test/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/GoodsDestinationControllerSpec.scala b/test/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/GoodsDestinationControllerSpec.scala index ab6e69562..b206e9995 100644 --- a/test/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/GoodsDestinationControllerSpec.scala +++ b/test/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/GoodsDestinationControllerSpec.scala @@ -18,7 +18,6 @@ package uk.gov.hmrc.merchandiseinbaggagefrontend.controllers import play.api.mvc.Result import play.api.test.Helpers._ -import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.GoodsDestinationFormProvider import uk.gov.hmrc.merchandiseinbaggagefrontend.model.core.GoodsDestinations import uk.gov.hmrc.merchandiseinbaggagefrontend.model.core.GoodsDestinations.NorthernIreland import uk.gov.hmrc.merchandiseinbaggagefrontend.views.html.GoodsDestinationView @@ -27,12 +26,10 @@ import scala.concurrent.ExecutionContext.Implicits.global import scala.concurrent.Future class GoodsDestinationControllerSpec extends DeclarationJourneyControllerSpec { - private val formProvider = new GoodsDestinationFormProvider() - private val form = formProvider() private lazy val controller = new GoodsDestinationController( - controllerComponents, actionBuilder, formProvider, declarationJourneyRepository, injector.instanceOf[GoodsDestinationView]) + controllerComponents, actionBuilder, declarationJourneyRepository, injector.instanceOf[GoodsDestinationView]) private def ensureContent(result: Future[Result]): String = { val content = contentAsString(result) @@ -86,8 +83,6 @@ class GoodsDestinationControllerSpec extends DeclarationJourneyControllerSpec { val request = postRequest.withFormUrlEncodedBody(("value", NorthernIreland.toString)) - form.bindFromRequest()(request) - val result = controller.onSubmit()(request) status(result) mustEqual SEE_OTHER @@ -99,7 +94,6 @@ class GoodsDestinationControllerSpec extends DeclarationJourneyControllerSpec { "return BAD_REQUEST and errors" when { "no selection is made" in { givenADeclarationJourneyIsPersisted(startedDeclarationJourney) - form.bindFromRequest()(postRequest) val result = controller.onSubmit()(postRequest) diff --git a/test/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/GoodsRemovedControllerSpec.scala b/test/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/GoodsRemovedControllerSpec.scala new file mode 100644 index 000000000..c37895970 --- /dev/null +++ b/test/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/GoodsRemovedControllerSpec.scala @@ -0,0 +1,43 @@ +/* + * Copyright 2020 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 uk.gov.hmrc.merchandiseinbaggagefrontend.controllers + +import play.api.test.Helpers._ +import uk.gov.hmrc.merchandiseinbaggagefrontend.views.html.GoodsRemovedView + +class GoodsRemovedControllerSpec extends DeclarationJourneyControllerSpec { + private val controller = new GoodsRemovedController(controllerComponents, actionBuilder, injector.instanceOf[GoodsRemovedView]) + private val url = routes.GoodsRemovedController.onPageLoad().url + + "onPageLoad" must { + behave like anEndpointRequiringASessionIdAndLinkedDeclarationJourneyToLoad(controller, url) + + "return OK and render the view" when{ + "a declaration journey has been started" in { + givenADeclarationJourneyIsPersisted(startedDeclarationJourney) + val request = buildGet(url, sessionId) + val result = controller.onPageLoad()(request) + val content = contentAsString(result) + + status(result) mustEqual OK + content must include("You removed your goods") + content must include("You have no goods to declare.") + content must include("Add other goods") + } + } + } +} diff --git a/test/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/GoodsVatRateControllerSpec.scala b/test/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/GoodsVatRateControllerSpec.scala index eb595e6c6..59129d9d9 100644 --- a/test/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/GoodsVatRateControllerSpec.scala +++ b/test/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/GoodsVatRateControllerSpec.scala @@ -18,7 +18,6 @@ package uk.gov.hmrc.merchandiseinbaggagefrontend.controllers import play.api.mvc.Result import play.api.test.Helpers._ -import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.GoodsVatRateFormProvider import uk.gov.hmrc.merchandiseinbaggagefrontend.model.core.GoodsVatRates.Twenty import uk.gov.hmrc.merchandiseinbaggagefrontend.model.core.{GoodsEntries, GoodsEntry} import uk.gov.hmrc.merchandiseinbaggagefrontend.views.html.GoodsVatRateView @@ -27,12 +26,10 @@ import scala.concurrent.ExecutionContext.Implicits.global import scala.concurrent.Future class GoodsVatRateControllerSpec extends DeclarationJourneyControllerSpec { - private val formProvider = new GoodsVatRateFormProvider() - private val form = formProvider() private lazy val controller = new GoodsVatRateController( - controllerComponents, actionBuilder, formProvider, declarationJourneyRepository, injector.instanceOf[GoodsVatRateView]) + controllerComponents, actionBuilder, declarationJourneyRepository, injector.instanceOf[GoodsVatRateView]) private def ensureContent(result: Future[Result], goodsEntry: GoodsEntry) = { val content = contentAsString(result) @@ -74,8 +71,6 @@ class GoodsVatRateControllerSpec extends DeclarationJourneyControllerSpec { val request = postRequest.withFormUrlEncodedBody(("value", "Twenty")) - form.bindFromRequest()(request) - val result = controller.onSubmit(1)(request) status(result) mustEqual SEE_OTHER @@ -89,7 +84,6 @@ class GoodsVatRateControllerSpec extends DeclarationJourneyControllerSpec { "return BAD_REQUEST and errors" when { "no selection is made" in { givenADeclarationJourneyIsPersisted(declarationJourneyWithStartedGoodsEntry) - form.bindFromRequest()(postRequest) val result = controller.onSubmit(1)(postRequest) diff --git a/test/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/RemoveGoodsControllerSpec.scala b/test/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/RemoveGoodsControllerSpec.scala new file mode 100644 index 000000000..394cbb262 --- /dev/null +++ b/test/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/RemoveGoodsControllerSpec.scala @@ -0,0 +1,134 @@ +/* + * Copyright 2020 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 uk.gov.hmrc.merchandiseinbaggagefrontend.controllers + +import play.api.mvc.Result +import play.api.test.Helpers._ +import uk.gov.hmrc.merchandiseinbaggagefrontend.model.core.{GoodsEntries, GoodsEntry} +import uk.gov.hmrc.merchandiseinbaggagefrontend.views.html.RemoveGoodsView + +import scala.concurrent.ExecutionContext.Implicits.global +import scala.concurrent.Future + +class RemoveGoodsControllerSpec extends DeclarationJourneyControllerSpec { + + private lazy val controller = + new RemoveGoodsController( + controllerComponents, actionBuilder, declarationJourneyRepository, injector.instanceOf[RemoveGoodsView]) + + private def ensureContent(result: Future[Result], goodsEntry: GoodsEntry) = { + val content = contentAsString(result) + + content must include(s"Are you sure you want to remove the ${goodsEntry.maybeCategoryQuantityOfGoods.get.category}?") + content must include("Confirm") + + content + } + + "onPageLoad" must { + val url = routes.RemoveGoodsController.onPageLoad(1).url + val request = buildGet(url, sessionId) + + behave like anIndexedEndpointRequiringASessionIdAndLinkedDeclarationJourneyToLoad(controller, url) + + "redirect to /invalid-request" when { + "a declaration has been started but a required answer is missing in the journey" in { + givenADeclarationJourneyIsPersisted(startedDeclarationJourney) + + val result = controller.onPageLoad(1)(request) + + status(result) mustEqual SEE_OTHER + redirectLocation(result).get mustEqual routes.InvalidRequestController.onPageLoad().toString + } + } + + "return OK and render the view" when { + "a declaration has been started" in { + givenADeclarationJourneyIsPersisted(startedDeclarationJourney.copy(goodsEntries = GoodsEntries(completedGoodsEntry))) + + val result = controller.onPageLoad(1)(request) + + status(result) mustEqual OK + ensureContent(result, completedGoodsEntry) + } + } + } + + "onSubmit" must { + val url = routes.RemoveGoodsController.onSubmit(1).url + val postRequest = buildPost(url, sessionId) + + behave like anIndexedEndpointRequiringASessionIdAndLinkedDeclarationJourneyToUpdate(controller, url) + + "Redirect to /review-goods" when { + "a declaration is started and false is submitted" in { + val before = startedDeclarationJourney.copy(goodsEntries = GoodsEntries(Seq(completedGoodsEntry, completedGoodsEntry))) + givenADeclarationJourneyIsPersisted(before) + + val request = postRequest.withFormUrlEncodedBody(("value", "false")) + val result = controller.onSubmit(1)(request) + + status(result) mustEqual SEE_OTHER + redirectLocation(result).get mustEqual routes.ReviewGoodsController.onPageLoad().toString + + //Assert than no deletions were made + before.goodsEntries.entries.size mustBe 2 + declarationJourneyRepository.findBySessionId(sessionId).futureValue.get.goodsEntries.entries.size mustBe 2 + } + } + + "Redirect to /review-goods" when { + "a declaration is started and true is submitted and goods still exist in the journey" in { + val before = startedDeclarationJourney.copy(goodsEntries = GoodsEntries(Seq(completedGoodsEntry, completedGoodsEntry))) + givenADeclarationJourneyIsPersisted(before) + + val request = postRequest.withFormUrlEncodedBody(("value", "true")) + val result = controller.onSubmit(1)(request) + + status(result) mustEqual SEE_OTHER + redirectLocation(result).get mustEqual routes.ReviewGoodsController.onPageLoad().toString + + //Assert than entry was removed + before.goodsEntries.entries.size mustBe 2 + declarationJourneyRepository.findBySessionId(sessionId).futureValue.get.goodsEntries.entries.size mustBe 1 + } + } + + "Redirect to /goods-removed" when { + "a declaration is started and true is submitted and no more goods exist in the journey" in { + givenADeclarationJourneyIsPersisted(startedDeclarationJourney.copy(goodsEntries = GoodsEntries(Seq(completedGoodsEntry)))) + + val request = postRequest.withFormUrlEncodedBody(("value", "true")) + val result = controller.onSubmit(1)(request) + + status(result) mustEqual SEE_OTHER + redirectLocation(result).get mustEqual routes.GoodsRemovedController.onPageLoad().toString + } + } + + "return BAD_REQUEST and errors" when { + "no selection is made" in { + givenADeclarationJourneyIsPersisted(startedDeclarationJourney.copy(goodsEntries = GoodsEntries(Seq(completedGoodsEntry)))) + + val result = controller.onSubmit(1)(postRequest) + + status(result) mustEqual BAD_REQUEST + ensureContent(result, completedGoodsEntry) must include("Select one of the options below") + } + } + } +} diff --git a/test/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/ReviewGoodsControllerSpec.scala b/test/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/ReviewGoodsControllerSpec.scala index dfcf4e95a..6c189f799 100644 --- a/test/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/ReviewGoodsControllerSpec.scala +++ b/test/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/ReviewGoodsControllerSpec.scala @@ -17,19 +17,18 @@ package uk.gov.hmrc.merchandiseinbaggagefrontend.controllers import play.api.test.Helpers._ -import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.ReviewGoodsFormProvider import uk.gov.hmrc.merchandiseinbaggagefrontend.model.core._ import uk.gov.hmrc.merchandiseinbaggagefrontend.model.currencyconversion.Currency import uk.gov.hmrc.merchandiseinbaggagefrontend.views.html.ReviewGoodsView +import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.ReviewGoodsForm.form import scala.concurrent.ExecutionContext.Implicits.global class ReviewGoodsControllerSpec extends DeclarationJourneyControllerSpec { - private val formProvider = new ReviewGoodsFormProvider() - private val form = formProvider() private lazy val view = injector.instanceOf[ReviewGoodsView] - private lazy val controller = new ReviewGoodsController(controllerComponents, actionBuilder, formProvider, declarationJourneyRepository, view) + private lazy val controller = + new ReviewGoodsController(controllerComponents, actionBuilder, declarationJourneyRepository, view) private val goods = GoodsEntry( diff --git a/test/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/SearchGoodsControllerSpec.scala b/test/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/SearchGoodsControllerSpec.scala index 1109b9d9b..3493b1da7 100644 --- a/test/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/SearchGoodsControllerSpec.scala +++ b/test/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/SearchGoodsControllerSpec.scala @@ -18,7 +18,6 @@ package uk.gov.hmrc.merchandiseinbaggagefrontend.controllers import play.api.mvc.Result import play.api.test.Helpers._ -import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.SearchGoodsFormProvider import uk.gov.hmrc.merchandiseinbaggagefrontend.model.core.{CategoryQuantityOfGoods, GoodsEntries, GoodsEntry} import uk.gov.hmrc.merchandiseinbaggagefrontend.views.html.SearchGoodsView @@ -26,12 +25,10 @@ import scala.concurrent.ExecutionContext.Implicits.global import scala.concurrent.Future class SearchGoodsControllerSpec extends DeclarationJourneyControllerSpec { - private val formProvider = new SearchGoodsFormProvider() - private val form = formProvider() private lazy val controller = new SearchGoodsController( - controllerComponents, actionBuilder, formProvider, declarationJourneyRepository, injector.instanceOf[SearchGoodsView]) + controllerComponents, actionBuilder, declarationJourneyRepository, injector.instanceOf[SearchGoodsView]) private def ensureContent(result: Future[Result]) = { val content = contentAsString(result) @@ -105,7 +102,6 @@ class SearchGoodsControllerSpec extends DeclarationJourneyControllerSpec { "return BAD_REQUEST and errors" when { "no selection is made" in { givenADeclarationJourneyIsPersisted(startedDeclarationJourney) - form.bindFromRequest()(postRequest) val result = controller.onSubmit(1)(postRequest) diff --git a/test/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/SearchGoodsCountryControllerSpec.scala b/test/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/SearchGoodsCountryControllerSpec.scala index 7b3669d74..aab650887 100644 --- a/test/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/SearchGoodsCountryControllerSpec.scala +++ b/test/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/SearchGoodsCountryControllerSpec.scala @@ -18,21 +18,17 @@ package uk.gov.hmrc.merchandiseinbaggagefrontend.controllers import play.api.mvc.Result import play.api.test.Helpers._ -import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.SearchGoodsCountryFormProvider import uk.gov.hmrc.merchandiseinbaggagefrontend.model.core.{CategoryQuantityOfGoods, GoodsEntries, GoodsEntry} -import uk.gov.hmrc.merchandiseinbaggagefrontend.service.CountriesService import uk.gov.hmrc.merchandiseinbaggagefrontend.views.html.SearchGoodsCountryView import scala.concurrent.ExecutionContext.Implicits.global import scala.concurrent.Future class SearchGoodsCountryControllerSpec extends DeclarationJourneyControllerSpec { - private val formProvider = new SearchGoodsCountryFormProvider() - private val form = formProvider(CountriesService.countries) private lazy val controller = new SearchGoodsCountryController( - controllerComponents, actionBuilder, formProvider, declarationJourneyRepository, injector.instanceOf[SearchGoodsCountryView]) + controllerComponents, actionBuilder, declarationJourneyRepository, injector.instanceOf[SearchGoodsCountryView]) private def ensureContent(result: Future[Result], goodsEntry: GoodsEntry) = { val content = contentAsString(result) @@ -87,7 +83,6 @@ class SearchGoodsCountryControllerSpec extends DeclarationJourneyControllerSpec "return BAD_REQUEST and errors" when { "no selection is made" in { givenADeclarationJourneyIsPersisted(declarationJourneyWithStartedGoodsEntry) - form.bindFromRequest()(postRequest) val result = controller.onSubmit(1)(postRequest) diff --git a/test/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/SkeletonJourneyControllerSpec.scala b/test/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/SkeletonJourneyControllerSpec.scala index f57598f93..cf4663287 100644 --- a/test/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/SkeletonJourneyControllerSpec.scala +++ b/test/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/SkeletonJourneyControllerSpec.scala @@ -24,46 +24,6 @@ import scala.concurrent.Future class SkeletonJourneyControllerSpec extends DeclarationJourneyControllerSpec { private lazy val controller = app.injector.instanceOf[SkeletonJourneyController] - "removeGoods" should { - val url = routes.SkeletonJourneyController.removeGoods().url - - "render the page" when { - "a declaration journey has been started" in { - val title = "Are you sure you want to remove the x?" - val getRequest = buildGet(url, sessionId) - - givenADeclarationJourneyIsPersisted(startedDeclarationJourney) - ensure(controller.removeGoods(getRequest), title, routes.SkeletonJourneyController.goodsRemoved()) - } - } - - "redirect to /invalid-request" when { - "a declaration journey has not been started" in { - ensureRedirectToInvalidRequestPage(controller.removeGoods(buildGet(url))) - } - } - } - - "goodsRemoved" should { - val url = routes.SkeletonJourneyController.goodsRemoved().url - - "render the page" when { - "a declaration journey has been started" in { - val title = "You removed your goods" - val getRequest = buildGet(url, sessionId) - - givenADeclarationJourneyIsPersisted(startedDeclarationJourney) - ensure(controller.goodsRemoved(getRequest), title, routes.SearchGoodsController.onPageLoad(1)) - } - } - - "redirect to /invalid-request" when { - "a declaration journey has not been started" in { - ensureRedirectToInvalidRequestPage(controller.goodsRemoved(buildGet(url))) - } - } - } - "taxCalculation" should { val url = routes.SkeletonJourneyController.taxCalculation().url diff --git a/test/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/ValueWeightOfGoodsControllerSpec.scala b/test/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/ValueWeightOfGoodsControllerSpec.scala index a4cb86357..15cb54da7 100644 --- a/test/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/ValueWeightOfGoodsControllerSpec.scala +++ b/test/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/ValueWeightOfGoodsControllerSpec.scala @@ -18,7 +18,6 @@ package uk.gov.hmrc.merchandiseinbaggagefrontend.controllers import play.api.mvc.Result import play.api.test.Helpers._ -import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.ValueWeightOfGoodsFormProvider import uk.gov.hmrc.merchandiseinbaggagefrontend.model.core.GoodsDestinations.{GreatBritain, NorthernIreland} import uk.gov.hmrc.merchandiseinbaggagefrontend.views.html.ValueWeightOfGoodsView @@ -26,12 +25,10 @@ import scala.concurrent.ExecutionContext.Implicits.global import scala.concurrent.Future class ValueWeightOfGoodsControllerSpec extends DeclarationJourneyControllerSpec { - private val formProvider = new ValueWeightOfGoodsFormProvider() - private val form = formProvider() private lazy val controller = new ValueWeightOfGoodsController( - controllerComponents, actionBuilder, formProvider, declarationJourneyRepository, injector.instanceOf[ValueWeightOfGoodsView]) + controllerComponents, actionBuilder, declarationJourneyRepository, injector.instanceOf[ValueWeightOfGoodsView]) private def ensureContent(result: Future[Result]) = { val content = contentAsString(result) @@ -129,7 +126,6 @@ class ValueWeightOfGoodsControllerSpec extends DeclarationJourneyControllerSpec "return BAD_REQUEST and errors" when { "no selection is made" in { givenADeclarationJourneyIsPersisted(startedDeclarationJourney.copy(maybeGoodsDestination = Some(NorthernIreland))) - form.bindFromRequest()(postRequest) val result = controller.onSubmit()(postRequest) diff --git a/test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/ExciseAndRestrictedGoodsFormProviderSpec.scala b/test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/ExciseAndRestrictedGoodsFormSpec.scala similarity index 88% rename from test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/ExciseAndRestrictedGoodsFormProviderSpec.scala rename to test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/ExciseAndRestrictedGoodsFormSpec.scala index 911bd485f..43c11474c 100644 --- a/test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/ExciseAndRestrictedGoodsFormProviderSpec.scala +++ b/test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/ExciseAndRestrictedGoodsFormSpec.scala @@ -18,14 +18,13 @@ package uk.gov.hmrc.merchandiseinbaggagefrontend.forms import play.api.data.FormError import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.behaviours.BooleanFieldBehaviours +import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.ExciseAndRestrictedGoodsForm.form -class ExciseAndRestrictedGoodsFormProviderSpec extends BooleanFieldBehaviours { +class ExciseAndRestrictedGoodsFormSpec extends BooleanFieldBehaviours { val requiredKey = "exciseAndRestrictedGoods.error.required" val invalidKey = "error.boolean" - val form = new ExciseAndRestrictedGoodsFormProvider()() - ".value" must { val fieldName = "value" diff --git a/test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/GoodsDestinationFormProviderSpec.scala b/test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/GoodsDestinationFormSpec.scala similarity index 90% rename from test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/GoodsDestinationFormProviderSpec.scala rename to test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/GoodsDestinationFormSpec.scala index 34499dbbb..656616575 100644 --- a/test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/GoodsDestinationFormProviderSpec.scala +++ b/test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/GoodsDestinationFormSpec.scala @@ -17,12 +17,11 @@ package uk.gov.hmrc.merchandiseinbaggagefrontend.forms import play.api.data.FormError +import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.GoodsDestinationForm.form import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.behaviours.OptionFieldBehaviours import uk.gov.hmrc.merchandiseinbaggagefrontend.model.core.{GoodsDestination, GoodsDestinations} -class GoodsDestinationFormProviderSpec extends OptionFieldBehaviours { - - val form = new GoodsDestinationFormProvider()() +class GoodsDestinationFormSpec extends OptionFieldBehaviours { ".value" must { diff --git a/test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/GoodsVatRateFormProviderSpec.scala b/test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/GoodsVatRateFormSpec.scala similarity index 90% rename from test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/GoodsVatRateFormProviderSpec.scala rename to test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/GoodsVatRateFormSpec.scala index 5a84807a9..bddc47d22 100644 --- a/test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/GoodsVatRateFormProviderSpec.scala +++ b/test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/GoodsVatRateFormSpec.scala @@ -17,12 +17,11 @@ package uk.gov.hmrc.merchandiseinbaggagefrontend.forms import play.api.data.FormError +import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.GoodsVatRateForm.form import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.behaviours.OptionFieldBehaviours import uk.gov.hmrc.merchandiseinbaggagefrontend.model.core.{GoodsVatRate, GoodsVatRates} -class GoodsVatRateFormProviderSpec extends OptionFieldBehaviours { - - val form = new GoodsVatRateFormProvider()() +class GoodsVatRateFormSpec extends OptionFieldBehaviours { ".value" must { diff --git a/test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/RemoveGoodsFormSpec.scala b/test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/RemoveGoodsFormSpec.scala new file mode 100644 index 000000000..8c3ed9466 --- /dev/null +++ b/test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/RemoveGoodsFormSpec.scala @@ -0,0 +1,44 @@ +/* + * Copyright 2020 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 uk.gov.hmrc.merchandiseinbaggagefrontend.forms + +import play.api.data.FormError +import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.RemoveGoodsForm.form +import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.behaviours.BooleanFieldBehaviours + +class RemoveGoodsFormSpec extends BooleanFieldBehaviours { + + val requiredKey = "removeGoods.error.required" + val invalidKey = "error.boolean" + + ".value" must { + + val fieldName = "value" + + behave like booleanField( + form, + fieldName, + invalidError = FormError(fieldName, invalidKey) + ) + + behave like mandatoryField( + form, + fieldName, + requiredError = FormError(fieldName, requiredKey) + ) + } +} diff --git a/test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/ReviewGoodsFormProviderSpec.scala b/test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/ReviewGoodsFormSpec.scala similarity index 89% rename from test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/ReviewGoodsFormProviderSpec.scala rename to test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/ReviewGoodsFormSpec.scala index 201eaa22a..c1a202501 100644 --- a/test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/ReviewGoodsFormProviderSpec.scala +++ b/test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/ReviewGoodsFormSpec.scala @@ -18,14 +18,13 @@ package uk.gov.hmrc.merchandiseinbaggagefrontend.forms import play.api.data.FormError import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.behaviours.BooleanFieldBehaviours +import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.ReviewGoodsForm.form -class ReviewGoodsFormProviderSpec extends BooleanFieldBehaviours { +class ReviewGoodsFormSpec extends BooleanFieldBehaviours { val requiredKey = "reviewGoods.error.required" val invalidKey = "error.boolean" - val form = new ReviewGoodsFormProvider()() - ".value" must { val fieldName = "value" diff --git a/test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/SearchGoodsCountryFormProviderSpec.scala b/test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/SearchGoodsCountryFormSpec.scala similarity index 87% rename from test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/SearchGoodsCountryFormProviderSpec.scala rename to test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/SearchGoodsCountryFormSpec.scala index 508bfb662..c69e5c098 100644 --- a/test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/SearchGoodsCountryFormProviderSpec.scala +++ b/test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/SearchGoodsCountryFormSpec.scala @@ -22,11 +22,11 @@ import uk.gov.hmrc.merchandiseinbaggagefrontend.config.AppConfig import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.behaviours.FieldBehaviours import uk.gov.hmrc.merchandiseinbaggagefrontend.service.CountriesService -class SearchGoodsCountryFormProviderSpec extends BaseSpecWithApplication with FieldBehaviours { +class SearchGoodsCountryFormSpec extends BaseSpecWithApplication with FieldBehaviours { val appConfig = injector.instanceOf[AppConfig] - val form = new SearchGoodsCountryFormProvider()(CountriesService.countries) + val form = SearchGoodsCountryForm.form(CountriesService.countries) ".value" must { diff --git a/test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/SearchGoodsFormProviderSpec.scala b/test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/SearchGoodsFormSpec.scala similarity index 90% rename from test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/SearchGoodsFormProviderSpec.scala rename to test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/SearchGoodsFormSpec.scala index 3d5d36741..6ea9794cf 100644 --- a/test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/SearchGoodsFormProviderSpec.scala +++ b/test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/SearchGoodsFormSpec.scala @@ -18,10 +18,9 @@ package uk.gov.hmrc.merchandiseinbaggagefrontend.forms import play.api.data.FormError import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.behaviours.FieldBehaviours +import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.SearchGoodsForm.form -class SearchGoodsFormProviderSpec extends FieldBehaviours { - - val form = new SearchGoodsFormProvider()() +class SearchGoodsFormSpec extends FieldBehaviours { ".category" must { diff --git a/test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/ValueWeightOfGoodsFormProviderSpec.scala b/test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/ValueWeightOfGoodsFormSpec.scala similarity index 88% rename from test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/ValueWeightOfGoodsFormProviderSpec.scala rename to test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/ValueWeightOfGoodsFormSpec.scala index 51de9dda9..5e4eee198 100644 --- a/test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/ValueWeightOfGoodsFormProviderSpec.scala +++ b/test/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/ValueWeightOfGoodsFormSpec.scala @@ -17,15 +17,14 @@ package uk.gov.hmrc.merchandiseinbaggagefrontend.forms import play.api.data.FormError +import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.ValueWeightOfGoodsForm.form import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.behaviours.BooleanFieldBehaviours -class ValueWeightOfGoodsFormProviderSpec extends BooleanFieldBehaviours { +class ValueWeightOfGoodsFormSpec extends BooleanFieldBehaviours { val requiredKey = "valueWeightOfGoods.error.required" val invalidKey = "error.boolean" - val form = new ValueWeightOfGoodsFormProvider()() - ".value" must { val fieldName = "value"