Skip to content

Commit

Permalink
Merge pull request #69 from hmrc/ATED-3662
Browse files Browse the repository at this point in the history
updated address selection page to show error
  • Loading branch information
sinead-fay authored Sep 12, 2017
2 parents a32d107 + 1af34f6 commit a19af78
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ trait AddressLookupController extends PropertyDetailsHelpers with ClientHelper w
}
},
searchCriteria => {
addressLookupService.findById(searchCriteria.selected).flatMap(foundProperty =>
addressLookupService.findById(searchCriteria.selected.get).flatMap(foundProperty =>
(id, foundProperty) match {
case (Some(x), Some(found)) =>
propertyDetailsService.saveDraftPropertyDetailsAddress(x, found).flatMap(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ trait SelectExistingReturnAddressController extends PropertyDetailsHelpers with
formWithError => {
summaryReturnService.retrieveCachedPreviousReturnAddressList.map { prevReturns =>
val addressList = prevReturns.getOrElse(Nil)
BadRequest(views.html.propertyDetails.selectPreviousReturn(periodKey, returnType, addressSelectedForm, addressList, getBackLink(periodKey, returnType)))
BadRequest(views.html.propertyDetails.selectPreviousReturn(periodKey, returnType, formWithError, addressList, getBackLink(periodKey, returnType)))
}
},
addressSelectForm => {
val formBundleNum = addressSelectForm.selected
val formBundleNum = addressSelectForm.selected.get
for {
formBundleReturnOpt <- formBundleReturnService.getFormBundleReturns(formBundleNum)
result <- formBundleReturnOpt match {
Expand Down
12 changes: 3 additions & 9 deletions app/forms/AddressLookupForms.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,8 @@ object AddressLookupForms {
)(AddressLookup.apply)(AddressLookup.unapply)
)

lazy val mandatoryRadio = optional(text)
.verifying("ated.address-lookup.error.non-selected.field", _.isDefined)
.transform({ s: Option[String] => s.getOrElse("") }, { v: String => Some(v) })
val addressSelectedForm = Form(mapping(
"selected" -> optional(text).verifying(Messages("ated.address-lookup.error.non-selected.field"), _.isDefined)
)(AddressSelected.apply)(AddressSelected.unapply))

val addressSelectedForm = Form(

mapping(
"selected" -> mandatoryRadio
)(AddressSelected.apply)(AddressSelected.unapply)
)
}
2 changes: 1 addition & 1 deletion app/models/AddressLookupModels.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ object AddressLookup {
implicit val formats = Json.format[AddressLookup]
}

case class AddressSelected(selected: String)
case class AddressSelected(selected: Option[String])

object AddressSelected {
implicit val formats = Json.format[AddressSelected]
Expand Down
3 changes: 2 additions & 1 deletion app/views/propertyDetails/selectPreviousReturn.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
@(periodKey: Int, returnType: String, addressResultsForm: Form[AddressSelected], prevReturns: Seq[PreviousReturns], backLink: Option[String])(implicit atedContext: AtedContext, messages: Messages)

@atedMain(title = Messages("ated.select-past-return.title"), attorney = atedContext.user.authContext.attorney) {
@pageHeadersAndError(backLink, "pre-header", Messages("ated.return-type.pre-header"), "header", Messages("ated.select-past-return.header"), None)
@pageHeadersAndError(backLink, "pre-header", Messages("ated.return-type.pre-header"), "header", Messages("ated.select-past-return.header"),
Some(atedErrorSummary(addressResultsForm, "ated.select-past-return.general")))

<div class="form-group">
@if(!prevReturns.isEmpty) {
Expand Down
1 change: 1 addition & 0 deletions conf/messages
Original file line number Diff line number Diff line change
Expand Up @@ -1456,3 +1456,4 @@ yes-no.error.mandatory = The {0} question must be answered

ated.select-past-return.title = Select the previous return that this new return relates to
ated.select-past-return.header = Select the previous return that this new return relates to
ated.select-past-return.general.selected = There is a problem with the address option
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ class AddressLookupControllerSpec extends PlaySpec with OneServerPerSuite with M
"submitting an invalid request should fail and return to the search results page" in {
val searchCriteria = AddressLookup("XX1 1XX", None)
val searchResults = AddressSearchResults(searchCriteria, Nil)
saveWithAuthorisedUser(None, 2015, Json.toJson(AddressSelected("")), Some(searchResults), None) {
saveWithAuthorisedUser(None, 2015, Json.toJson(AddressSelected(None)), Some(searchResults), None) {
result =>
status(result) must be(BAD_REQUEST)
val document = Jsoup.parse(contentAsString(result))
Expand All @@ -223,7 +223,7 @@ class AddressLookupControllerSpec extends PlaySpec with OneServerPerSuite with M
"submitting an invalid request should fail and return to the search results page even with no cached data" in {
val searchCriteria = AddressLookup("XX1 1XX", None)
val searchResults = AddressSearchResults(searchCriteria, Nil)
saveWithAuthorisedUser(None, 2015, Json.toJson(AddressSelected("")), None, None) {
saveWithAuthorisedUser(None, 2015, Json.toJson(AddressSelected(None)), None, None) {
result =>
status(result) must be(BAD_REQUEST)
val document = Jsoup.parse(contentAsString(result))
Expand All @@ -236,7 +236,7 @@ class AddressLookupControllerSpec extends PlaySpec with OneServerPerSuite with M
val searchCriteria = AddressLookup("XX1 1XX", None)
val results = AddressSearchResults(searchCriteria,List(address1, address2, address3))

saveWithAuthorisedUser(None, 2015, Json.toJson(AddressSelected("1")), Some(results), None) {
saveWithAuthorisedUser(None, 2015, Json.toJson(AddressSelected(Some("1"))), Some(results), None) {
result =>
status(result) must be(BAD_REQUEST)
val document = Jsoup.parse(contentAsString(result))
Expand All @@ -249,7 +249,7 @@ class AddressLookupControllerSpec extends PlaySpec with OneServerPerSuite with M
val searchCriteria = AddressLookup("XX1 1XX", None)
val results = AddressSearchResults(searchCriteria,List(address1, address2, address3))

saveWithAuthorisedUser(None, 2015, Json.toJson(AddressSelected("1")), None, None) {
saveWithAuthorisedUser(None, 2015, Json.toJson(AddressSelected(Some("1"))), None, None) {
result =>
status(result) must be(BAD_REQUEST)
val document = Jsoup.parse(contentAsString(result))
Expand All @@ -265,7 +265,7 @@ class AddressLookupControllerSpec extends PlaySpec with OneServerPerSuite with M
when(mockPropertyDetailsService.createDraftPropertyDetailsAddress(Matchers.eq(2015), Matchers.eq(foundProperty))(Matchers.any(), Matchers.any())).thenReturn(Future.successful("newId"))
when(mockBackLinkCache.saveBackLink(Matchers.any(), Matchers.any())(Matchers.any())).thenReturn(Future.successful(None))

saveWithAuthorisedUser(None, 2015, Json.toJson(AddressSelected("1")), None, Some(foundProperty)) {
saveWithAuthorisedUser(None, 2015, Json.toJson(AddressSelected(Some("1"))), None, Some(foundProperty)) {
result =>
status(result) must be(SEE_OTHER)
redirectLocation(result).get must include("/ated/liability/create/title/view/newId")
Expand All @@ -277,7 +277,7 @@ class AddressLookupControllerSpec extends PlaySpec with OneServerPerSuite with M
when(mockPropertyDetailsService.saveDraftPropertyDetailsAddress(Matchers.any(), Matchers.eq(foundProperty))(Matchers.any(), Matchers.any())).thenReturn(Future.successful("1"))
when(mockBackLinkCache.saveBackLink(Matchers.any(), Matchers.any())(Matchers.any())).thenReturn(Future.successful(None))

saveWithAuthorisedUser(Some("1"), 2015, Json.toJson(AddressSelected("1")), None, Some(foundProperty)) {
saveWithAuthorisedUser(Some("1"), 2015, Json.toJson(AddressSelected(Some("1"))), None, Some(foundProperty)) {
result =>
status(result) must be(SEE_OTHER)
redirectLocation(result).get must include("/ated/liability/create/title/view/1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class SelectExistingReturnAddressControllerSpec extends PlaySpec with OneServerP


"submitting an invalid request should fail and return to the search results page" in {
saveWithAuthorisedUser(None, prevReturns, Json.toJson(AddressSelected(""))) {
saveWithAuthorisedUser(None, prevReturns, Json.toJson(AddressSelected(None))) {
result =>
status(result) must be(BAD_REQUEST)
val document = Jsoup.parse(contentAsString(result))
Expand All @@ -151,7 +151,7 @@ class SelectExistingReturnAddressControllerSpec extends PlaySpec with OneServerP
}

"submitting an invalid request should fail and return to the search results page even with cached data" in {
saveWithAuthorisedUser(None, prevReturns, Json.toJson(AddressSelected(""))) {
saveWithAuthorisedUser(None, prevReturns, Json.toJson(AddressSelected(None))) {
result =>
status(result) must be(BAD_REQUEST)
val document = Jsoup.parse(contentAsString(result))
Expand All @@ -161,7 +161,7 @@ class SelectExistingReturnAddressControllerSpec extends PlaySpec with OneServerP
}

"submitting an invalid request should fail and return to the search results page even with no cached data" in {
saveWithAuthorisedUser(None, None, Json.toJson(AddressSelected(""))) {
saveWithAuthorisedUser(None, None, Json.toJson(AddressSelected(None))) {
result =>
status(result) must be(BAD_REQUEST)
val document = Jsoup.parse(contentAsString(result))
Expand All @@ -177,14 +177,14 @@ class SelectExistingReturnAddressControllerSpec extends PlaySpec with OneServerP
val formBundlePropertyDetails = FormBundlePropertyDetails(Some("title here"), formBundleAddress, Some("additional details"))
val viewReturn = FormBundleReturn("2014", formBundlePropertyDetails, Some(new LocalDate("2013-10-10")), Some(BigDecimal(100)), Some("ABCdefgh"), Some("PromABCdefgh"), Some("1234"), true, true, new LocalDate("2015-05-10"), BigDecimal(9324), "1234567891", List(formBundleProp))

saveWithAuthorisedUser(Some(viewReturn), prevReturns, Json.toJson(AddressSelected("12345678"))) {
saveWithAuthorisedUser(Some(viewReturn), prevReturns, Json.toJson(AddressSelected(Some("12345678")))) {
result =>
status(result) must be(SEE_OTHER)
}
}

"submitting an invalid form bundle number request should redirect to Account Summary Page" in {
saveWithAuthorisedUser(formBundleReturn = None, prevReturns, Json.toJson(AddressSelected("12345678"))) {
saveWithAuthorisedUser(formBundleReturn = None, prevReturns, Json.toJson(AddressSelected(Some("12345678")))) {
result =>
status(result) must be(SEE_OTHER)
}
Expand Down

0 comments on commit a19af78

Please sign in to comment.