Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sigma 1268 ussd baby DoB update #642

Merged
merged 5 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go-app-ussd_clinic_rapidpro.js
Original file line number Diff line number Diff line change
Expand Up @@ -1466,7 +1466,7 @@ go.app = function() {
};
var flow_uuid;

if (self.im.user.answers.state_message_type === "state_edd_month"
if (self.im.user.answers.state_message_type === "state_edd_year"
|| typeof self.im.user.answers.state_edd_month != "undefined") {
flow_uuid = self.im.config.prebirth_flow_uuid;
data.edd = new moment.utc(
Expand Down
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
2 changes: 1 addition & 1 deletion src/ussd_clinic_rapidpro.js
Original file line number Diff line number Diff line change
Expand Up @@ -1205,7 +1205,7 @@ go.app = function() {
};
var flow_uuid;

if (self.im.user.answers.state_message_type === "state_edd_month"
if (self.im.user.answers.state_message_type === "state_edd_year"
Buhle79 marked this conversation as resolved.
Show resolved Hide resolved
|| typeof self.im.user.answers.state_edd_month != "undefined") {
flow_uuid = self.im.config.prebirth_flow_uuid;
data.edd = new moment.utc(
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";
Buhle79 marked this conversation as resolved.
Show resolved Hide resolved
}
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
2 changes: 1 addition & 1 deletion test/ussd_clinic_rapidpro.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1668,7 +1668,7 @@ describe("ussd_clinic app", function() {
return tester
.setup.user.state("state_accept_popi_2")
.setup.user.answers({
state_message_type: "state_edd_month",
state_message_type: "state_edd_year",
state_research_consent: "no",
state_enter_msisdn: "0820001001",
state_id_type: "state_sa_id_no",
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({
Buhle79 marked this conversation as resolved.
Show resolved Hide resolved
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
Loading