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

fix display of edd and bdob plus tests #644

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 4 additions & 3 deletions go-app-ussd_popi_rapidpro.js
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down Expand Up @@ -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++) {
Expand All @@ -580,6 +580,7 @@ go.app = function() {
}
}
}

return new PaginatedChoiceState(name, {
question: $("What would you like to change?"),
accept_labels: true,
Expand Down
7 changes: 4 additions & 3 deletions src/ussd_popi_rapidpro.js
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down Expand Up @@ -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++) {
Expand All @@ -408,6 +408,7 @@ go.app = function() {
}
}
}

return new PaginatedChoiceState(name, {
question: $("What would you like to change?"),
accept_labels: true,
Expand Down
47 changes: 33 additions & 14 deletions test/ussd_popi_rapidpro.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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",
Expand All @@ -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")
Expand Down Expand Up @@ -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",
Expand All @@ -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();
Expand Down
Loading