Skip to content

Commit

Permalink
Merge pull request #648 from praekeltfoundation/fix-future-DOB
Browse files Browse the repository at this point in the history
added future DOB validation
  • Loading branch information
Mudiwa66 authored Nov 12, 2024
2 parents 5802e61 + d6899b6 commit efd6b3e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions go-app-ussd_clinic_rapidpro.js
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,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
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 efd6b3e

Please sign in to comment.