From 11680e431917d47da6cb126b64014689222e8f29 Mon Sep 17 00:00:00 2001 From: buhle79 Date: Thu, 5 Sep 2024 10:14:16 +0200 Subject: [PATCH] fix display of edd and bdob plus tests --- go-app-ussd_popi_rapidpro.js | 7 ++--- src/ussd_popi_rapidpro.js | 7 ++--- test/ussd_popi_rapidpro.test.js | 47 +++++++++++++++++++++++---------- 3 files changed, 41 insertions(+), 20 deletions(-) diff --git a/go-app-ussd_popi_rapidpro.js b/go-app-ussd_popi_rapidpro.js index 0d322339..ec9de2d7 100644 --- a/go-app-ussd_popi_rapidpro.js +++ b/go-app-ussd_popi_rapidpro.js @@ -469,15 +469,18 @@ go.app = function() { var answers = self.im.user.answers; var dates_count, postbirth; var dates_list = []; + var channel = _.get(contact, "fields.preferred_channel"); var baby_dob1 = _.get(contact, "fields.baby_dob1", null); var baby_dob2 = _.get(contact, "fields.baby_dob2", null); var baby_dob3 = _.get(contact, "fields.baby_dob3", null); var edd = _.get(contact, "fields.edd", null); + baby_dob1 = self.dateformat(baby_dob1); baby_dob2 = self.dateformat(baby_dob2); baby_dob3 = self.dateformat(baby_dob3); edd = self.dateformat(edd); + var context; if (edd){ @@ -565,9 +568,6 @@ go.app = function() { function push_dob(channel_list, dob_list, dob_count) { var i = 0; - if (postbirth){ - ++i; - } if (edd){ for (i; i < (dob_count); i++) { @@ -580,6 +580,7 @@ go.app = function() { } } } + return new PaginatedChoiceState(name, { question: $("What would you like to change?"), accept_labels: true, diff --git a/src/ussd_popi_rapidpro.js b/src/ussd_popi_rapidpro.js index 5d1db71d..cb393f0b 100644 --- a/src/ussd_popi_rapidpro.js +++ b/src/ussd_popi_rapidpro.js @@ -297,15 +297,18 @@ go.app = function() { var answers = self.im.user.answers; var dates_count, postbirth; var dates_list = []; + var channel = _.get(contact, "fields.preferred_channel"); var baby_dob1 = _.get(contact, "fields.baby_dob1", null); var baby_dob2 = _.get(contact, "fields.baby_dob2", null); var baby_dob3 = _.get(contact, "fields.baby_dob3", null); var edd = _.get(contact, "fields.edd", null); + baby_dob1 = self.dateformat(baby_dob1); baby_dob2 = self.dateformat(baby_dob2); baby_dob3 = self.dateformat(baby_dob3); edd = self.dateformat(edd); + var context; if (edd){ @@ -393,9 +396,6 @@ go.app = function() { function push_dob(channel_list, dob_list, dob_count) { var i = 0; - if (postbirth){ - ++i; - } if (edd){ for (i; i < (dob_count); i++) { @@ -408,6 +408,7 @@ go.app = function() { } } } + return new PaginatedChoiceState(name, { question: $("What would you like to change?"), accept_labels: true, diff --git a/test/ussd_popi_rapidpro.test.js b/test/ussd_popi_rapidpro.test.js index 16b68c19..77f40293 100644 --- a/test/ussd_popi_rapidpro.test.js +++ b/test/ussd_popi_rapidpro.test.js @@ -476,15 +476,17 @@ describe("ussd_popi_rapidpro app", function() { postbirth_messaging: "True" }, }) - .input("6") + .input("5") .check.interaction({ reply: [ "What would you like to change?", - "1. 3rd Baby's DoB: 07-07-2022", - "2. ID", - "3. Research msgs", - "4. Back", - "5. Previous" + "1. 2nd Baby's DoB: 11-11-2021", + "2. 3rd Baby's DoB: 07-07-2022", + "3. Language", + "4. ID", + "5. Research msgs", + "6. Back", + "7. Previous" ].join("\n") }) .run(); @@ -504,10 +506,9 @@ describe("ussd_popi_rapidpro app", function() { "What would you like to change?", "1. Cell number", "2. Change SMS to WhatsApp", - "3. Language", + "3. Baby's Expected Due Date: 04-06-2020", "4. 1st Baby's DoB: 10-03-2021", - "5. 2nd Baby's DoB: 11-11-2021", - "6. Next" + "5. Next" ].join("\n") }) .run(); @@ -885,7 +886,7 @@ describe("ussd_popi_rapidpro app", function() { }) .run(); }); - it("should display the list of options with 1 baby DOB", function() { + it("should display the list of options with 1 baby DOB for SMS channel", function() { return tester .setup.user.state("state_change_info") .setup.user.answer("contact", {fields: {preferred_channel: "SMS", @@ -905,6 +906,25 @@ describe("ussd_popi_rapidpro app", function() { }) .run(); }); + it("should display the list of options with 1 baby DOB for WA channel", function() { + return tester + .setup.user.state("state_change_info") + .setup.user.answer("contact", {fields: {preferred_channel: "WhatsApp", + baby_dob1: "2021-03-18T00:00:00.000000Z", + }}) + .check.interaction({ + reply: [ + "What would you like to change?", + "1. Cell number", + "2. Change WhatsApp to SMS", + "3. 1st Baby's DoB: 18-03-2021", + "4. ID", + "5. Research msgs", + "6. Back" + ].join("\n") + }) + .run(); + }); it("should display the list of options with EDD", function() { return tester .setup.user.state("state_change_info") @@ -1132,7 +1152,7 @@ describe("ussd_popi_rapidpro app", function() { .check.user.state("state_edd_baby_unborn_complete") .run(); }); - it("should display an error on invalid input and should not show EDD if contact has postbirth messaging", function() { + it("should display an error on invalid input with postbirth messaging", function() { return tester .setup.user.state("state_change_info") .setup.user.answer("contact", {fields: {preferred_channel: "SMS", @@ -1148,10 +1168,9 @@ describe("ussd_popi_rapidpro app", function() { "We don't understand. Please try again.", "1. Cell number", "2. Change SMS to WhatsApp", - "3. Language", + "3. Baby's Expected Due Date: 04-06-2020", "4. 1st Baby's DoB: 10-03-2021", - "5. 2nd Baby's DoB: 11-11-2021", - "6. Next" + "5. Next" ].join("\n") }) .run();