Skip to content

Commit

Permalink
Merge pull request #643 from praekeltfoundation/sigma-1267-change-edd…
Browse files Browse the repository at this point in the history
…-dob

Fix EDD and DoB display for change info
  • Loading branch information
Buhle79 authored Aug 15, 2024
2 parents 7863972 + 5fc7568 commit 2cc9b9a
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 34 deletions.
59 changes: 42 additions & 17 deletions go-app-ussd_popi_rapidpro.js
Original file line number Diff line number Diff line change
Expand Up @@ -478,14 +478,28 @@ go.app = function() {
baby_dob2 = self.dateformat(baby_dob2);
baby_dob3 = self.dateformat(baby_dob3);
edd = self.dateformat(edd);
var context = {
dobs: _.map(_.filter([
new moment(edd),
new moment(baby_dob1),
new moment(baby_dob2),
new moment(baby_dob3),
], _.method("isValid")), _.method("format", "DD-MM-YYYY")).join(", ") || $("None")
};
var context;

if (edd){
context = {
dobs: _.map(_.filter([
new moment(edd),
new moment(baby_dob1),
new moment(baby_dob2),
new moment(baby_dob3),
], _.method("isValid")), _.method("format", "DD-MM-YYYY")).join(", ") || $("None")
};
}
else {
context = {
dobs: _.map(_.filter([
new moment(baby_dob1),
new moment(baby_dob2),
new moment(baby_dob3),
], _.method("isValid")), _.method("format", "DD-MM-YYYY")).join(", ") || $("None")
};
}

var dates_entry = Object.values(context);
var sms_choices = [
new Choice("state_msisdn_change_enter", $("Cell number")),
Expand All @@ -504,20 +518,24 @@ go.app = function() {
];
postbirth = _.toUpper(_.get(contact, "fields.postbirth_messaging")) === "TRUE";

if (dates_entry[0].length){
if (edd || baby_dob1){
dates_list = dates_entry[0].trim().split(/\s*,\s*/);
dates_count = dates_list.length;
}

if (edd && baby_dob1){
edd = dates_list[0] || null;
baby_dob1 = dates_list[1] || null;
baby_dob2 = dates_list[2] || null;
baby_dob3 = dates_list[3] || null;

}
else if (baby_dob1){
baby_dob1 = dates_list[0] || null;
baby_dob2 = dates_list[1] || null;
baby_dob3 = dates_list[2] || null;
}
else {
if (!(dates_entry[0].length) && (edd)){
edd = dates_list[0] || null;

}
edd = dates_list[0] || null;
}
var dob_choices = [
new Choice("state_active_prebirth_check", $(
Expand Down Expand Up @@ -550,10 +568,17 @@ go.app = function() {
if (postbirth){
++i;
}
for (i; i < (dob_count); i++) {
channel_list.splice(i+2, 0, dob_list[i]);
}

if (edd){
for (i; i < (dob_count); i++) {
channel_list.splice(i+2, 0, dob_list[i]);
}
}
else {
for (i; i < (dob_count); i++) {
channel_list.splice(i+2, 0, dob_list[i+1]);
}
}
}
return new PaginatedChoiceState(name, {
question: $("What would you like to change?"),
Expand Down
59 changes: 42 additions & 17 deletions src/ussd_popi_rapidpro.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,14 +306,28 @@ go.app = function() {
baby_dob2 = self.dateformat(baby_dob2);
baby_dob3 = self.dateformat(baby_dob3);
edd = self.dateformat(edd);
var context = {
dobs: _.map(_.filter([
new moment(edd),
new moment(baby_dob1),
new moment(baby_dob2),
new moment(baby_dob3),
], _.method("isValid")), _.method("format", "DD-MM-YYYY")).join(", ") || $("None")
};
var context;

if (edd){
context = {
dobs: _.map(_.filter([
new moment(edd),
new moment(baby_dob1),
new moment(baby_dob2),
new moment(baby_dob3),
], _.method("isValid")), _.method("format", "DD-MM-YYYY")).join(", ") || $("None")
};
}
else {
context = {
dobs: _.map(_.filter([
new moment(baby_dob1),
new moment(baby_dob2),
new moment(baby_dob3),
], _.method("isValid")), _.method("format", "DD-MM-YYYY")).join(", ") || $("None")
};
}

var dates_entry = Object.values(context);
var sms_choices = [
new Choice("state_msisdn_change_enter", $("Cell number")),
Expand All @@ -332,20 +346,24 @@ go.app = function() {
];
postbirth = _.toUpper(_.get(contact, "fields.postbirth_messaging")) === "TRUE";

if (dates_entry[0].length){
if (edd || baby_dob1){
dates_list = dates_entry[0].trim().split(/\s*,\s*/);
dates_count = dates_list.length;
}

if (edd && baby_dob1){
edd = dates_list[0] || null;
baby_dob1 = dates_list[1] || null;
baby_dob2 = dates_list[2] || null;
baby_dob3 = dates_list[3] || null;

}
else if (baby_dob1){
baby_dob1 = dates_list[0] || null;
baby_dob2 = dates_list[1] || null;
baby_dob3 = dates_list[2] || null;
}
else {
if (!(dates_entry[0].length) && (edd)){
edd = dates_list[0] || null;

}
edd = dates_list[0] || null;
}
var dob_choices = [
new Choice("state_active_prebirth_check", $(
Expand Down Expand Up @@ -378,10 +396,17 @@ go.app = function() {
if (postbirth){
++i;
}
for (i; i < (dob_count); i++) {
channel_list.splice(i+2, 0, dob_list[i]);
}

if (edd){
for (i; i < (dob_count); i++) {
channel_list.splice(i+2, 0, dob_list[i]);
}
}
else {
for (i; i < (dob_count); i++) {
channel_list.splice(i+2, 0, dob_list[i+1]);
}
}
}
return new PaginatedChoiceState(name, {
question: $("What would you like to change?"),
Expand Down
79 changes: 79 additions & 0 deletions test/ussd_popi_rapidpro.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,85 @@ describe("ussd_popi_rapidpro app", function() {
})
.run();
});
it("should display the list of options with 1 baby DOB", function() {
return tester
.setup.user.state("state_change_info")
.setup.user.answer("contact", {fields: {preferred_channel: "SMS",
baby_dob1: "2021-03-18T00:00:00.000000Z",
}})
.check.interaction({
reply: [
"What would you like to change?",
"1. Cell number",
"2. Change SMS to WhatsApp",
"3. 1st Baby's DoB: 18-03-2021",
"4. Language",
"5. ID",
"6. Research msgs",
"7. Back"
].join("\n")
})
.run();
});
it("should display the list of options with EDD", function() {
return tester
.setup.user.state("state_change_info")
.setup.user.answer("contact", {fields: {preferred_channel: "SMS",
edd: "2020-06-04T00:00:00.000000Z",
}})
.check.interaction({
reply: [
"What would you like to change?",
"1. Cell number",
"2. Change SMS to WhatsApp",
"3. Baby's Expected Due Date: 04-06-2020",
"4. Language",
"5. ID",
"6. Research msgs",
"7. Back"
].join("\n")
})
.run();
});
it("should display the list of options include EDD and DOB", function() {
return tester
.setup.user.state("state_change_info")
.setup.user.answer("contact", {fields: {preferred_channel: "SMS",
baby_dob1: "2021-03-18T00:00:00.000000Z",
edd: "2020-06-04T00:00:00.000000Z",
}})
.check.interaction({
reply: [
"What would you like to change?",
"1. Cell number",
"2. Change SMS to WhatsApp",
"3. Baby's Expected Due Date: 04-06-2020",
"4. 1st Baby's DoB: 18-03-2021",
"5. Next"
].join("\n")
})
.run();
});
it("should display the list of options to the user SMS page 1", function() {
return tester
.setup.user.state("state_change_info")
.setup.user.answer("contact", {fields: {preferred_channel: "SMS",
baby_dob1: "2021-03-18T00:00:00.000000Z",
baby_dob2: "2021-11-11T00:00:00.000000Z",
edd: "2020-06-04T00:00:00.000000Z",
}})
.check.interaction({
reply: [
"What would you like to change?",
"1. Cell number",
"2. Change SMS to WhatsApp",
"3. Baby's Expected Due Date: 04-06-2020",
"4. 1st Baby's DoB: 18-03-2021",
"5. Next"
].join("\n")
})
.run();
});

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

0 comments on commit 2cc9b9a

Please sign in to comment.