Skip to content

Commit

Permalink
Merge pull request #597 from hmrc/CVSRP-4763
Browse files Browse the repository at this point in the history
CVSRP-4763 allows furlough period start to be stored in second calcul…
  • Loading branch information
mywyau authored Mar 26, 2021
2 parents 48ef456 + e9b2836 commit 525d0f9
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/handlers/FastJourneyUserAnswersHandler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ trait FastJourneyUserAnswersHandler extends DataExtractor with UserAnswersHelper

private val keepFurloughPeriod: Kleisli[Option, UserAnswersState, UserAnswersState] = Kleisli(answersState =>
for {
furlough <- extractFurloughWithinClaimV(answersState.original).toOption
furlough <- extractFurloughPeriodDatesV(answersState.original).toOption
withStart <- answersState.updated.set(FurloughStartDatePage, furlough.start).toOption
withEnd <- withStart.set(FurloughEndDatePage, furlough.end).toOption
} yield UserAnswersState(withEnd, answersState.original))
Expand Down
14 changes: 11 additions & 3 deletions app/services/FurloughPeriodExtractor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,17 @@ trait FurloughPeriodExtractor extends LocalDateHelpers {
FurloughWithinClaim(startDate, endDate)
}

def extractFurloughPeriodV(
userAnswers: UserAnswers
): AnswerV[FurloughDates] =
def extractFurloughPeriodDatesV(userAnswers: UserAnswers): AnswerV[FurloughWithinClaim] =
(userAnswers.getV(ClaimPeriodEndPage), extractFurloughPeriodV(userAnswers)).mapN { (claimPeriodEnd, furloughDates) =>
val startDate = furloughDates.start
val endDate = furloughDates match {
case FurloughOngoing(_) => claimPeriodEnd
case FurloughEnded(_, furloughEnd) => furloughEnd
}
FurloughWithinClaim(startDate, endDate)
}

def extractFurloughPeriodV(userAnswers: UserAnswers): AnswerV[FurloughDates] =
userAnswers.getV(FurloughStartDatePage).map { startDate =>
FurloughDates(startDate, userAnswers.getV(FurloughEndDatePage).toOption)
}
Expand Down
87 changes: 85 additions & 2 deletions test/services/FurloughPeriodExtractorSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package services
import java.time.LocalDate

import base.SpecBase
import cats.data.{Chain, Validated}
import cats.scalatest.{ValidatedMatchers, ValidatedValues}
import generators.Generators
import models.{FurloughEnded, FurloughOngoing, FurloughWithinClaim, UserAnswers}
Expand All @@ -29,7 +30,7 @@ import utils.CoreTestData
class FurloughPeriodExtractorSpec
extends SpecBase with CoreTestData with ScalaCheckPropertyChecks with ValidatedMatchers with ValidatedValues with Generators {

"extractFurloughPeriod" must {
"calling the .extractFurloughPeriod()" must {

"span furlough start to furlough end if furlough start and end is set" in new FurloughPeriodExtractor {
val userAnswers = emptyUserAnswers
Expand Down Expand Up @@ -59,11 +60,13 @@ class FurloughPeriodExtractorSpec
}
}

"extractFurloughWithinClaim" must {
"calling the .extractFurloughWithinClaim()" must {

val policyStart: LocalDate = LocalDate.of(2020, 3, 1)
val policyEnd: LocalDate = LocalDate.of(2020, 6, 30)

"use claim period start if after furlough start" in new FurloughPeriodExtractor {

val userAnswers = emptyUserAnswers
.withFurloughStartDate("2020, 3, 1")
.withClaimPeriodStart("2020, 3, 2")
Expand Down Expand Up @@ -248,9 +251,89 @@ class FurloughPeriodExtractorSpec

extractFurloughWithinClaimV(userAnswers) mustBe invalid
}
}

}

"calling the .extractFurloughPeriodDatesV()" when {

"determining the furlough start date" should {

"the furlough start date should just be the furlough start date" in new FurloughPeriodExtractor {

val userAnswers = emptyUserAnswers
.withClaimPeriodEnd("2020, 3, 31")
.withFurloughStartDate("2020, 3, 1")

extractFurloughPeriodDatesV(userAnswers).value.start mustBe LocalDate.of(2020, 3, 1)
}

}

"determining the furlough end date" should {

"user answers furlough is 'FurloughEnded', the furlough end date should be set to the answered furlough end date" in new FurloughPeriodExtractor {

val userAnswers = emptyUserAnswers
.withClaimPeriodEnd("2020, 3, 31")
.withFurloughStartDate("2020, 3, 1")
.withFurloughEndDate("2020, 3, 20")

extractFurloughPeriodDatesV(userAnswers).value.`end` mustBe
LocalDate.of(2020, 3, 20)

}

"user answers furlough is 'FurloughOngoing', the furlough end date should be set to the claim period end date" in new FurloughPeriodExtractor {

val userAnswers = emptyUserAnswers
.withClaimPeriodEnd("2020, 3, 31")
.withFurloughStartDate("2020, 3, 1")

extractFurloughPeriodDatesV(userAnswers).value.`end` mustBe
LocalDate.of(2020, 3, 31)

}
}

"supplied all answers should build a correct FurloughWithinClaim model" should {

"user answers furlough is 'FurloughEnded', the furlough end date should be set to the answered furlough end date" in new FurloughPeriodExtractor {

val userAnswers = emptyUserAnswers
.withClaimPeriodEnd("2020, 3, 31")
.withFurloughStartDate("2020, 3, 5")
.withFurloughEndDate("2020, 3, 20")

extractFurloughPeriodDatesV(userAnswers).value mustBe
FurloughWithinClaim(
start = LocalDate.of(2020, 3, 5),
end = LocalDate.of(2020, 3, 20)
)
}

"user answers furlough is 'FurloughOngoing', the furlough end date should be set to the claim period end date" in new FurloughPeriodExtractor {

val userAnswers = emptyUserAnswers
.withClaimPeriodEnd("2020, 3, 31")
.withFurloughStartDate("2020, 3, 1")

extractFurloughPeriodDatesV(userAnswers).value mustBe FurloughWithinClaim(
start = LocalDate.of(2020, 3, 1),
end = LocalDate.of(2020, 3, 31)
)
}
}

"not supplied any answers" should {

"return invalid" in new FurloughPeriodExtractor {

val userAnswers = emptyUserAnswers

extractFurloughPeriodDatesV(userAnswers) mustBe invalid
}
}
}

}
4 changes: 2 additions & 2 deletions test/utils/UserAnswersBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ trait UserAnswersBuilder extends CoreTestDataBuilder {
def withFurloughStartDate(startDate: String): UserAnswers =
userAnswers.setValue(FurloughStartDatePage, startDate.toLocalDate)

def withFurloughEndDate(startDate: String): UserAnswers =
userAnswers.setValue(FurloughEndDatePage, startDate.toLocalDate)
def withFurloughEndDate(endDate: String): UserAnswers =
userAnswers.setValue(FurloughEndDatePage, endDate.toLocalDate)

def withFurloughInLastTaxYear(answer: Boolean): UserAnswers =
userAnswers.setValue(FurloughInLastTaxYearPage, answer)
Expand Down

0 comments on commit 525d0f9

Please sign in to comment.