diff --git a/internal/serve/validators/disbursement_instructions_validator.go b/internal/serve/validators/disbursement_instructions_validator.go index 71ee96656..e3d2e6149 100644 --- a/internal/serve/validators/disbursement_instructions_validator.go +++ b/internal/serve/validators/disbursement_instructions_validator.go @@ -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") } } diff --git a/internal/serve/validators/disbursement_instructions_validator_test.go b/internal/serve/validators/disbursement_instructions_validator_test.go index 95e53cd79..ebb282a13 100644 --- a/internal/serve/validators/disbursement_instructions_validator_test.go +++ b/internal/serve/validators/disbursement_instructions_validator_test.go @@ -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 {