Skip to content

Commit

Permalink
Merge pull request #719 from praekeltfoundation/endline-study-limit-fix
Browse files Browse the repository at this point in the history
Endline study limit fix
  • Loading branch information
Hlamallama authored Nov 22, 2023
2 parents 01bcf03 + e58e3a0 commit 2c79bdb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
9 changes: 9 additions & 0 deletions yal/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,15 @@ 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
26 changes: 26 additions & 0 deletions yal/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1638,3 +1638,29 @@ async def test_state_endline_limit_reached_aaq(
await tester.user_input("Ask a question")

tester.assert_state("state_aaq_start")


@pytest.mark.asyncio
@mock.patch("yal.rapidpro.get_group_membership_count")
async def test_state_endline_limit_reached_pending_menu(
get_group_membership_count, tester: AppTester, rapidpro_mock
):
get_group_membership_count.return_value = False, 250

tester.user.metadata["baseline_survey_completed"] = True
tester.user.metadata["endline_survey_started"] = "Pending"
tester.user.metadata["terms_accepted"] = True
tester.user.metadata["onboarding_completed"] = True

await tester.user_input("Yes, I want to answer")
tester.assert_state("state_endline_limit_reached")

tester.assert_metadata("endline_survey_started", "limit_reached")

request = rapidpro_mock.tstate.requests[4]

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

0 comments on commit 2c79bdb

Please sign in to comment.