Skip to content

Commit

Permalink
SDP-688 - Verification DOB validation missing when date is in the fut…
Browse files Browse the repository at this point in the history
…ure (#101)
  • Loading branch information
marwen-abid authored Nov 20, 2023
1 parent ac1423c commit 251b625
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ func (iv *DisbursementInstructionsValidator) ValidateInstruction(instruction *da
// validate verification field
// date of birth with format 2006-01-02
if iv.verificationField == data.VerificationFieldDateOfBirth {
_, err := time.Parse("2006-01-02", verification)
dob, err := time.Parse("2006-01-02", verification)
iv.CheckError(err, fmt.Sprintf("line %d - birthday", lineNumber), "invalid date of birth format. Correct format: 1990-01-01")

// check if date of birth is in the past
iv.Check(dob.Before(time.Now()), fmt.Sprintf("line %d - birthday", lineNumber), "date of birth cannot be in the future")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,20 @@ func Test_DisbursementInstructionsValidator_ValidateAndGetInstruction(t *testing
"line 3 - birthday": "invalid date of birth format. Correct format: 1990-01-01",
},
},
{
name: "date of birth in the future",
actual: &data.DisbursementInstruction{
Phone: "+380445555555",
ID: "123456789",
Amount: "100.5",
VerificationValue: "2090-01-01",
},
lineNumber: 3,
hasErrors: true,
expectedErrors: map[string]interface{}{
"line 3 - birthday": "date of birth cannot be in the future",
},
},
}

for _, tt := range tests {
Expand Down

0 comments on commit 251b625

Please sign in to comment.