Skip to content

Commit 01cb611

Browse files
committed
[DTR-4543] fixing unit test
1 parent 740e8ed commit 01cb611

5 files changed

Lines changed: 27 additions & 29 deletions

File tree

app/controllers/amend/WhatDoYouWantToAmendStandardController.scala

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package controllers.amend
1919
import controllers.actions._
2020
import forms.amend.WhatDoYouWantToAmendStandardFormProvider
2121
import javax.inject.Inject
22-
import models.Mode
22+
import models.NormalMode
2323
import navigation.Navigator
2424
import pages.amend.WhatDoYouWantToAmendStandardPage
2525
import play.api.i18n.{I18nSupport, MessagesApi}
@@ -46,27 +46,26 @@ class WhatDoYouWantToAmendStandardController @Inject() (
4646

4747
val form = formProvider()
4848

49-
def onPageLoad(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData) { implicit request =>
49+
def onPageLoad(): Action[AnyContent] = (identify andThen getData andThen requireData) { implicit request =>
5050

5151
val preparedForm = request.userAnswers.get(WhatDoYouWantToAmendStandardPage) match {
5252
case None => form
5353
case Some(value) => form.fill(value)
5454
}
5555

56-
Ok(view(preparedForm, mode))
56+
Ok(view(preparedForm))
5757
}
5858

59-
def onSubmit(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData).async {
60-
implicit request =>
61-
form
62-
.bindFromRequest()
63-
.fold(
64-
formWithErrors => Future.successful(BadRequest(view(formWithErrors, mode))),
65-
value =>
66-
for {
67-
updatedAnswers <- Future.fromTry(request.userAnswers.set(WhatDoYouWantToAmendStandardPage, value))
68-
_ <- sessionRepository.set(updatedAnswers)
69-
} yield Redirect(navigator.nextPage(WhatDoYouWantToAmendStandardPage, mode, updatedAnswers))
70-
)
59+
def onSubmit(): Action[AnyContent] = (identify andThen getData andThen requireData).async { implicit request =>
60+
form
61+
.bindFromRequest()
62+
.fold(
63+
formWithErrors => Future.successful(BadRequest(view(formWithErrors))),
64+
value =>
65+
for {
66+
updatedAnswers <- Future.fromTry(request.userAnswers.set(WhatDoYouWantToAmendStandardPage, value))
67+
_ <- sessionRepository.set(updatedAnswers)
68+
} yield Redirect(navigator.nextPage(WhatDoYouWantToAmendStandardPage, NormalMode, updatedAnswers))
69+
)
7170
}
7271
}

app/views/amend/WhatDoYouWantToAmendStandardView.scala.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
govukButton: GovukButton
2525
)
2626

27-
@(form: Form[_], mode: Mode)(implicit request: Request[_], messages: Messages)
27+
@(form: Form[_])(implicit request: Request[_], messages: Messages)
2828

2929
@layout(pageTitle = title(form, messages("amend.whatDoYouWantToAmendStandard.title"))) {
3030

31-
@formHelper(action = controllers.amend.routes.WhatDoYouWantToAmendStandardController.onSubmit(mode), Symbol("autoComplete") -> "off") {
31+
@formHelper(action = controllers.amend.routes.WhatDoYouWantToAmendStandardController.onSubmit(), Symbol("autoComplete") -> "off") {
3232

3333
@if(form.errors.nonEmpty) {
3434
@govukErrorSummary(ErrorSummaryViewModel(form, errorLinkOverrides = Map("value" -> "value_0")))

conf/app.routes

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,5 +174,5 @@ POST /amend-monthly-return/what-do-you-want-to-amend-nil
174174
GET /manage-cis-return/amend-monthly-return/confirm-amendment controllers.amend.ConfirmAmendmentController.onPageLoad()
175175
POST /manage-cis-return/amend-monthly-return/confirm-amendment controllers.amend.ConfirmAmendmentController.onSubmit()
176176

177-
GET /amend-monthly-return/what-do-you-want-to-amend-standard controllers.amend.WhatDoYouWantToAmendStandardController.onPageLoad(mode: Mode = NormalMode)
178-
POST /amend-monthly-return/what-do-you-want-to-amend-standard controllers.amend.WhatDoYouWantToAmendStandardController.onSubmit(mode: Mode = NormalMode)
177+
GET /amend-monthly-return/what-do-you-want-to-amend-standard controllers.amend.WhatDoYouWantToAmendStandardController.onPageLoad()
178+
POST /amend-monthly-return/what-do-you-want-to-amend-standard controllers.amend.WhatDoYouWantToAmendStandardController.onSubmit()

test/controllers/amend/WhatDoYouWantToAmendStandardControllerSpec.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package controllers.amend
1818

1919
import base.SpecBase
2020
import forms.amend.WhatDoYouWantToAmendStandardFormProvider
21-
import models.{NormalMode, UserAnswers}
21+
import models.UserAnswers
2222
import models.amend.WhatDoYouWantToAmendStandard
2323
import navigation.{FakeNavigator, Navigator}
2424
import org.mockito.ArgumentMatchers.any
@@ -38,7 +38,7 @@ class WhatDoYouWantToAmendStandardControllerSpec extends SpecBase with MockitoSu
3838

3939
def onwardRoute = Call("GET", "/foo")
4040

41-
lazy val whatDoYouWantToAmendStandardRoute = routes.WhatDoYouWantToAmendStandardController.onPageLoad(NormalMode).url
41+
lazy val whatDoYouWantToAmendStandardRoute = routes.WhatDoYouWantToAmendStandardController.onPageLoad().url
4242

4343
val formProvider = new WhatDoYouWantToAmendStandardFormProvider()
4444
val form = formProvider()
@@ -57,7 +57,7 @@ class WhatDoYouWantToAmendStandardControllerSpec extends SpecBase with MockitoSu
5757
val view = application.injector.instanceOf[WhatDoYouWantToAmendStandardView]
5858

5959
status(result) mustEqual OK
60-
contentAsString(result) mustEqual view(form, NormalMode)(request, messages(application)).toString
60+
contentAsString(result) mustEqual view(form)(request, messages(application)).toString
6161
}
6262
}
6363

@@ -78,7 +78,7 @@ class WhatDoYouWantToAmendStandardControllerSpec extends SpecBase with MockitoSu
7878
val result = route(application, request).value
7979

8080
status(result) mustEqual OK
81-
contentAsString(result) mustEqual view(form.fill(WhatDoYouWantToAmendStandard.values.head), NormalMode)(
81+
contentAsString(result) mustEqual view(form.fill(WhatDoYouWantToAmendStandard.values.head))(
8282
request,
8383
messages(application)
8484
).toString
@@ -127,7 +127,7 @@ class WhatDoYouWantToAmendStandardControllerSpec extends SpecBase with MockitoSu
127127
val result = route(application, request).value
128128

129129
status(result) mustEqual BAD_REQUEST
130-
contentAsString(result) mustEqual view(boundForm, NormalMode)(request, messages(application)).toString
130+
contentAsString(result) mustEqual view(boundForm)(request, messages(application)).toString
131131
}
132132
}
133133

test/views/amend/WhatDoYouWantToAmendStandardViewSpec.scala

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package views.amend
1818

1919
import base.SpecBase
2020
import forms.amend.WhatDoYouWantToAmendStandardFormProvider
21-
import models.NormalMode
2221
import models.amend.WhatDoYouWantToAmendStandard
2322
import org.jsoup.Jsoup
2423
import org.jsoup.nodes.Document
@@ -51,7 +50,7 @@ class WhatDoYouWantToAmendStandardViewSpec extends SpecBase {
5150

5251
"must pre-populate the form when user has previously answered" in new Setup {
5352
val filledForm = form.fill(WhatDoYouWantToAmendStandard.AmendToNilReturn)
54-
val filledHtml = view(filledForm, NormalMode)
53+
val filledHtml = view(filledForm)
5554
val doc: Document = Jsoup.parse(filledHtml.toString)
5655

5756
doc.select("input[value=amendToNilReturn]").hasAttr("checked") mustBe true
@@ -60,7 +59,7 @@ class WhatDoYouWantToAmendStandardViewSpec extends SpecBase {
6059

6160
"must show error summary when form has errors" in new Setup {
6261
val formWithErrors = form.bind(Map("value" -> ""))
63-
val errorHtml = view(formWithErrors, NormalMode)
62+
val errorHtml = view(formWithErrors)
6463
val doc: Document = Jsoup.parse(errorHtml.toString)
6564

6665
doc.title must startWith(messages("error.title.prefix"))
@@ -70,7 +69,7 @@ class WhatDoYouWantToAmendStandardViewSpec extends SpecBase {
7069

7170
"must render error summary with correct link when form has errors" in new Setup {
7271
val formWithErrors = form.bind(Map("value" -> ""))
73-
val errorHtml = view(formWithErrors, NormalMode)
72+
val errorHtml = view(formWithErrors)
7473
val doc: Document = Jsoup.parse(errorHtml.toString)
7574

7675
doc.select(".govuk-error-summary__list a").attr("href") mustBe "#value_0"
@@ -93,6 +92,6 @@ class WhatDoYouWantToAmendStandardViewSpec extends SpecBase {
9392
app.injector.instanceOf[play.api.i18n.MessagesApi]
9493
)
9594

96-
val html = view(form, NormalMode)
95+
val html = view(form)
9796
}
9897
}

0 commit comments

Comments
 (0)