Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADR-1425: Additional validations for DSD #221

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Conversation

sini-george
Copy link
Contributor

No description provided.

@platops-pr-bot
Copy link

args = args
)

private def pureAlcoholBigDecimalFormatter(fieldKey: String) = new BigDecimalFieldFormatter(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for BigDecimal in the name

formatVolume(key, data).fold(
errors => Left(errors),
volumes =>
if (volumes.totalLitresVolume < volumes.pureAlcoholVolume) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fails if both are negative. e.g. -100 litres of product, -10 litres of pure alcohol

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is being discussed with Tom

private def checkValues(key: String, data: Map[String, String]): Either[Seq[FormError], DutySuspendedVolume] =
formatVolume(key, data).fold(
errors => Left(errors),
volumes =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably the simplest way to deal with this is check the following:

If litres > 0
check pure_alcohol > 0
check pure alcohol <= litres
else if litres = 0
check pure alcohol = 0
else [therefore litres < 0]
check pure alcohol < 0
check abs(pure_alcohol) <= abs(litres)

Probably best to spell it out (including the abs) to prioritise readability and correctness checking rather than the minimum number of cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per the screenshot in the ticket, this doesn't cover all the cases mentioned there


"fail to bind when pure alcohol volume is higher than total litres value" in {
val data = Map(
"volumes.totalLitresVolume" -> "0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should use a non-zero case here


"fail to bind when total litres value is zero and pure alcohol volume is negative" in {
val data = Map(
"volumes.totalLitresVolume" -> "0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non-zero case here

@@ -255,8 +255,8 @@ class AdrReturnSubmissionServiceImpl @Inject() (
AdrDutySuspendedProduct(
regime = AdrDutySuspendedAlcoholRegime.Beer,
suspendedQuantity = AdrAlcoholQuantity(
dutySuspendedBeer.totalBeer,
dutySuspendedBeer.pureAlcoholInBeer
dutySuspendedBeer.totalLitresVolume,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would break any returns in progress but not submitted - has there been sign off for this?

One way around this is to have a trait for the models with getters which extract the appropriate fields using a common method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this has been addressed in the latest commit

)
}

"fail to bind when total litres value is negative and pure alcohol volume is a higher negative" in {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should work, since abs(totalities) > abs(pure alcohol) - however the checks are wrong.

formatVolume(key, data).fold(
errors => Left(errors),
volumes =>
if (volumes.total < volumes.pureAlcohol) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't be right if total and pureAlcohol is negative

-100 product, -10 lpa fails here.

import pages.QuestionPage
import play.api.libs.json.JsPath

case object DutySuspendedBeerPage extends QuestionPage[DutySuspendedBeer] {
case object DutySuspendedBeerPage extends QuestionPage[DutySuspendedVolume] {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't use the original fields.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the field names are being generated now on DutySuspendedVolume model, this also helps in using the custom formatter


"fail to bind when pure alcohol volume is higher than total litres value" in {
val data = Map(
s"volumes.$totalVolumeKey" -> "0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should test with non-zero value


"fail to bind when total litres value is zero and pure alcohol volume is negative" in {
val data = Map(
s"volumes.$totalVolumeKey" -> "0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should test with a non-zero value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants