Skip to content

Commit

Permalink
add a check for when sms is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Hlamallama committed Sep 26, 2023
1 parent c8950cd commit 13a9da1
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 10 deletions.
7 changes: 5 additions & 2 deletions go-app-ussd_public_rapidpro.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ go.app = function() {
// Skip this state if they haven't opted out
var contact = self.im.user.get_answer("contact");
if(_.toUpper(_.get(contact, "fields.opted_out")) !== "TRUE") {
return self.states.create("state_trigger_rapidpro_flow");
return self.states.create("state_send_welcome_template");
}
return new MenuState(name, {
question: $(
Expand Down Expand Up @@ -514,8 +514,11 @@ go.app = function() {
timestamp: new moment.utc(self.im.config.testing_today).format(),
registered_by: msisdn,
mha: 6,
preferred_channel: self.im.user.answers.preferred_channel
swt: self.im.user.get_answer("preferred_channel") === "SMS" ? "1" : "7",
preferred_channel: self.im.user.get_answer("preferred_channel"),

};

return self.rapidpro
.start_flow(self.im.config.flow_uuid, null, "whatsapp:" + _.trim(msisdn, "+"), data)
.then(function() {
Expand Down
7 changes: 5 additions & 2 deletions src/ussd_public_rapidpro.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ go.app = function() {
// Skip this state if they haven't opted out
var contact = self.im.user.get_answer("contact");
if(_.toUpper(_.get(contact, "fields.opted_out")) !== "TRUE") {
return self.states.create("state_trigger_rapidpro_flow");
return self.states.create("state_send_welcome_template");
}
return new MenuState(name, {
question: $(
Expand Down Expand Up @@ -350,8 +350,11 @@ go.app = function() {
timestamp: new moment.utc(self.im.config.testing_today).format(),
registered_by: msisdn,
mha: 6,
preferred_channel: self.im.user.answers.preferred_channel
swt: self.im.user.get_answer("preferred_channel") === "SMS" ? "1" : "7",
preferred_channel: self.im.user.get_answer("preferred_channel"),

};

return self.rapidpro
.start_flow(self.im.config.flow_uuid, null, "whatsapp:" + _.trim(msisdn, "+"), data)
.then(function() {
Expand Down
56 changes: 50 additions & 6 deletions test/ussd_public_rapidpro.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,21 @@ describe("ussd_public app", function() {
});
it("should skip the opt in if the user hasn't opted out before", function() {
return tester
.setup.user.answers({
state_research_consent: "no",
state_opt_in: "yes",
opted_out: "False",
preferred_channel: "Whatsapp"
})
.setup(function(api) {
api.http.fixtures.add(
fixtures_hub.send_whatsapp_template_message(
"+27123456789",
"test-welcome-template",
null,
"Whatsapp"
)
);
api.http.fixtures.add(
fixtures_rapidpro.start_flow(
"rapidpro-flow-uuid",
Expand All @@ -489,7 +503,9 @@ describe("ussd_public app", function() {
"source": "Public USSD",
"timestamp": "2014-04-04T07:07:07Z",
"registered_by": "+27123456789",
"mha": 6
"mha": 6,
"swt": "7",
"preferred_channel": "Whatsapp"
}
)
);
Expand All @@ -503,6 +519,9 @@ describe("ussd_public app", function() {
describe("state_trigger_rapidpro_flow", function() {
it("should start a flow with the correct metadata", function() {
return tester
.setup.user.answers({
preferred_channel: "Whatsapp"
})
.setup(function(api) {
api.http.fixtures.add(
fixtures_rapidpro.start_flow(
Expand All @@ -515,7 +534,9 @@ describe("ussd_public app", function() {
"source": "Public USSD",
"timestamp": "2014-04-04T07:07:07Z",
"registered_by": "+27123456789",
"mha": 6
"mha": 6,
"swt": "7",
"preferred_channel": "Whatsapp"
}
)
);
Expand All @@ -529,6 +550,9 @@ describe("ussd_public app", function() {
});
it("should retry in the case of HTTP failures", function() {
return tester
.setup.user.answers({
preferred_channel: "Whatsapp"
})
.setup(function(api) {
api.http.fixtures.add(
fixtures_rapidpro.start_flow(
Expand All @@ -541,7 +565,9 @@ describe("ussd_public app", function() {
"source": "Public USSD",
"timestamp": "2014-04-04T07:07:07Z",
"registered_by": "+27123456789",
"mha": 6
"mha": 6,
"swt": "7",
"preferred_channel": "Whatsapp"
},
true
)
Expand All @@ -564,7 +590,21 @@ describe("ussd_public app", function() {
describe("state_registration_complete", function() {
it("should show the complete message for all users", function() {
return tester
.setup.user.answers({
state_research_consent: "no",
state_opt_in: "yes",
opted_out: "False",
preferred_channel: "Whatsapp"
})
.setup(function(api) {
api.http.fixtures.add(
fixtures_hub.send_whatsapp_template_message(
"+27123456789",
"test-welcome-template",
null,
"Whatsapp"
)
);
api.http.fixtures.add(
fixtures_rapidpro.start_flow(
"rapidpro-flow-uuid",
Expand All @@ -576,7 +616,9 @@ describe("ussd_public app", function() {
"source": "Public USSD",
"timestamp": "2014-04-04T07:07:07Z",
"registered_by": "+27123456789",
"mha": 6
"mha": 6,
"swt": "7",
"preferred_channel": "Whatsapp"
}
)
);
Expand Down Expand Up @@ -777,7 +819,8 @@ describe("ussd_public app", function() {
timestamp: "2014-04-04T07:07:07Z",
source: "Public USSD",
mha: 6,
preferred_channel: "SMS"
swt: "1",
preferred_channel: "SMS",
}
)
);
Expand Down Expand Up @@ -825,7 +868,8 @@ describe("ussd_public app", function() {
timestamp: "2014-04-04T07:07:07Z",
source: "Public USSD",
mha: 6,
preferred_channel: "Whatsapp"
swt: "7",
preferred_channel: "Whatsapp",
}
)
);
Expand Down

0 comments on commit 13a9da1

Please sign in to comment.