Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import uk.gov.hmrc.govukfrontend.views.viewmodels.table.{Table, TableRow}
import uk.gov.hmrc.http.NotFoundException
import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, PropertyLinkingAction}
import uk.gov.hmrc.ngrraldfrontend.config.AppConfig
import uk.gov.hmrc.ngrraldfrontend.models.RaldUserAnswers
import uk.gov.hmrc.ngrraldfrontend.models.{NGRDate, RaldUserAnswers}
import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio
import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio.buildRadios
import uk.gov.hmrc.ngrraldfrontend.models.components.NavBarPageContents.createDefaultNavBar
Expand All @@ -46,6 +46,7 @@ class RentPeriodsController @Inject()(view: RentPeriodView,
mcc: MessagesControllerComponents
)(implicit appConfig: AppConfig, ec:ExecutionContext) extends FrontendController(mcc) with I18nSupport {


def firstTable(userAnswers: RaldUserAnswers)(implicit messages:Messages): Table =
Table(
rows = Seq(
Expand All @@ -55,7 +56,7 @@ class RentPeriodsController @Inject()(view: RentPeriodView,
),
TableRow(
content = Text(userAnswers.provideDetailsOfFirstSecondRentPeriod.map{ dates =>
dates.firstDateStart
NGRDate.formatDate(dates.firstDateStart)
}.getOrElse(""))
)
),
Expand All @@ -65,22 +66,22 @@ class RentPeriodsController @Inject()(view: RentPeriodView,
),
TableRow(
content = Text(userAnswers.provideDetailsOfFirstSecondRentPeriod.map{ dates =>
dates.firstDateEnd
NGRDate.formatDate(dates.firstDateEnd)
}.getOrElse(""))
)
),
if(userAnswers.provideDetailsOfFirstSecondRentPeriod.nonEmpty){
Seq(
TableRow(
content = Text(messages("rentPeriods.first.rentValue"))
),
TableRow(
content = Text(userAnswers.provideDetailsOfFirstSecondRentPeriod.map { dates =>
dates.firstRentPeriodAmount.get
}.getOrElse(""))
)
)
}else(Seq()),
userAnswers.provideDetailsOfFirstSecondRentPeriod.map{ userAnswers =>
userAnswers.firstRentPeriodAmount match
case Some(answer) => Seq(
TableRow(
content = Text(messages("rentPeriods.first.rentValue"))
),
TableRow(
content = Text(answer)
)
)
case None => Seq()
}.getOrElse(Seq()),
Seq(
TableRow(
content = Text(messages("rentPeriods.first.doYouPay"))
Expand Down Expand Up @@ -108,7 +109,7 @@ class RentPeriodsController @Inject()(view: RentPeriodView,
),
TableRow(
content = Text(userAnswers.provideDetailsOfFirstSecondRentPeriod.map{ dates =>
dates.secondDateStart
NGRDate.formatDate(dates.secondDateStart)
}.getOrElse(""))
)
),
Expand All @@ -118,7 +119,7 @@ class RentPeriodsController @Inject()(view: RentPeriodView,
),
TableRow(
content = Text(userAnswers.provideDetailsOfFirstSecondRentPeriod.map { dates =>
dates.secondDateEnd
NGRDate.formatDate(dates.secondDateEnd)
}.getOrElse(""))
)
),
Expand All @@ -128,7 +129,7 @@ class RentPeriodsController @Inject()(view: RentPeriodView,
),
TableRow(
content = Text(userAnswers.provideDetailsOfFirstSecondRentPeriod.map { dates =>
dates.firstRentPeriodAmount.get
dates.secondHowMuchIsRent
}.getOrElse(""))
)
)
Expand Down
16 changes: 16 additions & 0 deletions app/uk/gov/hmrc/ngrraldfrontend/models/NGRDate.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import play.api.data.Mapping
import play.api.libs.json.{Json, OFormat}

import java.time.LocalDate
import java.time.format.DateTimeFormatter
import java.util.Locale

