Skip to content

Commit

Permalink
HMA-8912: Added new error in PensionValidator for 10millions (#121)
Browse files Browse the repository at this point in the history
* HMA-8912: Added new error in PensionValidator for 10millions

* spelling
  • Loading branch information
ngoulongkam authored Aug 5, 2024
1 parent 935443c commit 4165ba2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
- Added new validator to PensionValidator to check for amount lower than 10 millions.

## [2.13.0] - 2024-07-30Z
- Updated internal calculation to force Scottish Rate if consumer set `userPaysScottishTax` to true.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import uk.gov.hmrc.calculator.utils.convertWageToYearly
import uk.gov.hmrc.calculator.utils.validation.HoursDaysValidator.isTwoDecimalPlacesOrFewer
import kotlin.jvm.JvmSynthetic

@Suppress("TooManyFunctions")
object PensionValidator {

fun isValidMonthlyPension(
Expand Down Expand Up @@ -67,7 +68,11 @@ object PensionValidator {
if (isPensionBelowZero(inputValue)) listOfError.add(PensionError.BELOW_ZERO)
if (isPensionPercentageAboveHundred(inputValue, pensionMethod))
listOfError.add(PensionError.ABOVE_HUNDRED_PERCENT)
validatePensionInputValidDecimal(monthlyPension, pensionMethod)?.let { listOfError.add(it) }
if (isTenMillionOrAbove(monthlyPension)) {
listOfError.add(PensionError.AMOUNT_REACHED_TEN_MILLIONS)
} else {
validatePensionInputValidDecimal(monthlyPension, pensionMethod)?.let { listOfError.add(it) }
}

listOfError.sortBy { it.priority }
return listOfError
Expand All @@ -90,6 +95,10 @@ object PensionValidator {
return "([0-9])+(\\.\\d{1,2})".toRegex().matches(yearlyPension.toString())
}

private fun isTenMillionOrAbove(monthlyPension: Double): Boolean {
return monthlyPension >= 10000000.0
}

private fun isPensionBelowZero(yearlyPension: Double): Boolean {
return yearlyPension <= 0.0
}
Expand Down Expand Up @@ -117,11 +126,12 @@ object PensionValidator {

enum class PensionError(val priority: Int) {
INVALID_FORMAT(1),
INVALID_AMOUNT_DECIMAL(2),
INVALID_PERCENTAGE_DECIMAL(3),
BELOW_ZERO(4),
ABOVE_WAGE(5),
ABOVE_HUNDRED_PERCENT(6),
ABOVE_ANNUAL_ALLOWANCE(7),
AMOUNT_REACHED_TEN_MILLIONS(2),
INVALID_AMOUNT_DECIMAL(3),
INVALID_PERCENTAGE_DECIMAL(4),
BELOW_ZERO(5),
ABOVE_WAGE(6),
ABOVE_HUNDRED_PERCENT(7),
ABOVE_ANNUAL_ALLOWANCE(8),
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,16 @@ class PensionValidatorTests {
assertEquals(listOfError, PensionValidator.validateValidInputPensionInput(monthlyPension, pensionMethod))
}

@Test
fun `GIVEN amount is ten million or more AND pension method is amount in pounds WHEN validateValidInputPensionInput THEN return AMOUNT_REACHED_TEN_MILLIONS`() {
val monthlyPension = 10000000.0
val pensionMethod = PensionMethod.MONTHLY_AMOUNT_IN_POUNDS

val listOfError = mutableListOf(PensionValidator.PensionError.AMOUNT_REACHED_TEN_MILLIONS)

assertEquals(listOfError, PensionValidator.validateValidInputPensionInput(monthlyPension, pensionMethod))
}

@Test
fun `GIVEN amount is less then zero WHEN validateValidInputPensionInput THEN return BELOW_ZERO`() {
val monthlyPension = -10.0
Expand Down

0 comments on commit 4165ba2

Please sign in to comment.