From 61266a2e59e9ae108336ddb5b685108e30b4fb17 Mon Sep 17 00:00:00 2001 From: subhajitchowdhury Date: Thu, 26 May 2016 14:47:40 +0100 Subject: [PATCH] TAMC-941 previous year new page functionality added --- app/controllers/TransferController.scala | 20 ++- app/forms/CurrentYearForm.scala | 5 +- app/models/CurrentYearInput.scala | 2 +- app/views/eligible_years.scala.html | 29 ++--- app/views/previousYears.scala.html | 46 +++++++ conf/app.routes | 1 + test/controllers/ContentTest.scala | 31 ++++- .../MarriageAllowanceControllerTest.scala | 119 +++++++++++++++++- 8 files changed, 216 insertions(+), 37 deletions(-) create mode 100644 app/views/previousYears.scala.html diff --git a/app/controllers/TransferController.scala b/app/controllers/TransferController.scala index e68a0fdb..6044e6e1 100644 --- a/app/controllers/TransferController.scala +++ b/app/controllers/TransferController.scala @@ -59,7 +59,7 @@ import errors.TransferorDeceased import details.CitizenDetailsService import details.TamcUser import scala.concurrent.ExecutionContext.Implicits.global -import forms.MultiYearForm.multiYearForm +import forms.MultiYearForm._ import services.TimeService import services.CachingService import forms.CurrentYearForm.currentYearForm @@ -136,7 +136,7 @@ trait TransferController extends FrontendController with AuthorisedActions with case (false, extraYears, recipient) if (extraYears.isEmpty) => throw new NoTaxYearsAvailable case (false, extraYears, recipient) if (!extraYears.isEmpty) => - Ok(views.html.multi_year_select(multiYearForm(), recipient.data, extraYears)) + Ok(views.html.previousYears(recipient.data, extraYears)) case (currentYearAvailable, extraYears, recipient) => Ok(views.html.eligible_years( currentYearForm(!extraYears.isEmpty), @@ -168,10 +168,8 @@ trait TransferController extends FrontendController with AuthorisedActions with _ => if (extraYears.isEmpty && currentYearAvailable && (success.applyForCurrentYear != Some(true))) { throw new NoTaxYearsSelected - } else if (!extraYears.isEmpty && currentYearAvailable && !(success.applyForCurrentYear == Some(true) || success.applyForRetrospectiveYears == Some(true))) { - throw new NoTaxYearsSelected - } else if (!extraYears.isEmpty && success.applyForRetrospectiveYears == Some(true)) { - Ok(views.html.multi_year_select(multiYearForm(), recipient.data, extraYears)) + } else if (!extraYears.isEmpty) { + Ok(views.html.previousYears(recipient.data, extraYears)) } else { Redirect(controllers.routes.TransferController.confirmYourEmail()) } @@ -180,6 +178,16 @@ trait TransferController extends FrontendController with AuthorisedActions with } recover (handleError) } + def previousYears = TamcAuthPersonalDetailsAction { + implicit auth => + implicit request => + implicit details => + registrationService.getCurrentAndExtraYearEligibility flatMap { + case (currentYearAvailable, extraYears, recipient) => + Future.successful(Ok(views.html.multi_year_select(multiYearForm(), recipient.data, extraYears))) + }recover (handleError) + } + def extraYearsAction = TamcAuthPersonalDetailsAction { implicit auth => implicit request => diff --git a/app/forms/CurrentYearForm.scala b/app/forms/CurrentYearForm.scala index 0702b8b5..00ed3a5d 100644 --- a/app/forms/CurrentYearForm.scala +++ b/app/forms/CurrentYearForm.scala @@ -41,7 +41,6 @@ import models.CurrentYearInput object CurrentYearForm { def currentYearForm(historicYearsAvailable: Boolean = false) = Form[CurrentYearInput](mapping( "applyForCurrentYear" -> - optional(boolean).verifying("pages.form.field-required.applyForCurrentYear", _.isDefined), - "applyForHistoricYears" -> - optional(boolean).verifying("pages.form.field-required.applyForHistoricYears", selection => !(historicYearsAvailable && selection.isEmpty)))(CurrentYearInput.apply)(CurrentYearInput.unapply)) + optional(boolean).verifying("pages.form.field-required.applyForCurrentYear", _.isDefined) + )(CurrentYearInput.apply)(CurrentYearInput.unapply)) } diff --git a/app/models/CurrentYearInput.scala b/app/models/CurrentYearInput.scala index 56f99445..f782f1a1 100644 --- a/app/models/CurrentYearInput.scala +++ b/app/models/CurrentYearInput.scala @@ -16,4 +16,4 @@ package models -case class CurrentYearInput(applyForCurrentYear: Option[Boolean], applyForRetrospectiveYears: Option[Boolean]) +case class CurrentYearInput(applyForCurrentYear: Option[Boolean]) diff --git a/app/views/eligible_years.scala.html b/app/views/eligible_years.scala.html index d776cf9d..3ef443b2 100644 --- a/app/views/eligible_years.scala.html +++ b/app/views/eligible_years.scala.html @@ -39,7 +39,7 @@ maybeMainDataAttributes = Some(Html("data-journey=marriage-allowance:stage:current-year-select")))) { -

Tax years you are eligible for

+

You can apply for the current tax year

@templates.form_error_notification(form) @@ -53,7 +53,7 @@

This current tax year @helpers.form(action = routes.TransferController.eligibleYearsAction, args = ('id -> "current-year-form")) { -
+

Do you want to apply for this current tax year onwards?

@templates.input_radio_group( form("applyForCurrentYear"), @@ -65,33 +65,18 @@

Do you want to apply for this current tax year onwards '_legendClass -> "visuallyhidden", '_groupClass -> "inline spacingBottom" ) - + @if(historicYearsAvailable) { -
- You can still apply for earlier tax years below. -
- }

- @if(historicYearsAvailable) { -
-

You might also be eligible for earlier tax years

-

Do you want to apply for these additional years also?

- @templates.input_radio_group( - form("applyForHistoricYears"), - Seq(("true", "Yes"), ("false", "No")), - '_labelClass -> "block-label", - '_labelAfter -> true, - '_legend -> "Earlier years", - '_legendClass -> "visuallyhidden", - '_groupClass -> "inline spacingBottom" - ) -
- }

diff --git a/app/views/previousYears.scala.html b/app/views/previousYears.scala.html new file mode 100644 index 00000000..1bd4adea --- /dev/null +++ b/app/views/previousYears.scala.html @@ -0,0 +1,46 @@ +@* +* Copyright 2015 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. +*@ + +@(input:RegistrationFormInput, +availableYears:List[TaxYear] = List[TaxYear]())( + implicit lang: Lang, + request: Request[_], + breadcrumb: uk.gov.hmrc.play.breadcrumb.model.Breadcrumb, + user: details.TamcUser) + +@import play.twirl.api.Html +@import views.helpers.TextGenerators +@import uk.gov.hmrc.play.views.html._ +@import uk.gov.hmrc.time.TaxYearResolver +@import views.helpers.TextGenerators +@import uk.gov.hmrc.play.views.html._ +@import config.ApplicationConfig +@import java.text.NumberFormat + +@templates.tamc_main( + title = Messages("title.pattern", Messages("title.extra-years")), + mainConfig = views.helpers.MainConfig( + maybeMainDataAttributes = Some(Html("data-journey=marriage-allowance:stage:current-year-select")))) { + + +

You can apply for earlier tax years

+

You can apply for Marriage Allowance from when it was first introduced on 6 April 2015.

+ + +

You told us you married or formed a civil partnership with @input.name on @TextGenerators.ukDateTransformer(Some(input.dateOfMarriage)). This means you can apply for earlier tax years.

+ @Html(Messages("generic.continue")) + } + diff --git a/conf/app.routes b/conf/app.routes index 626f91e7..e928bd9e 100644 --- a/conf/app.routes +++ b/conf/app.routes @@ -18,6 +18,7 @@ POST /transfer-allowance controllers.TransferController.transferActi POST /date-of-marriage controllers.TransferController.dateOfMarriageAction GET /eligible-years controllers.TransferController.eligibleYears POST /eligible-years controllers.TransferController.eligibleYearsAction +GET /previous-years controllers.TransferController.previousYears POST /extra-years controllers.TransferController.extraYearsAction GET /confirm-your-email controllers.TransferController.confirmYourEmail POST /confirm-your-email controllers.TransferController.confirmYourEmailAction diff --git a/test/controllers/ContentTest.scala b/test/controllers/ContentTest.scala index 8c8c92ec..f72b144a 100644 --- a/test/controllers/ContentTest.scala +++ b/test/controllers/ContentTest.scala @@ -41,7 +41,7 @@ class ContentTest extends UnitSpec with TestUtility { val controllerToTest = testComponent.controller val request = testComponent.request.withFormUrlEncodedBody(data = ("gender" -> "M"), ("nino" -> Ninos.nino1), ("transferor-email" -> "example@example.com")) val result = controllerToTest.transfer(request) - + status(result) shouldBe OK val document = Jsoup.parse(contentAsString(result)) val transferor = document.getElementById("transferor-name") @@ -232,7 +232,7 @@ class ContentTest extends UnitSpec with TestUtility { labelNino.getElementsByClass("error-message").first().text() shouldBe "You can't enter your own details." document.getElementById("nino-error").text() shouldBe "Confirm your spouse or civil partner's National Insurance number." } - + "display form error message when recipient nino equals transferor nino (including mixed case and spaces)" in new WithApplication(fakeApplication) { val trrec = UserRecord(cid = Cids.cid1, timestamp = "2015", name = TestConstants.GENERIC_CITIZEN_NAME) val trRecipientData = Some(CacheData(transferor = Some(trrec), recipient = None, notification = None)) @@ -504,6 +504,33 @@ class ContentTest extends UnitSpec with TestUtility { } } + "Calling Previous year page " should { + "display dynamic message " in new WithApplication(fakeApplication) { + + val trrec = UserRecord(cid = Cids.cid1, timestamp = "2015") + val rcrec = UserRecord(cid = 123456, timestamp = "2015") + val cacheRecipientFormData = Some(RecipientDetailsFormInput(name = "foo", lastName = "bar", gender = Gender("M"), nino = Nino(Ninos.ninoWithLOA1))) + val rcdata = RegistrationFormInput(name = "foo", lastName = "bar", gender = Gender("M"), nino = Nino(Ninos.ninoWithLOA1), dateOfMarriage = new LocalDate(2011, 4, 10)) + val recrecord = RecipientRecord(record = rcrec, data = rcdata,aivailableTaxYears = List(TaxYear(2014),TaxYear(2015),TaxYear(2016))) + val trRecipientData = Some(CacheData( + transferor = Some(trrec), + recipient = Some(recrecord), + notification = Some(NotificationRecord(EmailAddress("example123@example.com"))), + recipientDetailsFormData = cacheRecipientFormData)) + + val testComponent = makeTestComponent("user_happy_path", transferorRecipientData = trRecipientData) + val controllerToTest = testComponent.controller + val request = testComponent.request.withFormUrlEncodedBody(data = ("applyForCurrentYear" -> "true")) + val result = controllerToTest.eligibleYearsAction(request) + + status(result) shouldBe OK + val document = Jsoup.parse(contentAsString(result)) + document.getElementById("firstNameOnly").text() shouldBe "foo" + document.getElementById("marriageDate").text() shouldBe "10 April 2011" + + } + } + "Calling Confirm email page with error in email field" should { "display form error message (transferor email missing from request)" in new WithApplication(fakeApplication) { val testComponent = makeTestComponent("user_happy_path") diff --git a/test/controllers/MarriageAllowanceControllerTest.scala b/test/controllers/MarriageAllowanceControllerTest.scala index e0226633..d6b68814 100644 --- a/test/controllers/MarriageAllowanceControllerTest.scala +++ b/test/controllers/MarriageAllowanceControllerTest.scala @@ -155,7 +155,7 @@ class MarriageAllowanceControllerTest extends UnitSpec with TestUtility { document.getElementById("error").text() shouldBe "We were unable to process your Marriage Allowance application." } - "showextrayears page if user is eligible for one historic year on eligibleYears page" in new WithApplication(fakeApplication) { + "show extra years page if user is eligible for one historic year on eligibleYears page" in new WithApplication(fakeApplication) { val trrec = UserRecord(cid = Cids.cid1, timestamp = "2015", name = TestConstants.GENERIC_CITIZEN_NAME) val rcrec = UserRecord(cid = Cids.cid2, timestamp = "2015", name = None) @@ -170,11 +170,124 @@ class MarriageAllowanceControllerTest extends UnitSpec with TestUtility { status(result) shouldBe OK val document = Jsoup.parse(contentAsString(result)) - document.getElementById("heading").text() shouldBe "Confirm the earlier years you want to apply for" + document.getElementById("heading").text() shouldBe "You can apply for earlier tax years" + } + + "show No Tax Years selected page if user is only eligible for current year and chooses no" in new WithApplication(fakeApplication) { + + val trrec = UserRecord(cid = Cids.cid1, timestamp = "2015", name = TestConstants.GENERIC_CITIZEN_NAME) + val rcrec = UserRecord(cid = Cids.cid2, timestamp = "2015", name = None) + val cachedRecipientData = Some(RegistrationFormInput("foo", "bar", Gender("F"), Nino(Ninos.ninoWithLOA1), dateOfMarriage = new LocalDate(2016, 4, 24))) + val recrecord = RecipientRecord(record = rcrec, data = cachedRecipientData.get, aivailableTaxYears = List(TaxYear(2016))) + val trRecipientData = Some(CacheData(transferor = Some(trrec), recipient = Some(recrecord), notification = Some(NotificationRecord(EmailAddress("example@example.com"))))) + + val testComponent = makeTestComponent("user_happy_path", transferorRecipientData = trRecipientData) + val controllerToTest = testComponent.controller + val request = testComponent.request.withFormUrlEncodedBody(data = ("applyForCurrentYear" -> "false")) + val result = controllerToTest.eligibleYearsAction(request) + + status(result) shouldBe OK + val document = Jsoup.parse(contentAsString(result)) + document.getElementById("message").text() shouldBe "You haven't selected any tax years to apply for" + } + + } + + "Calling previous year page" should{ + "not display previous years if user only eligible for current year" in new WithApplication(fakeApplication) { + val trrec = UserRecord(cid = Cids.cid1, timestamp = "2015") + val rcrec = UserRecord(cid = 123456, timestamp = "2015") + val cacheRecipientFormData = Some(RecipientDetailsFormInput(name = "foo", lastName = "bar", gender = Gender("M"), nino = Nino(Ninos.ninoWithLOA1))) + val rcdata = RegistrationFormInput(name = "foo", lastName = "bar", gender = Gender("M"), nino = Nino(Ninos.ninoWithLOA1), dateOfMarriage = new LocalDate(2016, 4, 10)) + val recrecord = RecipientRecord(record = rcrec, data = rcdata,aivailableTaxYears = List(TaxYear(2016))) + val trRecipientData = Some(CacheData( + transferor = Some(trrec), + recipient = Some(recrecord), + notification = Some(NotificationRecord(EmailAddress("example123@example.com"))), + recipientDetailsFormData = cacheRecipientFormData)) + + + val testComponent = makeTestComponent("user_happy_path", transferorRecipientData = trRecipientData) + val controllerToTest = testComponent.controller + val request = testComponent.request.withFormUrlEncodedBody(data = ("applyForCurrentYear" -> "true")) + val result = controllerToTest.eligibleYearsAction(request) + + status(result) shouldBe SEE_OTHER + redirectLocation(result) shouldBe Some("/marriage-allowance-application/confirm-your-email") + } + + "not display current year if user only eligible for only previous year" in new WithApplication(fakeApplication) { + val trrec = UserRecord(cid = Cids.cid1, timestamp = "2015") + val rcrec = UserRecord(cid = 123456, timestamp = "2015") + val cacheRecipientFormData = Some(RecipientDetailsFormInput(name = "foo", lastName = "bar", gender = Gender("M"), nino = Nino(Ninos.ninoWithLOA1))) + val rcdata = RegistrationFormInput(name = "foo", lastName = "bar", gender = Gender("M"), nino = Nino(Ninos.ninoWithLOA1), dateOfMarriage = new LocalDate(2010, 4, 10)) + val recrecord = RecipientRecord(record = rcrec, data = rcdata,aivailableTaxYears = List(TaxYear(2015))) + val trRecipientData = Some(CacheData( + transferor = Some(trrec), + recipient = Some(recrecord), + notification = Some(NotificationRecord(EmailAddress("example123@example.com"))), + recipientDetailsFormData = cacheRecipientFormData)) + + + val testComponent = makeTestComponent("user_happy_path", transferorRecipientData = trRecipientData) + val controllerToTest = testComponent.controller + val request = testComponent.request + val result = controllerToTest.eligibleYears(request) + + status(result) shouldBe OK + val document = Jsoup.parse(contentAsString(result)) + document.getElementById("heading").text() shouldBe "You can apply for earlier tax years" } + "display the generic previous year page" in new WithApplication(fakeApplication) { + val trrec = UserRecord(cid = Cids.cid1, timestamp = "2015") + val rcrec = UserRecord(cid = 123456, timestamp = "2015") + val cacheRecipientFormData = Some(RecipientDetailsFormInput(name = "foo", lastName = "bar", gender = Gender("M"), nino = Nino(Ninos.ninoWithLOA1))) + val rcdata = RegistrationFormInput(name = "foo", lastName = "bar", gender = Gender("M"), nino = Nino(Ninos.ninoWithLOA1), dateOfMarriage = new LocalDate(2011, 4, 10)) + val recrecord = RecipientRecord(record = rcrec, data = rcdata,aivailableTaxYears = List(TaxYear(2014),TaxYear(2015),TaxYear(2016))) + val trRecipientData = Some(CacheData( + transferor = Some(trrec), + recipient = Some(recrecord), + notification = Some(NotificationRecord(EmailAddress("example123@example.com"))), + recipientDetailsFormData = cacheRecipientFormData)) + + val testComponent = makeTestComponent("user_happy_path", transferorRecipientData = trRecipientData) + val controllerToTest = testComponent.controller + val request = testComponent.request.withFormUrlEncodedBody(data = ("applyForCurrentYear" -> "true")) + val result = controllerToTest.eligibleYearsAction(request) + + status(result) shouldBe OK + val document = Jsoup.parse(contentAsString(result)) + document.getElementById("heading").text() shouldBe "You can apply for earlier tax years" + } } + "Calling earlier years select page" should { + + "progressing by selecting continue on previous year page " in new WithApplication(fakeApplication) { + val trrec = UserRecord(cid = Cids.cid1, timestamp = "2015") + val rcrec = UserRecord(cid = 123456, timestamp = "2015") + val cacheRecipientFormData = Some(RecipientDetailsFormInput(name = "foo", lastName = "bar", gender = Gender("M"), nino = Nino(Ninos.ninoWithLOA1))) + val rcdata = RegistrationFormInput(name = "foo", lastName = "bar", gender = Gender("M"), nino = Nino(Ninos.ninoWithLOA1), dateOfMarriage = new LocalDate(2011, 4, 10)) + val recrecord = RecipientRecord(record = rcrec, data = rcdata,aivailableTaxYears = List(TaxYear(2014),TaxYear(2015),TaxYear(2016))) + val trRecipientData = Some(CacheData( + transferor = Some(trrec), + recipient = Some(recrecord), + notification = Some(NotificationRecord(EmailAddress("example123@example.com"))), + recipientDetailsFormData = cacheRecipientFormData)) + + val testComponent = makeTestComponent("user_happy_path", transferorRecipientData = trRecipientData) + val controllerToTest = testComponent.controller + val request = testComponent.request + val result = controllerToTest.previousYears(request) + + status(result) shouldBe OK + val document = Jsoup.parse(contentAsString(result)) + document.getElementById("heading").text() shouldBe "Confirm the earlier years you want to apply for" + } + } + + "Calling confirm and apply page" should { "read keystore" in new WithApplication(fakeApplication) { @@ -552,7 +665,7 @@ class MarriageAllowanceControllerTest extends UnitSpec with TestUtility { val tags = Map("X-Session-ID" -> ("session-ID-" + Ninos.ninoHappyPath)) eventsShouldMatch(event, "TxSuccessful", detailsToCheck, tags) } -// + "send audit event if relationship is already created" in new WithApplication(fakeApplication) { val trrec = UserRecord(cid = Cids.cid1, timestamp = "2015", name = None) val rcrec = UserRecord(cid = Cids.cid2, timestamp = "2015", name = None)