Skip to content

Commit

Permalink
Merge pull request #642 from praekeltfoundation/sigma-1155-CAPI-regis…
Browse files Browse the repository at this point in the history
…tration-USSD

Sigma 1268 ussd baby DoB update
  • Loading branch information
Buhle79 authored Aug 14, 2024
2 parents 146b62b + fb1c5d2 commit 7863972
Show file tree
Hide file tree
Showing 3 changed files with 173 additions and 16 deletions.
32 changes: 24 additions & 8 deletions go-app-ussd_popi_rapidpro.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ go.app = function() {

self.add("state_change_info", function(name) {
var contact = self.im.user.answers.contact;
var answers = self.im.user.answers;
var dates_count, postbirth;
var dates_list = [];
var channel = _.get(contact, "fields.preferred_channel");
Expand Down Expand Up @@ -564,6 +565,7 @@ go.app = function() {
more: $("Next"),
back: $("Previous"),
next: function(choice) {
answers.update_value = choice.label;
return choice.value;
}
});
Expand Down Expand Up @@ -872,21 +874,35 @@ go.app = function() {
var year = answers.state_edd_baby_unborn_year || answers.state_baby_born_year;
var month = answers.state_edd_baby_unborn_month || answers.state_baby_born_month;
var day = answers.state_edd_baby_unborn_day || answers.state_baby_born_day;
var baby_date = new moment.utc(
year + month + day,
"YYYYMMDD"
).format();

if ((typeof answers.state_edd_baby_unborn_year != "undefined")){
data.change_type = "edd_baby_expected";
data.baby_edd = new moment.utc(
year + month + day,
"YYYYMMDD"
).format(),
data.baby_edd = baby_date,
end_flow = "state_edd_baby_unborn_complete";
}
else if ((answers.update_value) && (answers.update_value.startsWith("1st") ||
answers.update_value.startsWith("2nd") ||
answers.update_value.startsWith("3rd"))) {
if (answers.update_value.startsWith("1st")){
data.change_baby = "baby_dob1";
}
else if (answers.update_value.startsWith("2nd")){
data.change_baby = "baby_dob2";
}
else if (answers.update_value.startsWith("3rd")){
data.change_baby = "baby_dob3";
}
data.change_type = "change_baby_dob";
data.baby_dob = baby_date,
end_flow = "state_baby_born_complete";
}
else {
data.change_type = "baby_born";
data.baby_dob = new moment.utc(
year + month + day,
"YYYYMMDD"
).format(),
data.baby_dob = baby_date,
end_flow = "state_baby_born_complete";
}
return self.rapidpro
Expand Down
32 changes: 24 additions & 8 deletions src/ussd_popi_rapidpro.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ go.app = function() {

self.add("state_change_info", function(name) {
var contact = self.im.user.answers.contact;
var answers = self.im.user.answers;
var dates_count, postbirth;
var dates_list = [];
var channel = _.get(contact, "fields.preferred_channel");
Expand Down Expand Up @@ -392,6 +393,7 @@ go.app = function() {
more: $("Next"),
back: $("Previous"),
next: function(choice) {
answers.update_value = choice.label;
return choice.value;
}
});
Expand Down Expand Up @@ -700,21 +702,35 @@ go.app = function() {
var year = answers.state_edd_baby_unborn_year || answers.state_baby_born_year;
var month = answers.state_edd_baby_unborn_month || answers.state_baby_born_month;
var day = answers.state_edd_baby_unborn_day || answers.state_baby_born_day;
var baby_date = new moment.utc(
year + month + day,
"YYYYMMDD"
).format();

if ((typeof answers.state_edd_baby_unborn_year != "undefined")){
data.change_type = "edd_baby_expected";
data.baby_edd = new moment.utc(
year + month + day,
"YYYYMMDD"
).format(),
data.baby_edd = baby_date,
end_flow = "state_edd_baby_unborn_complete";
}
else if ((answers.update_value) && (answers.update_value.startsWith("1st") ||
answers.update_value.startsWith("2nd") ||
answers.update_value.startsWith("3rd"))) {
if (answers.update_value.startsWith("1st")){
data.change_baby = "baby_dob1";
}
else if (answers.update_value.startsWith("2nd")){
data.change_baby = "baby_dob2";
}
else if (answers.update_value.startsWith("3rd")){
data.change_baby = "baby_dob3";
}
data.change_type = "change_baby_dob";
data.baby_dob = baby_date,
end_flow = "state_baby_born_complete";
}
else {
data.change_type = "baby_born";
data.baby_dob = new moment.utc(
year + month + day,
"YYYYMMDD"
).format(),
data.baby_dob = baby_date,
end_flow = "state_baby_born_complete";
}
return self.rapidpro
Expand Down
125 changes: 125 additions & 0 deletions test/ussd_popi_rapidpro.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,32 @@ describe("ussd_popi_rapidpro app", function() {
})
.run();
});
it("should show option to update baby DOB 1", function() {
return tester
.setup.user.state("state_change_info")
.setup.user.answer("contact", {fields: {preferred_channel: "WhatsApp",
baby_dob1: "2021-03-10",
baby_dob2: "2021-11-11",
baby_dob3: "2022-07-07",
edd: "2020-06-04T00:00:00Z",
postbirth_messaging: "True",
},
})
.input("4")
.check.user.answer("update_value", "1st Baby's DoB: 10-03-2021")
.check.interaction({
reply: [
"Which year was your baby born? " +
"Please reply with a number that matches your answer, " +
"not the year e.g. 1.",
"1. 2022",
"2. 2021",
"3. 2020",
"4. Other"
].join("\n")
})
.run();
});
it("should display the list of options to the user SMS page 2", function() {
return tester
.setup.user.state("state_change_info")
Expand Down Expand Up @@ -760,6 +786,105 @@ describe("ussd_popi_rapidpro app", function() {
})
.run();
});
it("should trigger the baby dob change on confirm for 1st baby update DOB", function() {
return tester
.setup.user.state("state_baby_born_confirm_date")
.setup.user.answer("state_baby_born_year", "2022")
.setup.user.answer("state_baby_born_month", "04")
.setup.user.answer("state_baby_born_day", "4")
.setup.user.answer("update_value", "1st Baby's DOB")

.setup(function(api) {
api.http.fixtures.add(
fixtures_rapidpro.start_flow(
"edd-dob-change-flow-uuid", null, "whatsapp:27123456789", {
timestamp: "2022-04-04T07:07:07Z",
change_type: "change_baby_dob",
baby_dob: '2022-04-04T00:00:00Z',
change_baby: "baby_dob1"
}
)
);
})
.input("1")
.check.user.state("state_baby_born_complete")
.check.interaction({
reply: [
"Your baby's date of birth has been updated " +
"to 2022-04-04 and you will start receiving " +
"messages based on this schedule.",
"1. Back",
"2. Exit"
].join("\n")
})
.run();
});
it("should trigger the baby dob change on confirm for 2nd baby update DOB", function() {
return tester
.setup.user.state("state_baby_born_confirm_date")
.setup.user.answer("state_baby_born_year", "2022")
.setup.user.answer("state_baby_born_month", "04")
.setup.user.answer("state_baby_born_day", "4")
.setup.user.answer("update_value", "2nd Baby's DOB")

.setup(function(api) {
api.http.fixtures.add(
fixtures_rapidpro.start_flow(
"edd-dob-change-flow-uuid", null, "whatsapp:27123456789", {
timestamp: "2022-04-04T07:07:07Z",
change_type: "change_baby_dob",
baby_dob: '2022-04-04T00:00:00Z',
change_baby: "baby_dob2"
}
)
);
})
.input("1")
.check.user.state("state_baby_born_complete")
.check.interaction({
reply: [
"Your baby's date of birth has been updated " +
"to 2022-04-04 and you will start receiving " +
"messages based on this schedule.",
"1. Back",
"2. Exit"
].join("\n")
})
.run();
});
it("should trigger the baby dob change on confirm for 3rd baby update DOB", function() {
return tester
.setup.user.state("state_baby_born_confirm_date")
.setup.user.answer("state_baby_born_year", "2022")
.setup.user.answer("state_baby_born_month", "04")
.setup.user.answer("state_baby_born_day", "4")
.setup.user.answer("update_value", "3rd Baby's DOB")

.setup(function(api) {
api.http.fixtures.add(
fixtures_rapidpro.start_flow(
"edd-dob-change-flow-uuid", null, "whatsapp:27123456789", {
timestamp: "2022-04-04T07:07:07Z",
change_type: "change_baby_dob",
baby_dob: '2022-04-04T00:00:00Z',
change_baby: "baby_dob3"
}
)
);
})
.input("1")
.check.user.state("state_baby_born_complete")
.check.interaction({
reply: [
"Your baby's date of birth has been updated " +
"to 2022-04-04 and you will start receiving " +
"messages based on this schedule.",
"1. Back",
"2. Exit"
].join("\n")
})
.run();
});

/***************************
***Edd Baby Unborn Tests***
Expand Down

0 comments on commit 7863972

Please sign in to comment.