diff --git a/go-app-ussd_popi_rapidpro.js b/go-app-ussd_popi_rapidpro.js index a3dbc73a..0d322339 100644 --- a/go-app-ussd_popi_rapidpro.js +++ b/go-app-ussd_popi_rapidpro.js @@ -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")), @@ -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", $( @@ -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?"), diff --git a/src/ussd_popi_rapidpro.js b/src/ussd_popi_rapidpro.js index 82903dc9..5d1db71d 100644 --- a/src/ussd_popi_rapidpro.js +++ b/src/ussd_popi_rapidpro.js @@ -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")), @@ -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", $( @@ -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?"), diff --git a/test/ussd_popi_rapidpro.test.js b/test/ussd_popi_rapidpro.test.js index 42bbd372..16b68c19 100644 --- a/test/ussd_popi_rapidpro.test.js +++ b/test/ussd_popi_rapidpro.test.js @@ -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***