Skip to content

Commit

Permalink
Updated stest and RP payload
Browse files Browse the repository at this point in the history
  • Loading branch information
Buhle79 committed Jul 18, 2024
1 parent d885106 commit 11bf1b1
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 39 deletions.
4 changes: 0 additions & 4 deletions go-app-ussd_clinic_rapidpro.js
Original file line number Diff line number Diff line change
Expand Up @@ -1426,13 +1426,11 @@ go.app = function() {
return self.hub
.get_whatsapp_template_status(status_id)
.then(function(data) {
console.log(">>>>>>", data);
self.im.user.set_answer("preferred_channel", data.preferred_channel);
self.im.user.set_answer("status", data.status);

return self.states.create("state_trigger_rapidpro_flow");
}).catch(function(e) {
console.log("Status Error: ", e.message);
// 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) {
Expand Down Expand Up @@ -1463,7 +1461,6 @@ go.app = function() {
swt: self.im.user.answers.preferred_channel == "SMS" ? "1" : "7",
preferred_channel: self.im.user.answers.preferred_channel,
status_id: self.im.user.answers.status_id,
status: self.im.user.answers.status,
};
var flow_uuid;

Expand Down Expand Up @@ -1515,7 +1512,6 @@ go.app = function() {
.then(function() {
return self.states.create("state_registration_complete");
}).catch(function(e) {
console.log("Trigger Error: ", e.message);
// 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) {
Expand Down
4 changes: 0 additions & 4 deletions src/ussd_clinic_rapidpro.js
Original file line number Diff line number Diff line change
Expand Up @@ -1164,13 +1164,11 @@ go.app = function() {
return self.hub
.get_whatsapp_template_status(status_id)
.then(function(data) {
console.log(">>>>>>", data);
self.im.user.set_answer("preferred_channel", data.preferred_channel);
self.im.user.set_answer("status", data.status);

return self.states.create("state_trigger_rapidpro_flow");
}).catch(function(e) {
console.log("Status Error: ", e.message);
// 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) {
Expand Down Expand Up @@ -1201,7 +1199,6 @@ go.app = function() {
swt: self.im.user.answers.preferred_channel == "SMS" ? "1" : "7",
preferred_channel: self.im.user.answers.preferred_channel,
status_id: self.im.user.answers.status_id,
status: self.im.user.answers.status,
};
var flow_uuid;

Expand Down Expand Up @@ -1253,7 +1250,6 @@ go.app = function() {
.then(function() {
return self.states.create("state_registration_complete");
}).catch(function(e) {
console.log("Trigger Error: ", e.message);
// 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) {
Expand Down
6 changes: 2 additions & 4 deletions test/fixtures_hub.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,12 @@ module.exports = function() {
};
},

get_whatsapp_template_status: function(status_id) {
console.log("ID: ", status_id);
get_whatsapp_template_status: function(status_id, preferred_channel) {
var response_body = {
"code": 200,
"data": {
"status_id": status_id,
"preferred_channel": "SMS",
"status": "wired"
"preferred_channel": preferred_channel,
}
};
return {
Expand Down
1 change: 0 additions & 1 deletion test/fixtures_rapidpro.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ module.exports = function() {
if(extra) {
data.extra = extra;
}
console.log("#####", data);
return {
"repeatable": true,
"request": {
Expand Down
54 changes: 28 additions & 26 deletions test/ussd_clinic_rapidpro.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1683,7 +1683,8 @@ describe("ussd_clinic app", function() {
.setup(function(api) {
api.http.fixtures.add(
fixtures_hub.get_whatsapp_template_status(
"status-id-uuid"
"status-id-uuid",
"SMS"
)
);
})
Expand All @@ -1704,7 +1705,6 @@ describe("ussd_clinic app", function() {
swt: "1",
preferred_channel: "SMS",
status_id: "status-id-uuid",
status: "wired",
}
)
);
Expand Down Expand Up @@ -1750,7 +1750,8 @@ describe("ussd_clinic app", function() {
.setup(function(api) {
api.http.fixtures.add(
fixtures_hub.get_whatsapp_template_status(
"status-id-uuid"
"status-id-uuid",
"SMS"
)
);
})
Expand All @@ -1771,7 +1772,6 @@ describe("ussd_clinic app", function() {
swt: "1",
preferred_channel: "SMS",
status_id: "status-id-uuid",
status: "wired",
}
)
);
Expand Down Expand Up @@ -1818,7 +1818,8 @@ describe("ussd_clinic app", function() {
.setup(function(api) {
api.http.fixtures.add(
fixtures_hub.get_whatsapp_template_status(
"status-id-uuid"
"status-id-uuid",
"SMS"
)
);
})
Expand All @@ -1840,7 +1841,6 @@ describe("ussd_clinic app", function() {
swt: "1",
preferred_channel: "SMS",
status_id: "status-id-uuid",
status: "wired",
}
)
);
Expand Down Expand Up @@ -1889,7 +1889,8 @@ describe("ussd_clinic app", function() {
.setup(function(api) {
api.http.fixtures.add(
fixtures_hub.get_whatsapp_template_status(
"status-id-uuid"
"status-id-uuid",
"SMS"
)
);
})
Expand All @@ -1912,7 +1913,6 @@ describe("ussd_clinic app", function() {
age: "16",
preferred_channel: "SMS",
status_id: "status-id-uuid",
status: "wired",
}
)
);
Expand Down Expand Up @@ -1961,7 +1961,8 @@ describe("ussd_clinic app", function() {
.setup(function(api) {
api.http.fixtures.add(
fixtures_hub.get_whatsapp_template_status(
"status-id-uuid"
"status-id-uuid",
"SMS"
)
);
})
Expand All @@ -1982,7 +1983,6 @@ describe("ussd_clinic app", function() {
dob: "2014-10-25T00:00:00Z",
preferred_channel: "SMS",
status_id: "status-id-uuid",
status: "wired",
}
)
);
Expand Down Expand Up @@ -2024,12 +2024,12 @@ describe("ussd_clinic app", function() {
preferred_channel: "WhatsApp",
state_language: "eng",
status_id: "status-id-uuid",
// status: "wired",
})
.setup(function(api) {
api.http.fixtures.add(
fixtures_hub.get_whatsapp_template_status(
"status-id-uuid"
"status-id-uuid",
"WhatsApp"
)
);
})
Expand All @@ -2049,8 +2049,7 @@ describe("ussd_clinic app", function() {
dob: "1990-01-02T00:00:00Z",
swt: "7",
preferred_channel: "WhatsApp",
status_id: "status-id-uuid",
status: "wired"
status_id: "status-id-uuid"
}
)
);
Expand All @@ -2067,7 +2066,7 @@ describe("ussd_clinic app", function() {
})
.check.reply.ends_session()
.check(function(api) {
assert.equal(api.http.requests.length, 1);
assert.equal(api.http.requests.length, 2);
var urls = _.map(api.http.requests, "url");
assert.deepEqual(urls, [
"http://hub/api/v2/whatsapptemplatesendstatus/status-id-uuid/",
Expand All @@ -2077,7 +2076,7 @@ describe("ussd_clinic app", function() {
})
.run();
});
it("should retry HTTP call when RapidPro is down", function() {
it("should retry HTTP call when RapidPro is down on accept_popi_2", function() {
return tester
.setup.user.state("state_accept_popi_2")
.setup.user.answers({
Expand All @@ -2096,7 +2095,8 @@ describe("ussd_clinic app", function() {
.setup(function(api) {
api.http.fixtures.add(
fixtures_hub.get_whatsapp_template_status(
"status-id-uuid"
"status-id-uuid",
"WhatsApp"
)
);
})
Expand All @@ -2117,7 +2117,6 @@ describe("ussd_clinic app", function() {
swt: "7",
preferred_channel: "WhatsApp",
status_id: "status-id-uuid",
status: "wired",
}, true
)
);
Expand All @@ -2131,10 +2130,14 @@ describe("ussd_clinic app", function() {
})
.check.reply.ends_session()
.check(function(api){
assert.equal(api.http.requests.length, 3);
api.http.requests.forEach(function(request){
assert.equal(request.url, "https://rapidpro/api/v2/flow_starts.json");
});
assert.equal(api.http.requests.length, 4);
var urls = _.map(api.http.requests, "url");
assert.deepEqual(urls, [
"http://hub/api/v2/whatsapptemplatesendstatus/status-id-uuid/",
"https://rapidpro/api/v2/flow_starts.json",
"https://rapidpro/api/v2/flow_starts.json",
"https://rapidpro/api/v2/flow_starts.json",
]);
assert.equal(api.log.error.length, 1);
assert(api.log.error[0].includes("HttpResponseError"));
})
Expand Down Expand Up @@ -2214,13 +2217,13 @@ describe("ussd_clinic app", function() {
state_edd_month: "201502",
state_edd_day: "13",
state_clinic_code: "123456",
// status_id: "status-id-uuid",
// status: "wired",
status_id: "status-id-uuid",
})
.setup(function(api) {
api.http.fixtures.add(
fixtures_hub.get_whatsapp_template_status(
"status-id-uuid"
"status-id-uuid",
"WhatsApp"
)
);
})
Expand Down Expand Up @@ -2253,7 +2256,6 @@ describe("ussd_clinic app", function() {
swt: "7",
preferred_channel: "WhatsApp",
status_id: "status-id-uuid",
status: "wired",
}
)
);
Expand Down

0 comments on commit 11bf1b1

Please sign in to comment.