final case class NGRDate(day: String, month: String, year: String) {
lazy val ngrDate: LocalDate = LocalDate.of(year.toInt, month.toInt, day.toInt)
Expand All @@ -33,6 +35,20 @@ final case class NGRDate(day: String, month: String, year: String) {
object NGRDate {
implicit val format: OFormat[NGRDate] = Json.format[NGRDate]


def formatDate(dateString: String): String = {
val parts = dateString.split("-").map(_.toInt)
val year = parts(0)
val month = f"${parts(1)}%02d"
val day = f"${parts(2)}%02d"
val paddedDate = s"$year-$month-$day"
val inputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd")
val outputFormatter = DateTimeFormatter.ofPattern("d MMMM yyyy", Locale.ENGLISH)
val date = LocalDate.parse(paddedDate, inputFormatter)
date.format(outputFormatter)
}


def unapply(ngrDate: NGRDate): Option[(String, String, String)] =
Some(ngrDate.day, ngrDate.month, ngrDate.year)
}
Expand Down
14 changes: 7 additions & 7 deletions app/uk/gov/hmrc/ngrraldfrontend/repo/RaldRepo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -136,19 +136,19 @@ case class RaldRepo @Inject()(mongo: MongoComponent,
): Future[Option[RaldUserAnswers]] = {

val updates = Seq(
Updates.set("ProvideDetailsOfFirstSecondRentPeriod.firstDateStart", firstDateStart),
Updates.set("ProvideDetailsOfFirstSecondRentPeriod.firstDateEnd", firstDateEnd),
Updates.set("ProvideDetailsOfFirstSecondRentPeriod.firstRentPeriodRadio", firstRentPeriodRadio match {
Updates.set("provideDetailsOfFirstSecondRentPeriod.firstDateStart", firstDateStart),
Updates.set("provideDetailsOfFirstSecondRentPeriod.firstDateEnd", firstDateEnd),
Updates.set("provideDetailsOfFirstSecondRentPeriod.firstRentPeriodRadio", firstRentPeriodRadio match {
case answer if (answer == "yesPayedRent") => true
case _ => false
}),
Updates.set("ProvideDetailsOfFirstSecondRentPeriod.firstRentPeriodAmount", firstRentPeriodAmount match {
Updates.set("provideDetailsOfFirstSecondRentPeriod.firstRentPeriodAmount", firstRentPeriodAmount match {
case Some(value) => value.toString()
case _ => null
}),
Updates.set("ProvideDetailsOfFirstSecondRentPeriod.secondDateStart", secondDateStart),
Updates.set("ProvideDetailsOfFirstSecondRentPeriod.secondDateEnd", secondDateEnd),
Updates.set("ProvideDetailsOfFirstSecondRentPeriod.secondHowMuchIsRent", secondHowMuchIsRent.toString)
Updates.set("provideDetailsOfFirstSecondRentPeriod.secondDateStart", secondDateStart),
Updates.set("provideDetailsOfFirstSecondRentPeriod.secondDateEnd", secondDateEnd),
Updates.set("provideDetailsOfFirstSecondRentPeriod.secondHowMuchIsRent", secondHowMuchIsRent.toString)
)

findAndUpdateByCredId(credId, updates: _*)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ class RentPeriodsControllerSpec extends ControllerSpecSupport {
selectedProperty = property,
provideDetailsOfFirstSecondRentPeriod =
Some(ProvideDetailsOfFirstSecondRentPeriod(
firstDateStart = "",
firstDateEnd = "",
firstDateStart = "2016-12-12",
firstDateEnd = "2017-12-12",
firstRentPeriodRadio = true,
firstRentPeriodAmount = Some(""),
secondDateStart = "",
secondDateEnd = "",
secondHowMuchIsRent = "")))))
firstRentPeriodAmount = Some("10000"),
secondDateStart = "2018-12-12",
secondDateEnd = "2019-12-12",
secondHowMuchIsRent = "10000")))))
val result = controller.show()(authenticatedFakeRequest())
status(result) mustBe OK
val content = contentAsString(result)
Expand Down
20 changes: 18 additions & 2 deletions test/uk/gov/hmrc/ngrraldfrontend/repo/RaldRepoSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,24 @@ class RaldRepoSpec extends TestSupport with TestData
result mustBe actual
}


"handle yesPayedRent value correctly by setting boolean to true and take first rent period amount" in {
val result = await(repository.insertProvideDetailsOfFirstSecondRentPeriod(
val expected = RaldUserAnswers(
credId,
NewAgreement,
property,
provideDetailsOfFirstSecondRentPeriod = Some(ProvideDetailsOfFirstSecondRentPeriod(
firstDateStart = "2025-01-01",
firstDateEnd = "2025-01-31",
firstRentPeriodRadio = true,
firstRentPeriodAmount = Some("1000"),
secondDateStart = "2025-02-01",
secondDateEnd = "2025-02-28",
secondHowMuchIsRent = "1000"
))
)

await(repository.insertProvideDetailsOfFirstSecondRentPeriod(
credId = credId,
firstDateStart = "2025-01-01",
firstDateEnd = "2025-01-31",
Expand All @@ -278,7 +294,7 @@ class RaldRepoSpec extends TestSupport with TestData

val actual = await(repository.findByCredId(credId))

result mustBe actual
actual mustBe Some(expected)
}

"insert rent based on with other desc successfully" in {
Expand Down