Skip to content

Commit

Permalink
Merge pull request #720 from praekeltfoundation/endline-study-limit-fix
Browse files Browse the repository at this point in the history
update pending status to limit_reached status when the endline survey…
  • Loading branch information
Hlamallama authored Nov 22, 2023
2 parents 2c79bdb + b1db750 commit 0b0039d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
13 changes: 13 additions & 0 deletions yal/endline_terms_and_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,19 @@ async def state_submit_terms_and_conditions_endline(self):
return await self.go_to_state(EndlineApplication.START_STATE)

async def state_endline_limit_reached(self):

msisdn = normalise_phonenumber(self.inbound.from_addr)
whatsapp_id = msisdn.lstrip(" + ")

data = {
"endline_survey_started": "limit_reached",
"assessment_reminder": "",
"assessment_reminder_sent": "",
"assessment_reminder_type": "",
}
error = await rapidpro.update_profile(whatsapp_id, data, self.user.metadata)
if error:
self.state_name = self.ERROR_STATE
choices = [
Choice("menu", "Go to the menu"),
Choice("aaq", "Ask a question"),
Expand Down
9 changes: 0 additions & 9 deletions yal/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,6 @@ async def process_message(self, message):
self.state_name = (
EndlineTermsApplication.ENDLINE_LIMIT_REACHED_STATE
)

data = {
"endline_survey_started": "limit_reached",
}
error = await rapidpro.update_profile(
whatsapp_id, data, self.user.metadata
)
if error:
self.state_name = self.ERROR_STATE
else:
self.state_name = EndlineTermsApplication.START_STATE

Expand Down
6 changes: 6 additions & 0 deletions yal/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1656,11 +1656,17 @@ async def test_state_endline_limit_reached_pending_menu(
tester.assert_state("state_endline_limit_reached")

tester.assert_metadata("endline_survey_started", "limit_reached")
tester.assert_metadata("assessment_reminder", "")
tester.assert_metadata("assessment_reminder_sent", "")
tester.assert_metadata("assessment_reminder_type", "")

request = rapidpro_mock.tstate.requests[4]

assert json.loads(request.body.decode("utf-8")) == {
"fields": {
"endline_survey_started": "limit_reached",
"assessment_reminder": "",
"assessment_reminder_sent": "",
"assessment_reminder_type": "",
}
}

0 comments on commit 0b0039d

Please sign in to comment.