diff --git a/app/controllers/Category1AssesmentsController.scala b/app/controllers/Category1AssesmentsController.scala new file mode 100644 index 000000000..910fb566e --- /dev/null +++ b/app/controllers/Category1AssesmentsController.scala @@ -0,0 +1,72 @@ +/* + * Copyright 2024 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package controllers + +import controllers.actions._ +import forms.Category1AssesmentsFormProvider +import javax.inject.Inject +import models.Mode +import navigation.Navigator +import pages.Category1AssesmentsPage +import play.api.i18n.{I18nSupport, MessagesApi} +import play.api.mvc.{Action, AnyContent, MessagesControllerComponents} +import repositories.SessionRepository +import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController +import views.html.Category1AssesmentsView + +import scala.concurrent.{ExecutionContext, Future} + +class Category1AssesmentsController @Inject()( + override val messagesApi: MessagesApi, + sessionRepository: SessionRepository, + navigator: Navigator, + identify: IdentifierAction, + getData: DataRetrievalAction, + requireData: DataRequiredAction, + formProvider: Category1AssesmentsFormProvider, + val controllerComponents: MessagesControllerComponents, + view: Category1AssesmentsView + )(implicit ec: ExecutionContext) extends FrontendBaseController with I18nSupport { + + private val form = formProvider() + + def onPageLoad(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData) { + implicit request => + + val preparedForm = request.userAnswers.get(Category1AssesmentsPage) match { + case None => form + case Some(value) => form.fill(value) + } + + Ok(view(preparedForm, mode)) + } + + def onSubmit(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData).async { + implicit request => + + form.bindFromRequest().fold( + formWithErrors => + Future.successful(BadRequest(view(formWithErrors, mode))), + + value => + for { + updatedAnswers <- Future.fromTry(request.userAnswers.set(Category1AssesmentsPage, value)) + _ <- sessionRepository.set(updatedAnswers) + } yield Redirect(navigator.nextPage(Category1AssesmentsPage, mode, updatedAnswers)) + ) + } +} diff --git a/app/controllers/CreateRecordStartController.scala b/app/controllers/CreateRecordStartController.scala new file mode 100644 index 000000000..26f6585e0 --- /dev/null +++ b/app/controllers/CreateRecordStartController.scala @@ -0,0 +1,39 @@ +/* + * Copyright 2024 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package controllers + +import controllers.actions._ +import javax.inject.Inject +import play.api.i18n.{I18nSupport, MessagesApi} +import play.api.mvc.{Action, AnyContent, MessagesControllerComponents} +import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController +import views.html.CreateRecordStartView + +class CreateRecordStartController @Inject()( + override val messagesApi: MessagesApi, + identify: IdentifierAction, + getData: DataRetrievalAction, + requireData: DataRequiredAction, + val controllerComponents: MessagesControllerComponents, + view: CreateRecordStartView + ) extends FrontendBaseController with I18nSupport { + + def onPageLoad: Action[AnyContent] = (identify andThen getData andThen requireData) { + implicit request => + Ok(view()) + } +} diff --git a/app/controllers/CreateRecordSuccessController.scala b/app/controllers/CreateRecordSuccessController.scala new file mode 100644 index 000000000..982bde710 --- /dev/null +++ b/app/controllers/CreateRecordSuccessController.scala @@ -0,0 +1,39 @@ +/* + * Copyright 2024 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package controllers + +import controllers.actions._ +import javax.inject.Inject +import play.api.i18n.{I18nSupport, MessagesApi} +import play.api.mvc.{Action, AnyContent, MessagesControllerComponents} +import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController +import views.html.CreateRecordSuccessView + +class CreateRecordSuccessController @Inject()( + override val messagesApi: MessagesApi, + identify: IdentifierAction, + getData: DataRetrievalAction, + requireData: DataRequiredAction, + val controllerComponents: MessagesControllerComponents, + view: CreateRecordSuccessView + ) extends FrontendBaseController with I18nSupport { + + def onPageLoad: Action[AnyContent] = (identify andThen getData andThen requireData) { + implicit request => + Ok(view()) + } +} diff --git a/app/controllers/GoodsDescriptionController.scala b/app/controllers/GoodsDescriptionController.scala new file mode 100644 index 000000000..d4722d3ab --- /dev/null +++ b/app/controllers/GoodsDescriptionController.scala @@ -0,0 +1,72 @@ +/* + * Copyright 2024 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package controllers + +import controllers.actions._ +import forms.GoodsDescriptionFormProvider +import javax.inject.Inject +import models.Mode +import navigation.Navigator +import pages.GoodsDescriptionPage +import play.api.i18n.{I18nSupport, MessagesApi} +import play.api.mvc.{Action, AnyContent, MessagesControllerComponents} +import repositories.SessionRepository +import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController +import views.html.GoodsDescriptionView + +import scala.concurrent.{ExecutionContext, Future} + +class GoodsDescriptionController @Inject()( + override val messagesApi: MessagesApi, + sessionRepository: SessionRepository, + navigator: Navigator, + identify: IdentifierAction, + getData: DataRetrievalAction, + requireData: DataRequiredAction, + formProvider: GoodsDescriptionFormProvider, + val controllerComponents: MessagesControllerComponents, + view: GoodsDescriptionView + )(implicit ec: ExecutionContext) extends FrontendBaseController with I18nSupport { + + private val form = formProvider() + + def onPageLoad(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData) { + implicit request => + + val preparedForm = request.userAnswers.get(GoodsDescriptionPage) match { + case None => form + case Some(value) => form.fill(value) + } + + Ok(view(preparedForm, mode)) + } + + def onSubmit(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData).async { + implicit request => + + form.bindFromRequest().fold( + formWithErrors => + Future.successful(BadRequest(view(formWithErrors, mode))), + + value => + for { + updatedAnswers <- Future.fromTry(request.userAnswers.set(GoodsDescriptionPage, value)) + _ <- sessionRepository.set(updatedAnswers) + } yield Redirect(navigator.nextPage(GoodsDescriptionPage, mode, updatedAnswers)) + ) + } +} diff --git a/app/controllers/HasCorrectGoodsController.scala b/app/controllers/HasCorrectGoodsController.scala new file mode 100644 index 000000000..0dcefd7bd --- /dev/null +++ b/app/controllers/HasCorrectGoodsController.scala @@ -0,0 +1,72 @@ +/* + * Copyright 2024 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package controllers + +import controllers.actions._ +import forms.HasCorrectGoodsFormProvider +import javax.inject.Inject +import models.Mode +import navigation.Navigator +import pages.HasCorrectGoodsPage +import play.api.i18n.{I18nSupport, MessagesApi} +import play.api.mvc.{Action, AnyContent, MessagesControllerComponents} +import repositories.SessionRepository +import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController +import views.html.HasCorrectGoodsView + +import scala.concurrent.{ExecutionContext, Future} + +class HasCorrectGoodsController @Inject()( + override val messagesApi: MessagesApi, + sessionRepository: SessionRepository, + navigator: Navigator, + identify: IdentifierAction, + getData: DataRetrievalAction, + requireData: DataRequiredAction, + formProvider: HasCorrectGoodsFormProvider, + val controllerComponents: MessagesControllerComponents, + view: HasCorrectGoodsView + )(implicit ec: ExecutionContext) extends FrontendBaseController with I18nSupport { + + private val form = formProvider() + + def onPageLoad(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData) { + implicit request => + + val preparedForm = request.userAnswers.get(HasCorrectGoodsPage) match { + case None => form + case Some(value) => form.fill(value) + } + + Ok(view(preparedForm, mode)) + } + + def onSubmit(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData).async { + implicit request => + + form.bindFromRequest().fold( + formWithErrors => + Future.successful(BadRequest(view(formWithErrors, mode))), + + value => + for { + updatedAnswers <- Future.fromTry(request.userAnswers.set(HasCorrectGoodsPage, value)) + _ <- sessionRepository.set(updatedAnswers) + } yield Redirect(navigator.nextPage(HasCorrectGoodsPage, mode, updatedAnswers)) + ) + } +} diff --git a/app/controllers/HasGoodsDescriptionController.scala b/app/controllers/HasGoodsDescriptionController.scala new file mode 100644 index 000000000..37c1cc6f0 --- /dev/null +++ b/app/controllers/HasGoodsDescriptionController.scala @@ -0,0 +1,72 @@ +/* + * Copyright 2024 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package controllers + +import controllers.actions._ +import forms.HasGoodsDescriptionFormProvider +import javax.inject.Inject +import models.Mode +import navigation.Navigator +import pages.HasGoodsDescriptionPage +import play.api.i18n.{I18nSupport, MessagesApi} +import play.api.mvc.{Action, AnyContent, MessagesControllerComponents} +import repositories.SessionRepository +import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController +import views.html.HasGoodsDescriptionView + +import scala.concurrent.{ExecutionContext, Future} + +class HasGoodsDescriptionController @Inject()( + override val messagesApi: MessagesApi, + sessionRepository: SessionRepository, + navigator: Navigator, + identify: IdentifierAction, + getData: DataRetrievalAction, + requireData: DataRequiredAction, + formProvider: HasGoodsDescriptionFormProvider, + val controllerComponents: MessagesControllerComponents, + view: HasGoodsDescriptionView + )(implicit ec: ExecutionContext) extends FrontendBaseController with I18nSupport { + + private val form = formProvider() + + def onPageLoad(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData) { + implicit request => + + val preparedForm = request.userAnswers.get(HasGoodsDescriptionPage) match { + case None => form + case Some(value) => form.fill(value) + } + + Ok(view(preparedForm, mode)) + } + + def onSubmit(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData).async { + implicit request => + + form.bindFromRequest().fold( + formWithErrors => + Future.successful(BadRequest(view(formWithErrors, mode))), + + value => + for { + updatedAnswers <- Future.fromTry(request.userAnswers.set(HasGoodsDescriptionPage, value)) + _ <- sessionRepository.set(updatedAnswers) + } yield Redirect(navigator.nextPage(HasGoodsDescriptionPage, mode, updatedAnswers)) + ) + } +} diff --git a/app/forms/Category1AssesmentsFormProvider.scala b/app/forms/Category1AssesmentsFormProvider.scala new file mode 100644 index 000000000..741e0a97d --- /dev/null +++ b/app/forms/Category1AssesmentsFormProvider.scala @@ -0,0 +1,31 @@ +/* + * Copyright 2024 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package forms + +import javax.inject.Inject + +import forms.mappings.Mappings +import play.api.data.Form +import models.Category1Assesments + +class Category1AssesmentsFormProvider @Inject() extends Mappings { + + def apply(): Form[Category1Assesments] = + Form( + "value" -> enumerable[Category1Assesments]("category1Assesments.error.required") + ) +} diff --git a/app/forms/GoodsDescriptionFormProvider.scala b/app/forms/GoodsDescriptionFormProvider.scala new file mode 100644 index 000000000..dcfc1e081 --- /dev/null +++ b/app/forms/GoodsDescriptionFormProvider.scala @@ -0,0 +1,31 @@ +/* + * Copyright 2024 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package forms + +import javax.inject.Inject + +import forms.mappings.Mappings +import play.api.data.Form + +class GoodsDescriptionFormProvider @Inject() extends Mappings { + + def apply(): Form[String] = + Form( + "value" -> text("goodsDescription.error.required") + .verifying(maxLength(512, "goodsDescription.error.length")) + ) +} diff --git a/app/forms/HasCorrectGoodsFormProvider.scala b/app/forms/HasCorrectGoodsFormProvider.scala new file mode 100644 index 000000000..3ba6a373a --- /dev/null +++ b/app/forms/HasCorrectGoodsFormProvider.scala @@ -0,0 +1,30 @@ +/* + * Copyright 2024 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package forms + +import javax.inject.Inject + +import forms.mappings.Mappings +import play.api.data.Form + +class HasCorrectGoodsFormProvider @Inject() extends Mappings { + + def apply(): Form[Boolean] = + Form( + "value" -> boolean("hasCorrectGoods.error.required") + ) +} diff --git a/app/forms/HasGoodsDescriptionFormProvider.scala b/app/forms/HasGoodsDescriptionFormProvider.scala new file mode 100644 index 000000000..bbc535707 --- /dev/null +++ b/app/forms/HasGoodsDescriptionFormProvider.scala @@ -0,0 +1,30 @@ +/* + * Copyright 2024 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package forms + +import javax.inject.Inject + +import forms.mappings.Mappings +import play.api.data.Form + +class HasGoodsDescriptionFormProvider @Inject() extends Mappings { + + def apply(): Form[Boolean] = + Form( + "value" -> boolean("hasGoodsDescription.error.required") + ) +} diff --git a/app/models/Category1Assesments.scala b/app/models/Category1Assesments.scala new file mode 100644 index 000000000..83c33bdf2 --- /dev/null +++ b/app/models/Category1Assesments.scala @@ -0,0 +1,45 @@ +/* + * Copyright 2024 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package models + +import play.api.i18n.Messages +import uk.gov.hmrc.govukfrontend.views.Aliases.Text +import uk.gov.hmrc.govukfrontend.views.viewmodels.radios.RadioItem + +sealed trait Category1Assesments + +object Category1Assesments extends Enumerable.Implicits { + + case object Option1 extends WithName("option1") with Category1Assesments + case object Option2 extends WithName("option2") with Category1Assesments + + val values: Seq[Category1Assesments] = Seq( + Option1, Option2 + ) + + def options(implicit messages: Messages): Seq[RadioItem] = values.zipWithIndex.map { + case (value, index) => + RadioItem( + content = Text(messages(s"category1Assesments.${value.toString}")), + value = Some(value.toString), + id = Some(s"value_$index") + ) + } + + implicit val enumerable: Enumerable[Category1Assesments] = + Enumerable(values.map(v => v.toString -> v): _*) +} diff --git a/app/pages/Category1AssesmentsPage.scala b/app/pages/Category1AssesmentsPage.scala new file mode 100644 index 000000000..ff100e222 --- /dev/null +++ b/app/pages/Category1AssesmentsPage.scala @@ -0,0 +1,27 @@ +/* + * Copyright 2024 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package pages + +import models.Category1Assesments +import play.api.libs.json.JsPath + +case object Category1AssesmentsPage extends QuestionPage[Category1Assesments] { + + override def path: JsPath = JsPath \ toString + + override def toString: String = "category1Assesments" +} diff --git a/app/pages/GoodsDescriptionPage.scala b/app/pages/GoodsDescriptionPage.scala new file mode 100644 index 000000000..572e7f586 --- /dev/null +++ b/app/pages/GoodsDescriptionPage.scala @@ -0,0 +1,26 @@ +/* + * Copyright 2024 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package pages + +import play.api.libs.json.JsPath + +case object GoodsDescriptionPage extends QuestionPage[String] { + + override def path: JsPath = JsPath \ toString + + override def toString: String = "goodsDescription" +} diff --git a/app/pages/HasCorrectGoodsPage.scala b/app/pages/HasCorrectGoodsPage.scala new file mode 100644 index 000000000..8310de0e1 --- /dev/null +++ b/app/pages/HasCorrectGoodsPage.scala @@ -0,0 +1,26 @@ +/* + * Copyright 2024 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package pages + +import play.api.libs.json.JsPath + +case object HasCorrectGoodsPage extends QuestionPage[Boolean] { + + override def path: JsPath = JsPath \ toString + + override def toString: String = "hasCorrectGoods" +} diff --git a/app/pages/HasGoodsDescriptionPage.scala b/app/pages/HasGoodsDescriptionPage.scala new file mode 100644 index 000000000..1182e54e7 --- /dev/null +++ b/app/pages/HasGoodsDescriptionPage.scala @@ -0,0 +1,26 @@ +/* + * Copyright 2024 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package pages + +import play.api.libs.json.JsPath + +case object HasGoodsDescriptionPage extends QuestionPage[Boolean] { + + override def path: JsPath = JsPath \ toString + + override def toString: String = "hasGoodsDescription" +} diff --git a/app/viewmodels/checkAnswers/Category1AssesmentsSummary.scala b/app/viewmodels/checkAnswers/Category1AssesmentsSummary.scala new file mode 100644 index 000000000..78e48ed14 --- /dev/null +++ b/app/viewmodels/checkAnswers/Category1AssesmentsSummary.scala @@ -0,0 +1,50 @@ +/* + * Copyright 2024 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package viewmodels.checkAnswers + +import controllers.routes +import models.{CheckMode, UserAnswers} +import pages.Category1AssesmentsPage +import play.api.i18n.Messages +import play.twirl.api.HtmlFormat +import uk.gov.hmrc.govukfrontend.views.viewmodels.content.HtmlContent +import uk.gov.hmrc.govukfrontend.views.viewmodels.summarylist.SummaryListRow +import viewmodels.govuk.summarylist._ +import viewmodels.implicits._ + +object Category1AssesmentsSummary { + + def row(answers: UserAnswers)(implicit messages: Messages): Option[SummaryListRow] = + answers.get(Category1AssesmentsPage).map { + answer => + + val value = ValueViewModel( + HtmlContent( + HtmlFormat.escape(messages(s"category1Assesments.$answer")) + ) + ) + + SummaryListRowViewModel( + key = "category1Assesments.checkYourAnswersLabel", + value = value, + actions = Seq( + ActionItemViewModel("site.change", routes.Category1AssesmentsController.onPageLoad(CheckMode).url) + .withVisuallyHiddenText(messages("category1Assesments.change.hidden")) + ) + ) + } +} diff --git a/app/viewmodels/checkAnswers/GoodsDescriptionSummary.scala b/app/viewmodels/checkAnswers/GoodsDescriptionSummary.scala new file mode 100644 index 000000000..9ef0725ed --- /dev/null +++ b/app/viewmodels/checkAnswers/GoodsDescriptionSummary.scala @@ -0,0 +1,43 @@ +/* + * Copyright 2024 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package viewmodels.checkAnswers + +import controllers.routes +import models.{CheckMode, UserAnswers} +import pages.GoodsDescriptionPage +import play.api.i18n.Messages +import play.twirl.api.HtmlFormat +import uk.gov.hmrc.govukfrontend.views.viewmodels.summarylist.SummaryListRow +import viewmodels.govuk.summarylist._ +import viewmodels.implicits._ + +object GoodsDescriptionSummary { + + def row(answers: UserAnswers)(implicit messages: Messages): Option[SummaryListRow] = + answers.get(GoodsDescriptionPage).map { + answer => + + SummaryListRowViewModel( + key = "goodsDescription.checkYourAnswersLabel", + value = ValueViewModel(HtmlFormat.escape(answer).toString), + actions = Seq( + ActionItemViewModel("site.change", routes.GoodsDescriptionController.onPageLoad(CheckMode).url) + .withVisuallyHiddenText(messages("goodsDescription.change.hidden")) + ) + ) + } +} diff --git a/app/viewmodels/checkAnswers/HasCorrectGoodsSummary.scala b/app/viewmodels/checkAnswers/HasCorrectGoodsSummary.scala new file mode 100644 index 000000000..ae29fc5cf --- /dev/null +++ b/app/viewmodels/checkAnswers/HasCorrectGoodsSummary.scala @@ -0,0 +1,44 @@ +/* + * Copyright 2024 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package viewmodels.checkAnswers + +import controllers.routes +import models.{CheckMode, UserAnswers} +import pages.HasCorrectGoodsPage +import play.api.i18n.Messages +import uk.gov.hmrc.govukfrontend.views.viewmodels.summarylist.SummaryListRow +import viewmodels.govuk.summarylist._ +import viewmodels.implicits._ + +object HasCorrectGoodsSummary { + + def row(answers: UserAnswers)(implicit messages: Messages): Option[SummaryListRow] = + answers.get(HasCorrectGoodsPage).map { + answer => + + val value = if (answer) "site.yes" else "site.no" + + SummaryListRowViewModel( + key = "hasCorrectGoods.checkYourAnswersLabel", + value = ValueViewModel(value), + actions = Seq( + ActionItemViewModel("site.change", routes.HasCorrectGoodsController.onPageLoad(CheckMode).url) + .withVisuallyHiddenText(messages("hasCorrectGoods.change.hidden")) + ) + ) + } +} diff --git a/app/viewmodels/checkAnswers/HasGoodsDescriptionSummary.scala b/app/viewmodels/checkAnswers/HasGoodsDescriptionSummary.scala new file mode 100644 index 000000000..f267bb583 --- /dev/null +++ b/app/viewmodels/checkAnswers/HasGoodsDescriptionSummary.scala @@ -0,0 +1,44 @@ +/* + * Copyright 2024 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package viewmodels.checkAnswers + +import controllers.routes +import models.{CheckMode, UserAnswers} +import pages.HasGoodsDescriptionPage +import play.api.i18n.Messages +import uk.gov.hmrc.govukfrontend.views.viewmodels.summarylist.SummaryListRow +import viewmodels.govuk.summarylist._ +import viewmodels.implicits._ + +object HasGoodsDescriptionSummary { + + def row(answers: UserAnswers)(implicit messages: Messages): Option[SummaryListRow] = + answers.get(HasGoodsDescriptionPage).map { + answer => + + val value = if (answer) "site.yes" else "site.no" + + SummaryListRowViewModel( + key = "hasGoodsDescription.checkYourAnswersLabel", + value = ValueViewModel(value), + actions = Seq( + ActionItemViewModel("site.change", routes.HasGoodsDescriptionController.onPageLoad(CheckMode).url) + .withVisuallyHiddenText(messages("hasGoodsDescription.change.hidden")) + ) + ) + } +} diff --git a/app/views/Category1AssesmentsView.scala.html b/app/views/Category1AssesmentsView.scala.html new file mode 100644 index 000000000..3c9e5296d --- /dev/null +++ b/app/views/Category1AssesmentsView.scala.html @@ -0,0 +1,47 @@ +@* + * Copyright 2024 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *@ + +@this( + layout: templates.Layout, + formHelper: FormWithCSRF, + govukErrorSummary: GovukErrorSummary, + govukRadios: GovukRadios, + govukButton: GovukButton +) + +@(form: Form[_], mode: Mode)(implicit request: Request[_], messages: Messages) + +@layout(pageTitle = title(form, messages("category1Assesments.title"))) { + + @formHelper(action = routes.Category1AssesmentsController.onSubmit(mode), 'autoComplete -> "off") { + + @if(form.errors.nonEmpty) { + @govukErrorSummary(ErrorSummaryViewModel(form, errorLinkOverrides = Map("value" -> "value_0"))) + } + + @govukRadios( + RadiosViewModel( + field = form("value"), + legend = LegendViewModel(messages("category1Assesments.heading")).asPageHeading(), + items = Category1Assesments.options + ) + ) + + @govukButton( + ButtonViewModel(messages("site.continue")) + ) + } +} diff --git a/app/views/CreateRecordStartView.scala.html b/app/views/CreateRecordStartView.scala.html new file mode 100644 index 000000000..10db26bf0 --- /dev/null +++ b/app/views/CreateRecordStartView.scala.html @@ -0,0 +1,27 @@ +@* + * Copyright 2024 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *@ + +@this( + layout: templates.Layout, + govukButton: GovukButton +) + +@()(implicit request: Request[_], messages: Messages) + +@layout(pageTitle = titleNoForm(messages("createRecordStart.title"))) { + +

@messages("createRecordStart.heading")

+} diff --git a/app/views/CreateRecordSuccessView.scala.html b/app/views/CreateRecordSuccessView.scala.html new file mode 100644 index 000000000..f59e93c7a --- /dev/null +++ b/app/views/CreateRecordSuccessView.scala.html @@ -0,0 +1,27 @@ +@* + * Copyright 2024 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *@ + +@this( + layout: templates.Layout, + govukButton: GovukButton +) + +@()(implicit request: Request[_], messages: Messages) + +@layout(pageTitle = titleNoForm(messages("createRecordSuccess.title"))) { + +

@messages("createRecordSuccess.heading")

+} diff --git a/app/views/GoodsDescriptionView.scala.html b/app/views/GoodsDescriptionView.scala.html new file mode 100644 index 000000000..7713c8800 --- /dev/null +++ b/app/views/GoodsDescriptionView.scala.html @@ -0,0 +1,49 @@ +@* + * Copyright 2024 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *@ + +@import viewmodels.InputWidth._ + +@this( + layout: templates.Layout, + formHelper: FormWithCSRF, + govukErrorSummary: GovukErrorSummary, + govukInput: GovukInput, + govukButton: GovukButton +) + +@(form: Form[_], mode: Mode)(implicit request: Request[_], messages: Messages) + +@layout(pageTitle = title(form, messages("goodsDescription.title"))) { + + @formHelper(action = routes.GoodsDescriptionController.onSubmit(mode)) { + + @if(form.errors.nonEmpty) { + @govukErrorSummary(ErrorSummaryViewModel(form)) + } + + @govukInput( + InputViewModel( + field = form("value"), + label = LabelViewModel(messages("goodsDescription.heading")).asPageHeading() + ) + .withWidth(Full) + ) + + @govukButton( + ButtonViewModel(messages("site.continue")) + ) + } +} diff --git a/app/views/HasCorrectGoodsView.scala.html b/app/views/HasCorrectGoodsView.scala.html new file mode 100644 index 000000000..81b70a718 --- /dev/null +++ b/app/views/HasCorrectGoodsView.scala.html @@ -0,0 +1,46 @@ +@* + * Copyright 2024 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *@ + +@this( + layout: templates.Layout, + formHelper: FormWithCSRF, + govukErrorSummary: GovukErrorSummary, + govukRadios: GovukRadios, + govukButton: GovukButton +) + +@(form: Form[_], mode: Mode)(implicit request: Request[_], messages: Messages) + +@layout(pageTitle = title(form, messages("hasCorrectGoods.title"))) { + + @formHelper(action = routes.HasCorrectGoodsController.onSubmit(mode), Symbol("autoComplete") -> "off") { + + @if(form.errors.nonEmpty) { + @govukErrorSummary(ErrorSummaryViewModel(form)) + } + + @govukRadios( + RadiosViewModel.yesNo( + field = form("value"), + legend = LegendViewModel(messages("hasCorrectGoods.heading")).asPageHeading() + ) + ) + + @govukButton( + ButtonViewModel(messages("site.continue")) + ) + } +} diff --git a/app/views/HasGoodsDescriptionView.scala.html b/app/views/HasGoodsDescriptionView.scala.html new file mode 100644 index 000000000..6dd011842 --- /dev/null +++ b/app/views/HasGoodsDescriptionView.scala.html @@ -0,0 +1,46 @@ +@* + * Copyright 2024 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *@ + +@this( + layout: templates.Layout, + formHelper: FormWithCSRF, + govukErrorSummary: GovukErrorSummary, + govukRadios: GovukRadios, + govukButton: GovukButton +) + +@(form: Form[_], mode: Mode)(implicit request: Request[_], messages: Messages) + +@layout(pageTitle = title(form, messages("hasGoodsDescription.title"))) { + + @formHelper(action = routes.HasGoodsDescriptionController.onSubmit(mode), Symbol("autoComplete") -> "off") { + + @if(form.errors.nonEmpty) { + @govukErrorSummary(ErrorSummaryViewModel(form)) + } + + @govukRadios( + RadiosViewModel.yesNo( + field = form("value"), + legend = LegendViewModel(messages("hasGoodsDescription.heading")).asPageHeading() + ) + ) + + @govukButton( + ButtonViewModel(messages("site.continue")) + ) + } +} diff --git a/conf/app.routes b/conf/app.routes index f4ea43e6c..bc848e4d5 100644 --- a/conf/app.routes +++ b/conf/app.routes @@ -63,3 +63,27 @@ GET /country-of-origin/check controllers.CountryOfOr POST /country-of-origin/check controllers.CountryOfOriginController.onSubmit(mode: Mode = CheckMode) GET /homePage controllers.HomePageController.onPageLoad() + +GET /category1Assesments controllers.Category1AssesmentsController.onPageLoad(mode: Mode = NormalMode) +POST /category1Assesments controllers.Category1AssesmentsController.onSubmit(mode: Mode = NormalMode) +GET /changeCategory1Assesments controllers.Category1AssesmentsController.onPageLoad(mode: Mode = CheckMode) +POST /changeCategory1Assesments controllers.Category1AssesmentsController.onSubmit(mode: Mode = CheckMode) + +GET /createRecordStart controllers.CreateRecordStartController.onPageLoad() + +GET /createRecordSuccess controllers.CreateRecordSuccessController.onPageLoad() + +GET /goodsDescription controllers.GoodsDescriptionController.onPageLoad(mode: Mode = NormalMode) +POST /goodsDescription controllers.GoodsDescriptionController.onSubmit(mode: Mode = NormalMode) +GET /changeGoodsDescription controllers.GoodsDescriptionController.onPageLoad(mode: Mode = CheckMode) +POST /changeGoodsDescription controllers.GoodsDescriptionController.onSubmit(mode: Mode = CheckMode) + +GET /hasCorrectGoods controllers.HasCorrectGoodsController.onPageLoad(mode: Mode = NormalMode) +POST /hasCorrectGoods controllers.HasCorrectGoodsController.onSubmit(mode: Mode = NormalMode) +GET /changeHasCorrectGoods controllers.HasCorrectGoodsController.onPageLoad(mode: Mode = CheckMode) +POST /changeHasCorrectGoods controllers.HasCorrectGoodsController.onSubmit(mode: Mode = CheckMode) + +GET /hasGoodsDescription controllers.HasGoodsDescriptionController.onPageLoad(mode: Mode = NormalMode) +POST /hasGoodsDescription controllers.HasGoodsDescriptionController.onSubmit(mode: Mode = NormalMode) +GET /changeHasGoodsDescription controllers.HasGoodsDescriptionController.onPageLoad(mode: Mode = CheckMode) +POST /changeHasGoodsDescription controllers.HasGoodsDescriptionController.onSubmit(mode: Mode = CheckMode) diff --git a/conf/messages.en b/conf/messages.en index 7a3eaa688..a4e89ca93 100644 --- a/conf/messages.en +++ b/conf/messages.en @@ -156,3 +156,36 @@ countryOfOrigin.error.required = Enter the country of origin homePage.title = homePage homePage.heading = homePage + +category1Assesments.title = category1Assesments +category1Assesments.heading = category1Assesments +category1Assesments.option1 = Option 1 +category1Assesments.option2 = Option 2 +category1Assesments.checkYourAnswersLabel = category1Assesments +category1Assesments.error.required = Select category1Assesments +category1Assesments.change.hidden = Category1Assesments + +createRecordStart.title = createRecordStart +createRecordStart.heading = createRecordStart + +createRecordSuccess.title = createRecordSuccess +createRecordSuccess.heading = createRecordSuccess + +goodsDescription.title = goodsDescription +goodsDescription.heading = goodsDescription +goodsDescription.checkYourAnswersLabel = goodsDescription +goodsDescription.error.required = Enter goodsDescription +goodsDescription.error.length = GoodsDescription must be 512 characters or less +goodsDescription.change.hidden = GoodsDescription + +hasCorrectGoods.title = hasCorrectGoods +hasCorrectGoods.heading = hasCorrectGoods +hasCorrectGoods.checkYourAnswersLabel = hasCorrectGoods +hasCorrectGoods.error.required = Select yes if hasCorrectGoods +hasCorrectGoods.change.hidden = HasCorrectGoods + +hasGoodsDescription.title = hasGoodsDescription +hasGoodsDescription.heading = hasGoodsDescription +hasGoodsDescription.checkYourAnswersLabel = hasGoodsDescription +hasGoodsDescription.error.required = Select yes if hasGoodsDescription +hasGoodsDescription.change.hidden = HasGoodsDescription diff --git a/test-utils/generators/ModelGenerators.scala b/test-utils/generators/ModelGenerators.scala index 28bab5722..76f448edd 100644 --- a/test-utils/generators/ModelGenerators.scala +++ b/test-utils/generators/ModelGenerators.scala @@ -17,8 +17,12 @@ package generators import models._ -import org.scalacheck.Arbitrary.arbitrary import org.scalacheck.{Arbitrary, Gen} trait ModelGenerators { + + implicit lazy val arbitraryCategory1Assesments: Arbitrary[Category1Assesments] = + Arbitrary { + Gen.oneOf(Category1Assesments.values) + } } diff --git a/test/controllers/Category1AssesmentsControllerSpec.scala b/test/controllers/Category1AssesmentsControllerSpec.scala new file mode 100644 index 000000000..af527076a --- /dev/null +++ b/test/controllers/Category1AssesmentsControllerSpec.scala @@ -0,0 +1,158 @@ +/* + * Copyright 2024 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package controllers + +import base.SpecBase +import forms.Category1AssesmentsFormProvider +import models.{NormalMode, Category1Assesments, UserAnswers} +import navigation.{FakeNavigator, Navigator} +import org.mockito.ArgumentMatchers.any +import org.mockito.Mockito.when +import org.scalatestplus.mockito.MockitoSugar +import pages.Category1AssesmentsPage +import play.api.inject.bind +import play.api.mvc.Call +import play.api.test.FakeRequest +import play.api.test.Helpers._ +import repositories.SessionRepository +import views.html.Category1AssesmentsView + +import scala.concurrent.Future + +class Category1AssesmentsControllerSpec extends SpecBase with MockitoSugar { + + private def onwardRoute = Call("GET", "/foo") + + private lazy val category1AssesmentsRoute = routes.Category1AssesmentsController.onPageLoad(NormalMode).url + + val formProvider = new Category1AssesmentsFormProvider() + private val form = formProvider() + + "Category1Assesments Controller" - { + + "must return OK and the correct view for a GET" in { + + val application = applicationBuilder(userAnswers = Some(emptyUserAnswers)).build() + + running(application) { + val request = FakeRequest(GET, category1AssesmentsRoute) + + val result = route(application, request).value + + val view = application.injector.instanceOf[Category1AssesmentsView] + + status(result) mustEqual OK + contentAsString(result) mustEqual view(form, NormalMode)(request, messages(application)).toString + } + } + + "must populate the view correctly on a GET when the question has previously been answered" in { + + val userAnswers = UserAnswers(userAnswersId).set(Category1AssesmentsPage, Category1Assesments.values.head).success.value + + val application = applicationBuilder(userAnswers = Some(userAnswers)).build() + + running(application) { + val request = FakeRequest(GET, category1AssesmentsRoute) + + val view = application.injector.instanceOf[Category1AssesmentsView] + + val result = route(application, request).value + + status(result) mustEqual OK + contentAsString(result) mustEqual view(form.fill(Category1Assesments.values.head), NormalMode)(request, messages(application)).toString + } + } + + "must redirect to the next page when valid data is submitted" in { + + val mockSessionRepository = mock[SessionRepository] + + when(mockSessionRepository.set(any())) thenReturn Future.successful(true) + + val application = + applicationBuilder(userAnswers = Some(emptyUserAnswers)) + .overrides( + bind[Navigator].toInstance(new FakeNavigator(onwardRoute)), + bind[SessionRepository].toInstance(mockSessionRepository) + ) + .build() + + running(application) { + val request = + FakeRequest(POST, category1AssesmentsRoute) + .withFormUrlEncodedBody(("value", Category1Assesments.values.head.toString)) + + val result = route(application, request).value + + status(result) mustEqual SEE_OTHER + redirectLocation(result).value mustEqual onwardRoute.url + } + } + + "must return a Bad Request and errors when invalid data is submitted" in { + + val application = applicationBuilder(userAnswers = Some(emptyUserAnswers)).build() + + running(application) { + val request = + FakeRequest(POST, category1AssesmentsRoute) + .withFormUrlEncodedBody(("value", "invalid value")) + + val boundForm = form.bind(Map("value" -> "invalid value")) + + val view = application.injector.instanceOf[Category1AssesmentsView] + + val result = route(application, request).value + + status(result) mustEqual BAD_REQUEST + contentAsString(result) mustEqual view(boundForm, NormalMode)(request, messages(application)).toString + } + } + + "must redirect to Journey Recovery for a GET if no existing data is found" in { + + val application = applicationBuilder(userAnswers = None).build() + + running(application) { + val request = FakeRequest(GET, category1AssesmentsRoute) + + val result = route(application, request).value + + status(result) mustEqual SEE_OTHER + redirectLocation(result).value mustEqual routes.JourneyRecoveryController.onPageLoad().url + } + } + + "redirect to Journey Recovery for a POST if no existing data is found" in { + + val application = applicationBuilder(userAnswers = None).build() + + running(application) { + val request = + FakeRequest(POST, category1AssesmentsRoute) + .withFormUrlEncodedBody(("value", Category1Assesments.values.head.toString)) + + val result = route(application, request).value + + status(result) mustEqual SEE_OTHER + + redirectLocation(result).value mustEqual routes.JourneyRecoveryController.onPageLoad().url + } + } + } +} diff --git a/test/controllers/CreateRecordStartControllerSpec.scala b/test/controllers/CreateRecordStartControllerSpec.scala new file mode 100644 index 000000000..5ed22a41e --- /dev/null +++ b/test/controllers/CreateRecordStartControllerSpec.scala @@ -0,0 +1,44 @@ +/* + * Copyright 2024 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package controllers + +import base.SpecBase +import play.api.test.FakeRequest +import play.api.test.Helpers._ +import views.html.CreateRecordStartView + +class CreateRecordStartControllerSpec extends SpecBase { + + "CreateRecordStart Controller" - { + + "must return OK and the correct view for a GET" in { + + val application = applicationBuilder(userAnswers = Some(emptyUserAnswers)).build() + + running(application) { + val request = FakeRequest(GET, routes.CreateRecordStartController.onPageLoad().url) + + val result = route(application, request).value + + val view = application.injector.instanceOf[CreateRecordStartView] + + status(result) mustEqual OK + contentAsString(result) mustEqual view()(request, messages(application)).toString + } + } + } +} diff --git a/test/controllers/CreateRecordSuccessControllerSpec.scala b/test/controllers/CreateRecordSuccessControllerSpec.scala new file mode 100644 index 000000000..0b496fa42 --- /dev/null +++ b/test/controllers/CreateRecordSuccessControllerSpec.scala @@ -0,0 +1,44 @@ +/* + * Copyright 2024 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package controllers + +import base.SpecBase +import play.api.test.FakeRequest +import play.api.test.Helpers._ +import views.html.CreateRecordSuccessView + +class CreateRecordSuccessControllerSpec extends SpecBase { + + "CreateRecordSuccess Controller" - { + + "must return OK and the correct view for a GET" in { + + val application = applicationBuilder(userAnswers = Some(emptyUserAnswers)).build() + + running(application) { + val request = FakeRequest(GET, routes.CreateRecordSuccessController.onPageLoad().url) + + val result = route(application, request).value + + val view = application.injector.instanceOf[CreateRecordSuccessView] + + status(result) mustEqual OK + contentAsString(result) mustEqual view()(request, messages(application)).toString + } + } + } +} diff --git a/test/controllers/GoodsDescriptionControllerSpec.scala b/test/controllers/GoodsDescriptionControllerSpec.scala new file mode 100644 index 000000000..40d9cf6ae --- /dev/null +++ b/test/controllers/GoodsDescriptionControllerSpec.scala @@ -0,0 +1,157 @@ +/* + * Copyright 2024 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package controllers + +import base.SpecBase +import forms.GoodsDescriptionFormProvider +import models.{NormalMode, UserAnswers} +import navigation.{FakeNavigator, Navigator} +import org.mockito.ArgumentMatchers.any +import org.mockito.Mockito.when +import org.scalatestplus.mockito.MockitoSugar +import pages.GoodsDescriptionPage +import play.api.inject.bind +import play.api.mvc.Call +import play.api.test.FakeRequest +import play.api.test.Helpers._ +import repositories.SessionRepository +import views.html.GoodsDescriptionView + +import scala.concurrent.Future + +class GoodsDescriptionControllerSpec extends SpecBase with MockitoSugar { + + private def onwardRoute = Call("GET", "/foo") + + val formProvider = new GoodsDescriptionFormProvider() + private val form = formProvider() + + private lazy val goodsDescriptionRoute = routes.GoodsDescriptionController.onPageLoad(NormalMode).url + + "GoodsDescription Controller" - { + + "must return OK and the correct view for a GET" in { + + val application = applicationBuilder(userAnswers = Some(emptyUserAnswers)).build() + + running(application) { + val request = FakeRequest(GET, goodsDescriptionRoute) + + val result = route(application, request).value + + val view = application.injector.instanceOf[GoodsDescriptionView] + + status(result) mustEqual OK + contentAsString(result) mustEqual view(form, NormalMode)(request, messages(application)).toString + } + } + + "must populate the view correctly on a GET when the question has previously been answered" in { + + val userAnswers = UserAnswers(userAnswersId).set(GoodsDescriptionPage, "answer").success.value + + val application = applicationBuilder(userAnswers = Some(userAnswers)).build() + + running(application) { + val request = FakeRequest(GET, goodsDescriptionRoute) + + val view = application.injector.instanceOf[GoodsDescriptionView] + + val result = route(application, request).value + + status(result) mustEqual OK + contentAsString(result) mustEqual view(form.fill("answer"), NormalMode)(request, messages(application)).toString + } + } + + "must redirect to the next page when valid data is submitted" in { + + val mockSessionRepository = mock[SessionRepository] + + when(mockSessionRepository.set(any())) thenReturn Future.successful(true) + + val application = + applicationBuilder(userAnswers = Some(emptyUserAnswers)) + .overrides( + bind[Navigator].toInstance(new FakeNavigator(onwardRoute)), + bind[SessionRepository].toInstance(mockSessionRepository) + ) + .build() + + running(application) { + val request = + FakeRequest(POST, goodsDescriptionRoute) + .withFormUrlEncodedBody(("value", "answer")) + + val result = route(application, request).value + + status(result) mustEqual SEE_OTHER + redirectLocation(result).value mustEqual onwardRoute.url + } + } + + "must return a Bad Request and errors when invalid data is submitted" in { + + val application = applicationBuilder(userAnswers = Some(emptyUserAnswers)).build() + + running(application) { + val request = + FakeRequest(POST, goodsDescriptionRoute) + .withFormUrlEncodedBody(("value", "")) + + val boundForm = form.bind(Map("value" -> "")) + + val view = application.injector.instanceOf[GoodsDescriptionView] + + val result = route(application, request).value + + status(result) mustEqual BAD_REQUEST + contentAsString(result) mustEqual view(boundForm, NormalMode)(request, messages(application)).toString + } + } + + "must redirect to Journey Recovery for a GET if no existing data is found" in { + + val application = applicationBuilder(userAnswers = None).build() + + running(application) { + val request = FakeRequest(GET, goodsDescriptionRoute) + + val result = route(application, request).value + + status(result) mustEqual SEE_OTHER + redirectLocation(result).value mustEqual routes.JourneyRecoveryController.onPageLoad().url + } + } + + "must redirect to Journey Recovery for a POST if no existing data is found" in { + + val application = applicationBuilder(userAnswers = None).build() + + running(application) { + val request = + FakeRequest(POST, goodsDescriptionRoute) + .withFormUrlEncodedBody(("value", "answer")) + + val result = route(application, request).value + + status(result) mustEqual SEE_OTHER + redirectLocation(result).value mustEqual routes.JourneyRecoveryController.onPageLoad().url + } + } + } +} diff --git a/test/controllers/HasCorrectGoodsControllerSpec.scala b/test/controllers/HasCorrectGoodsControllerSpec.scala new file mode 100644 index 000000000..024b1f50b --- /dev/null +++ b/test/controllers/HasCorrectGoodsControllerSpec.scala @@ -0,0 +1,157 @@ +/* + * Copyright 2024 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package controllers + +import base.SpecBase +import forms.HasCorrectGoodsFormProvider +import models.{NormalMode, UserAnswers} +import navigation.{FakeNavigator, Navigator} +import org.mockito.ArgumentMatchers.any +import org.mockito.Mockito.when +import org.scalatestplus.mockito.MockitoSugar +import pages.HasCorrectGoodsPage +import play.api.inject.bind +import play.api.mvc.Call +import play.api.test.FakeRequest +import play.api.test.Helpers._ +import repositories.SessionRepository +import views.html.HasCorrectGoodsView + +import scala.concurrent.Future + +class HasCorrectGoodsControllerSpec extends SpecBase with MockitoSugar { + + private def onwardRoute = Call("GET", "/foo") + + val formProvider = new HasCorrectGoodsFormProvider() + private val form = formProvider() + + private lazy val hasCorrectGoodsRoute = routes.HasCorrectGoodsController.onPageLoad(NormalMode).url + + "HasCorrectGoods Controller" - { + + "must return OK and the correct view for a GET" in { + + val application = applicationBuilder(userAnswers = Some(emptyUserAnswers)).build() + + running(application) { + val request = FakeRequest(GET, hasCorrectGoodsRoute) + + val result = route(application, request).value + + val view = application.injector.instanceOf[HasCorrectGoodsView] + + status(result) mustEqual OK + contentAsString(result) mustEqual view(form, NormalMode)(request, messages(application)).toString + } + } + + "must populate the view correctly on a GET when the question has previously been answered" in { + + val userAnswers = UserAnswers(userAnswersId).set(HasCorrectGoodsPage, true).success.value + + val application = applicationBuilder(userAnswers = Some(userAnswers)).build() + + running(application) { + val request = FakeRequest(GET, hasCorrectGoodsRoute) + + val view = application.injector.instanceOf[HasCorrectGoodsView] + + val result = route(application, request).value + + status(result) mustEqual OK + contentAsString(result) mustEqual view(form.fill(true), NormalMode)(request, messages(application)).toString + } + } + + "must redirect to the next page when valid data is submitted" in { + + val mockSessionRepository = mock[SessionRepository] + + when(mockSessionRepository.set(any())) thenReturn Future.successful(true) + + val application = + applicationBuilder(userAnswers = Some(emptyUserAnswers)) + .overrides( + bind[Navigator].toInstance(new FakeNavigator(onwardRoute)), + bind[SessionRepository].toInstance(mockSessionRepository) + ) + .build() + + running(application) { + val request = + FakeRequest(POST, hasCorrectGoodsRoute) + .withFormUrlEncodedBody(("value", "true")) + + val result = route(application, request).value + + status(result) mustEqual SEE_OTHER + redirectLocation(result).value mustEqual onwardRoute.url + } + } + + "must return a Bad Request and errors when invalid data is submitted" in { + + val application = applicationBuilder(userAnswers = Some(emptyUserAnswers)).build() + + running(application) { + val request = + FakeRequest(POST, hasCorrectGoodsRoute) + .withFormUrlEncodedBody(("value", "")) + + val boundForm = form.bind(Map("value" -> "")) + + val view = application.injector.instanceOf[HasCorrectGoodsView] + + val result = route(application, request).value + + status(result) mustEqual BAD_REQUEST + contentAsString(result) mustEqual view(boundForm, NormalMode)(request, messages(application)).toString + } + } + + "must redirect to Journey Recovery for a GET if no existing data is found" in { + + val application = applicationBuilder(userAnswers = None).build() + + running(application) { + val request = FakeRequest(GET, hasCorrectGoodsRoute) + + val result = route(application, request).value + + status(result) mustEqual SEE_OTHER + redirectLocation(result).value mustEqual routes.JourneyRecoveryController.onPageLoad().url + } + } + + "must redirect to Journey Recovery for a POST if no existing data is found" in { + + val application = applicationBuilder(userAnswers = None).build() + + running(application) { + val request = + FakeRequest(POST, hasCorrectGoodsRoute) + .withFormUrlEncodedBody(("value", "true")) + + val result = route(application, request).value + + status(result) mustEqual SEE_OTHER + redirectLocation(result).value mustEqual routes.JourneyRecoveryController.onPageLoad().url + } + } + } +} diff --git a/test/controllers/HasGoodsDescriptionControllerSpec.scala b/test/controllers/HasGoodsDescriptionControllerSpec.scala new file mode 100644 index 000000000..0e278897e --- /dev/null +++ b/test/controllers/HasGoodsDescriptionControllerSpec.scala @@ -0,0 +1,157 @@ +/* + * Copyright 2024 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package controllers + +import base.SpecBase +import forms.HasGoodsDescriptionFormProvider +import models.{NormalMode, UserAnswers} +import navigation.{FakeNavigator, Navigator} +import org.mockito.ArgumentMatchers.any +import org.mockito.Mockito.when +import org.scalatestplus.mockito.MockitoSugar +import pages.HasGoodsDescriptionPage +import play.api.inject.bind +import play.api.mvc.Call +import play.api.test.FakeRequest +import play.api.test.Helpers._ +import repositories.SessionRepository +import views.html.HasGoodsDescriptionView + +import scala.concurrent.Future + +class HasGoodsDescriptionControllerSpec extends SpecBase with MockitoSugar { + + private def onwardRoute = Call("GET", "/foo") + + val formProvider = new HasGoodsDescriptionFormProvider() + private val form = formProvider() + + private lazy val hasGoodsDescriptionRoute = routes.HasGoodsDescriptionController.onPageLoad(NormalMode).url + + "HasGoodsDescription Controller" - { + + "must return OK and the correct view for a GET" in { + + val application = applicationBuilder(userAnswers = Some(emptyUserAnswers)).build() + + running(application) { + val request = FakeRequest(GET, hasGoodsDescriptionRoute) + + val result = route(application, request).value + + val view = application.injector.instanceOf[HasGoodsDescriptionView] + + status(result) mustEqual OK + contentAsString(result) mustEqual view(form, NormalMode)(request, messages(application)).toString + } + } + + "must populate the view correctly on a GET when the question has previously been answered" in { + + val userAnswers = UserAnswers(userAnswersId).set(HasGoodsDescriptionPage, true).success.value + + val application = applicationBuilder(userAnswers = Some(userAnswers)).build() + + running(application) { + val request = FakeRequest(GET, hasGoodsDescriptionRoute) + + val view = application.injector.instanceOf[HasGoodsDescriptionView] + + val result = route(application, request).value + + status(result) mustEqual OK + contentAsString(result) mustEqual view(form.fill(true), NormalMode)(request, messages(application)).toString + } + } + + "must redirect to the next page when valid data is submitted" in { + + val mockSessionRepository = mock[SessionRepository] + + when(mockSessionRepository.set(any())) thenReturn Future.successful(true) + + val application = + applicationBuilder(userAnswers = Some(emptyUserAnswers)) + .overrides( + bind[Navigator].toInstance(new FakeNavigator(onwardRoute)), + bind[SessionRepository].toInstance(mockSessionRepository) + ) + .build() + + running(application) { + val request = + FakeRequest(POST, hasGoodsDescriptionRoute) + .withFormUrlEncodedBody(("value", "true")) + + val result = route(application, request).value + + status(result) mustEqual SEE_OTHER + redirectLocation(result).value mustEqual onwardRoute.url + } + } + + "must return a Bad Request and errors when invalid data is submitted" in { + + val application = applicationBuilder(userAnswers = Some(emptyUserAnswers)).build() + + running(application) { + val request = + FakeRequest(POST, hasGoodsDescriptionRoute) + .withFormUrlEncodedBody(("value", "")) + + val boundForm = form.bind(Map("value" -> "")) + + val view = application.injector.instanceOf[HasGoodsDescriptionView] + + val result = route(application, request).value + + status(result) mustEqual BAD_REQUEST + contentAsString(result) mustEqual view(boundForm, NormalMode)(request, messages(application)).toString + } + } + + "must redirect to Journey Recovery for a GET if no existing data is found" in { + + val application = applicationBuilder(userAnswers = None).build() + + running(application) { + val request = FakeRequest(GET, hasGoodsDescriptionRoute) + + val result = route(application, request).value + + status(result) mustEqual SEE_OTHER + redirectLocation(result).value mustEqual routes.JourneyRecoveryController.onPageLoad().url + } + } + + "must redirect to Journey Recovery for a POST if no existing data is found" in { + + val application = applicationBuilder(userAnswers = None).build() + + running(application) { + val request = + FakeRequest(POST, hasGoodsDescriptionRoute) + .withFormUrlEncodedBody(("value", "true")) + + val result = route(application, request).value + + status(result) mustEqual SEE_OTHER + redirectLocation(result).value mustEqual routes.JourneyRecoveryController.onPageLoad().url + } + } + } +} diff --git a/test/forms/Category1AssesmentsFormProviderSpec.scala b/test/forms/Category1AssesmentsFormProviderSpec.scala new file mode 100644 index 000000000..c53b42420 --- /dev/null +++ b/test/forms/Category1AssesmentsFormProviderSpec.scala @@ -0,0 +1,45 @@ +/* + * Copyright 2024 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package forms + +import forms.behaviours.OptionFieldBehaviours +import models.Category1Assesments +import play.api.data.FormError + +class Category1AssesmentsFormProviderSpec extends OptionFieldBehaviours { + + val form = new Category1AssesmentsFormProvider()() + + ".value" - { + + val fieldName = "value" + val requiredKey = "category1Assesments.error.required" + + behave like optionsField[Category1Assesments]( + form, + fieldName, + validValues = Category1Assesments.values, + invalidError = FormError(fieldName, "error.invalid") + ) + + behave like mandatoryField( + form, + fieldName, + requiredError = FormError(fieldName, requiredKey) + ) + } +} diff --git a/test/forms/GoodsDescriptionFormProviderSpec.scala b/test/forms/GoodsDescriptionFormProviderSpec.scala new file mode 100644 index 000000000..0de28c26b --- /dev/null +++ b/test/forms/GoodsDescriptionFormProviderSpec.scala @@ -0,0 +1,53 @@ +/* + * Copyright 2024 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package forms + +import forms.behaviours.StringFieldBehaviours +import play.api.data.FormError + +class GoodsDescriptionFormProviderSpec extends StringFieldBehaviours { + + val requiredKey = "goodsDescription.error.required" + val lengthKey = "goodsDescription.error.length" + val maxLength = 512 + + val form = new GoodsDescriptionFormProvider()() + + ".value" - { + + val fieldName = "value" + + behave like fieldThatBindsValidData( + form, + fieldName, + stringsWithMaxLength(maxLength) + ) + + behave like fieldWithMaxLength( + form, + fieldName, + maxLength = maxLength, + lengthError = FormError(fieldName, lengthKey, Seq(maxLength)) + ) + + behave like mandatoryField( + form, + fieldName, + requiredError = FormError(fieldName, requiredKey) + ) + } +} diff --git a/test/forms/HasCorrectGoodsFormProviderSpec.scala b/test/forms/HasCorrectGoodsFormProviderSpec.scala new file mode 100644 index 000000000..9b70fa7c6 --- /dev/null +++ b/test/forms/HasCorrectGoodsFormProviderSpec.scala @@ -0,0 +1,45 @@ +/* + * Copyright 2024 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package forms + +import forms.behaviours.BooleanFieldBehaviours +import play.api.data.FormError + +class HasCorrectGoodsFormProviderSpec extends BooleanFieldBehaviours { + + val requiredKey = "hasCorrectGoods.error.required" + val invalidKey = "error.boolean" + + val form = new HasCorrectGoodsFormProvider()() + + ".value" - { + + 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/forms/HasGoodsDescriptionFormProviderSpec.scala b/test/forms/HasGoodsDescriptionFormProviderSpec.scala new file mode 100644 index 000000000..d3eb7833c --- /dev/null +++ b/test/forms/HasGoodsDescriptionFormProviderSpec.scala @@ -0,0 +1,45 @@ +/* + * Copyright 2024 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package forms + +import forms.behaviours.BooleanFieldBehaviours +import play.api.data.FormError + +class HasGoodsDescriptionFormProviderSpec extends BooleanFieldBehaviours { + + val requiredKey = "hasGoodsDescription.error.required" + val invalidKey = "error.boolean" + + val form = new HasGoodsDescriptionFormProvider()() + + ".value" - { + + 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/models/Category1AssesmentsSpec.scala b/test/models/Category1AssesmentsSpec.scala new file mode 100644 index 000000000..248842c1a --- /dev/null +++ b/test/models/Category1AssesmentsSpec.scala @@ -0,0 +1,64 @@ +/* + * Copyright 2024 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package models + +import org.scalacheck.Arbitrary.arbitrary +import org.scalacheck.Gen +import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks +import org.scalatest.freespec.AnyFreeSpec +import org.scalatest.matchers.must.Matchers +import org.scalatest.OptionValues +import play.api.libs.json.{JsError, JsString, Json} + +class Category1AssesmentsSpec extends AnyFreeSpec with Matchers with ScalaCheckPropertyChecks with OptionValues { + + "Category1Assesments" - { + + "must deserialise valid values" in { + + val gen = Gen.oneOf(Category1Assesments.values) + + forAll(gen) { + category1Assesments => + + JsString(category1Assesments.toString).validate[Category1Assesments].asOpt.value mustEqual category1Assesments + } + } + + "must fail to deserialise invalid values" in { + + val gen = arbitrary[String] suchThat (!Category1Assesments.values.map(_.toString).contains(_)) + + forAll(gen) { + invalidValue => + + JsString(invalidValue).validate[Category1Assesments] mustEqual JsError("error.invalid") + } + } + + "must serialise" in { + + val gen = Gen.oneOf(Category1Assesments.values) + + forAll(gen) { + category1Assesments => + + Json.toJson(category1Assesments) mustEqual JsString(category1Assesments.toString) + } + } + } +}