Skip to content

Commit

Permalink
Merge pull request #618 from praekeltfoundation/TBH-720-bug-incorrect…
Browse files Browse the repository at this point in the history
…-response-after-replying-no-to-soft-commitment

Tbh 720 bug incorrect response after replying no to soft commitment
  • Loading branch information
Buhle79 authored Oct 26, 2023
2 parents 7a99152 + 3c15837 commit d7f95f8
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 26 deletions.
37 changes: 25 additions & 12 deletions go-app-ussd_tb_check.js
Original file line number Diff line number Diff line change
Expand Up @@ -1126,20 +1126,33 @@ go.app = function () {
),
error: $("Please use numbers from list. Do you commit to getting tested?"),
accept_labels: true,
choices: [new Choice("state_commit_to_get_tested_yes", $("YES")),
choices: [new Choice("state_send_facilities_link_sms", $("YES")),
new Choice("state_submit_test_commit", $("NO"))],
});
});

self.add("state_commit_to_get_tested_yes", function(name) {
return new MenuState(name, {
question: $([
"For a list of facilities in your community, please access the facilities ",
"section of the Western Cape Government website.",
].join("\n")
),
accept_labels: true,
choices: [new Choice("state_clinic_visit_day", $("Next"))],
self.add("state_send_facilities_link_sms", function(name, opts) {
var next_state = "state_clinic_visit_day";
var flow_uuid = self.im.config.rapidpro.tb_study_facilities_uuid;
var language = self.im.user.answers.state_language;
var msisdn = utils.normalize_msisdn(
_.get(
self.im.user.answers, "state_enter_msisdn", self.im.user.addr), "ZA");
var data = {
language: language
};
return self.rapidpro
.start_flow(flow_uuid, null, "tel:" + msisdn, data)
.then(function() {
return self.states.create(next_state);
}).catch(function(e) {
// Go to error state after 3 failed HTTP requests
opts.http_error_count = _.get(opts, "http_error_count", 0) + 1;
if(opts.http_error_count === 3) {
self.im.log.error(e.message);
return self.states.create("__error__", {return_state: name});
}
return self.states.create(name, opts);
});
});

Expand Down Expand Up @@ -1176,7 +1189,7 @@ go.app = function () {

var payload = {
data: {
commit_get_tested: answers.state_commit_to_get_tested === "state_commit_to_get_tested_yes" ? "yes" : "no",
commit_get_tested: answers.state_commit_to_get_tested === "state_send_facilities_link_sms" ? "yes" : "no",
"source": "USSD",
clinic_visit_day: answers.clinic_visit_day,
},
Expand All @@ -1189,7 +1202,7 @@ go.app = function () {
.patch(self.im.config.healthcheck.url + "/v2/tbcheck/"+ id +"/", payload)
.then(
function () {
if (answers.state_commit_to_get_tested === "state_commit_to_get_tested_yes"){
if (answers.state_commit_to_get_tested === "state_send_facilities_link_sms"){
return self.states.create("state_commitment");
}
else{
Expand Down
37 changes: 25 additions & 12 deletions src/ussd_tb_check.js
Original file line number Diff line number Diff line change
Expand Up @@ -1009,20 +1009,33 @@ go.app = function () {
),
error: $("Please use numbers from list. Do you commit to getting tested?"),
accept_labels: true,
choices: [new Choice("state_commit_to_get_tested_yes", $("YES")),
choices: [new Choice("state_send_facilities_link_sms", $("YES")),
new Choice("state_submit_test_commit", $("NO"))],
});
});

self.add("state_commit_to_get_tested_yes", function(name) {
return new MenuState(name, {
question: $([
"For a list of facilities in your community, please access the facilities ",
"section of the Western Cape Government website.",
].join("\n")
),
accept_labels: true,
choices: [new Choice("state_clinic_visit_day", $("Next"))],
self.add("state_send_facilities_link_sms", function(name, opts) {
var next_state = "state_clinic_visit_day";
var flow_uuid = self.im.config.rapidpro.tb_study_facilities_uuid;
var language = self.im.user.answers.state_language;
var msisdn = utils.normalize_msisdn(
_.get(
self.im.user.answers, "state_enter_msisdn", self.im.user.addr), "ZA");
var data = {
language: language
};
return self.rapidpro
.start_flow(flow_uuid, null, "tel:" + msisdn, data)
.then(function() {
return self.states.create(next_state);
}).catch(function(e) {
// Go to error state after 3 failed HTTP requests
opts.http_error_count = _.get(opts, "http_error_count", 0) + 1;
if(opts.http_error_count === 3) {
self.im.log.error(e.message);
return self.states.create("__error__", {return_state: name});
}
return self.states.create(name, opts);
});
});

Expand Down Expand Up @@ -1059,7 +1072,7 @@ go.app = function () {

var payload = {
data: {
commit_get_tested: answers.state_commit_to_get_tested === "state_commit_to_get_tested_yes" ? "yes" : "no",
commit_get_tested: answers.state_commit_to_get_tested === "state_send_facilities_link_sms" ? "yes" : "no",
"source": "USSD",
clinic_visit_day: answers.clinic_visit_day,
},
Expand All @@ -1072,7 +1085,7 @@ go.app = function () {
.patch(self.im.config.healthcheck.url + "/v2/tbcheck/"+ id +"/", payload)
.then(
function () {
if (answers.state_commit_to_get_tested === "state_commit_to_get_tested_yes"){
if (answers.state_commit_to_get_tested === "state_send_facilities_link_sms"){
return self.states.create("state_commitment");
}
else{
Expand Down
5 changes: 3 additions & 2 deletions test/ussd_tb_check.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ describe("ussd_tb_check app", function () {
token: "rapidpro-token",
privacy_policy_sms_flow: "privacy-policy-flow-uuid",
tbcheck_survey_flow_uuid: "tbcheck-survey-flow-uuid",
faq_sms_flow_uuid: "faq-sms-flow-uuid"
faq_sms_flow_uuid: "faq-sms-flow-uuid",
tb_study_facilities_uuid: "tb-study-facilities-uuid"
},
activations: {
to_regex: "\\\*\\d\+\\\*\\d\+\\\*\(\[\\d\]\+\)#",
Expand Down Expand Up @@ -2122,7 +2123,7 @@ describe("ussd_tb_check app", function () {
.state("state_submit_test_commit")
.setup.user.answers({
tbcheck_id: 22,
state_commit_to_get_tested: "state_commit_to_get_tested_yes",
state_commit_to_get_tested: "state_send_facilities_link_sms",
})
.setup(function (api) {
api.http.fixtures.add({
Expand Down

0 comments on commit d7f95f8

Please sign in to comment.