Skip to content

Commit

Permalink
added future DOB validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Mudiwa Matanda authored and Mudiwa Matanda committed Nov 12, 2024
1 parent 5802e61 commit 072673c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
8 changes: 7 additions & 1 deletion go-app-ussd_clinic_rapidpro.js
Original file line number Diff line number Diff line change
Expand Up @@ -911,13 +911,19 @@ go.app = function() {
"Enter the day that baby was born as a number. For example if baby was born on 12th May, type in 12"
].join("\n"));
}
if (date > current_date){
return $(
"Sorry, that date is in the future. Please enter a valid date."
);
}
if (!date.isBetween(current_date.clone().add(-2, "years"), current_date.add(1, "days")) ) {
return $(
"Unfortunately MomConnect doesn't send messages to children older " +
"than 2 years. Please try again by entering the day the baby was " +
"born as a number, e.g. 12."
);
}
}

},
next: "state_id_type"
});
Expand Down
5 changes: 5 additions & 0 deletions src/ussd_clinic_rapidpro.js
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,11 @@ go.app = function() {
"Enter the day that baby was born as a number. For example if baby was born on 12th May, type in 12"
].join("\n"));
}
if (date > current_date){
return $(
"Sorry, that date is in the future. Please enter a valid date."
);
}
if (!date.isBetween(current_date.clone().add(-2, "years"), current_date.add(1, "days")) ) {
return $(
"Unfortunately MomConnect doesn't send messages to children older " +
Expand Down
11 changes: 11 additions & 0 deletions test/ussd_clinic_rapidpro.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,17 @@ describe("ussd_clinic app", function() {
})
.run();
});
it("should return an error if the date of birth is in the future", function() {
return tester
.setup.user.state("state_birth_day")
.setup.user.answer("state_birth_month","2020-04")
.input("1")
.check.interaction({
reply:
"Sorry, that date is in the future. Please enter a valid date."
})
.run();
});
it("should pass if the date of birth is today", function() {
return tester
.setup.user.state("state_birth_day")
Expand Down

0 comments on commit 072673c

Please sign in to comment.